Patches: Browse | Submit New | Admin

[#2717] bug fix + enhancement + suggestion (sorry! mixed patch)

Date:
2005-10-25 16:22
Priority:
3
Submitted By:
Choon Keat Chew (choonkeat)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
bug fix + enhancement + suggestion (sorry! mixed patch)

Detailed description
in addition to the attached .patch on the simple-rss.rb, for my own purpose (RssFwd) the below chunk of code is the
dynamic class modifications I make when using simple rss.

the 'def clean_content' addition allows me to get attributes of tags (e.g. :enclosure) like this:
  item.enclosure => #Hash{"url" => "http://.../...mp3", "type" =>
"audio/mpeg"}
  item.enclosure['url'] => "http://.../...mp3"

######

class SimpleRSS
  @@item_ignore_regex = /<link[^>]+type=.application[^>]+>/

  @@item_tags << :modified
  @@item_tags << :enclosure

  @@feed_tags << :name
  @@feed_tags << :webMaster

  # convert content-less tags to hash of attributes!
  alias_method :old_clean_content, :clean_content
  def clean_content(tag, attrs, content)
    val = old_clean_content(tag, attrs, content)
    if (val.nil? or val.to_s.strip == "") and attrs
      array = attrs.scan(/(\w+)=['"]?([^'"]+)/)
      # thanks http://www.bigbold.com/snippets/posts/show/302
      Hash[*array.collect { |x|
          [x, x]
        }.flatten]
    else
      val
    end
  end

end

######

Add A Comment: Notepad

Please login


Followup

No Followups Have Been Posted

Attached Files:

Name Description Download
simple-rss.rssfwd.patch patch to lib/simple-rss.rb based on modifications for RssFwd Download

Changes:

Field Old Value Date By
File Added336: simple-rss.rssfwd.patch2005-10-25 16:23choonkeat