diff options
Diffstat (limited to 'lib/rss/maker/2.0.rb')
-rw-r--r-- | lib/rss/maker/2.0.rb | 134 |
1 files changed, 93 insertions, 41 deletions
diff --git a/lib/rss/maker/2.0.rb b/lib/rss/maker/2.0.rb index a958661614..d93ba94d4a 100644 --- a/lib/rss/maker/2.0.rb +++ b/lib/rss/maker/2.0.rb @@ -7,16 +7,13 @@ module RSS class RSS20 < RSS09 - def initialize(rss_version="2.0") + def initialize(feed_version="2.0") super end class Channel < RSS09::Channel - def have_required_values? - @title and @link and @description - end - + private def required_variable_names %w(title link description) end @@ -32,47 +29,64 @@ module RSS end class Cloud < RSS09::Channel::Cloud - def to_rss(rss, channel) + def to_feed(rss, channel) cloud = Rss::Channel::Cloud.new set = setup_values(cloud) if set channel.cloud = cloud - setup_other_elements(rss) + set_parent(cloud, channel) + setup_other_elements(rss, cloud) end end - def have_required_values? - @domain and @port and @path and - @registerProcedure and @protocol + private + def required_variable_names + %w(domain port path registerProcedure protocol) end end class Categories < RSS09::Channel::Categories - def to_rss(rss, channel) + def to_feed(rss, channel) @categories.each do |category| - category.to_rss(rss, channel) + category.to_feed(rss, channel) end end class Category < RSS09::Channel::Categories::Category - def to_rss(rss, channel) + def to_feed(rss, channel) category = Rss::Channel::Category.new set = setup_values(category) if set channel.categories << category - setup_other_elements(rss) + set_parent(category, channel) + setup_other_elements(rss, category) end end - - def have_required_values? - @content + + private + def required_variable_names + %w(content) end end end - + + class Generator < GeneratorBase + def to_feed(rss, channel) + channel.generator = content + end + + private + def required_variable_names + %w(content) + end + end end class Image < RSS09::Image + private + def required_element? + false + end end class Items < RSS09::Items @@ -84,85 +98,123 @@ module RSS end private + def required_variable_names + %w(title description) + end + def variables super + ["pubDate"] end class Guid < RSS09::Items::Item::Guid - def to_rss(rss, item) + def to_feed(rss, item) guid = Rss::Channel::Item::Guid.new set = setup_values(guid) if set item.guid = guid - setup_other_elements(rss) + set_parent(guid, item) + setup_other_elements(rss, guid) end end - - def have_required_values? - @content + + private + def required_variable_names + %w(content) end end class Enclosure < RSS09::Items::Item::Enclosure - def to_rss(rss, item) + def to_feed(rss, item) enclosure = Rss::Channel::Item::Enclosure.new set = setup_values(enclosure) if set item.enclosure = enclosure - setup_other_elements(rss) + set_parent(enclosure, item) + setup_other_elements(rss, enclosure) end end - - def have_required_values? - @url and @length and @type + + private + def required_variable_names + %w(url length type) end end class Source < RSS09::Items::Item::Source - def to_rss(rss, item) + def to_feed(rss, item) source = Rss::Channel::Item::Source.new set = setup_values(source) if set item.source = source - setup_other_elements(rss) + set_parent(source, item) + setup_other_elements(rss, source) end end - - def have_required_values? - @url and @content + + private + def required_variable_names + %w(url content) + end + + class Links < RSS09::Items::Item::Source::Links + def to_feed(rss, source) + return if @links.empty? + @links.first.to_feed(rss, source) + end + + class Link < RSS09::Items::Item::Source::Links::Link + def to_feed(rss, source) + source.url = href + end + end end end class Categories < RSS09::Items::Item::Categories - def to_rss(rss, item) + def to_feed(rss, item) @categories.each do |category| - category.to_rss(rss, item) + category.to_feed(rss, item) end end class Category < RSS09::Items::Item::Categories::Category - def to_rss(rss, item) + def to_feed(rss, item) category = Rss::Channel::Item::Category.new set = setup_values(category) if set item.categories << category + set_parent(category, item) setup_other_elements(rss) end end - - def have_required_values? - @content + + private + def required_variable_names + %w(content) + end + end + end + + class Authors < RSS09::Items::Item::Authors + def to_feed(rss, item) + return if @authors.empty? + @authors.first.to_feed(rss, item) + end + + class Author < RSS09::Items::Item::Authors::Author + def to_feed(rss, item) + item.author = name end end end end - end class Textinput < RSS09::Textinput end end - add_maker(filename_to_version(__FILE__), RSS20) + add_maker("2.0", RSS20) + add_maker("rss2.0", RSS20) end end |