diff options
author | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-20 12:06:52 +0000 |
---|---|---|
committer | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-20 12:06:52 +0000 |
commit | df1e494a136dc507b36e90edbaffdeb611ab8923 (patch) | |
tree | 4e93ad2100a27a46c2261e17916981aa0afec34d | |
parent | 028e6396c043119448afce67ebf8f3aafc96e27e (diff) |
* lib/rss/rss.rb: provided default RSS::Element#_tags.
* lib/rss/0.9.rb: used default RSS::Element#_tags.
* lib/rss/1.0.rb: ditto.
* lib/rss/2.0.rb: ditto.
* lib/rss/image.rb: ditto.
* lib/rss/taxonomy.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10342 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | lib/rss/0.9.rb | 84 | ||||
-rw-r--r-- | lib/rss/1.0.rb | 78 | ||||
-rw-r--r-- | lib/rss/2.0.rb | 24 | ||||
-rw-r--r-- | lib/rss/image.rb | 9 | ||||
-rw-r--r-- | lib/rss/rss.rb | 29 | ||||
-rw-r--r-- | lib/rss/taxonomy.rb | 13 |
7 files changed, 30 insertions, 217 deletions
@@ -1,3 +1,13 @@ +Tue Jun 20 21:04:33 2006 Kouhei Sutou <kou@cozmixng.org> + + * lib/rss/rss.rb: provided default RSS::Element#_tags. + + * lib/rss/0.9.rb: used default RSS::Element#_tags. + * lib/rss/1.0.rb: ditto. + * lib/rss/2.0.rb: ditto. + * lib/rss/image.rb: ditto. + * lib/rss/taxonomy.rb: ditto. + Tue Jun 20 20:47:07 2006 Kouhei Sutou <kou@cozmixng.org> * lib/rss/rss.rb: hide RSS::Element.install_model. diff --git a/lib/rss/0.9.rb b/lib/rss/0.9.rb index 24af74a4ce..4007391f98 100644 --- a/lib/rss/0.9.rb +++ b/lib/rss/0.9.rb @@ -65,14 +65,6 @@ module RSS [@channel] end - def _tags - [ - ["", 'channel'], - ].delete_if do |uri, name| - __send__(name).nil? - end - end - def _attrs [ ["version", true, "rss_version"], @@ -112,35 +104,6 @@ module RSS [@skipDays, @skipHours, @image, @textInput, @cloud, *@item] end - def _tags - rv = [ - "title", - "link", - "description", - "language", - "copyright", - "managingEditor", - "webMaster", - "rating", - "docs", - "skipDays", - "skipHours", - "image", - "textInput", - "cloud", - ].delete_if do |name| - __send__(name).nil? - end.collect do |elem| - ["", elem] - end - - @item.each do - rv << ["", "item"] - end - - rv - end - def maker_target(maker) maker.channel end @@ -179,12 +142,6 @@ module RSS @day end - def _tags - @day.compact.collect do - ["", "day"] - end - end - class Day < Element include RSS09 @@ -217,12 +174,6 @@ module RSS @hour end - def _tags - @hour.compact.collect do - ["", "hour"] - end - end - class Hour < Element include RSS09 @@ -270,14 +221,6 @@ module RSS end private - def _tags - %w(url title link width height description).delete_if do |name| - __send__(name).nil? - end.collect do |elem| - ["", elem] - end - end - def maker_target(maker) maker.image end @@ -331,21 +274,6 @@ module RSS [@source, @enclosure, *@category].compact end - def _tags - rv = %w(title link description author comments - source enclosure).delete_if do |name| - __send__(name).nil? - end.collect do |name| - ["", name] - end - - @category.each do - rv << ["", "category"] - end - - rv - end - def maker_target(items) if items.respond_to?("items") # For backward compatibility @@ -383,10 +311,6 @@ module RSS end private - def _tags - [] - end - def maker_target(item) item.source end @@ -489,14 +413,6 @@ module RSS end private - def _tags - %w(title description name link).each do |name| - __send__(name).nil? - end.collect do |elem| - ["", elem] - end - end - def maker_target(maker) maker.textinput end diff --git a/lib/rss/1.0.rb b/lib/rss/1.0.rb index ff21a3430d..03d118a444 100644 --- a/lib/rss/1.0.rb +++ b/lib/rss/1.0.rb @@ -60,18 +60,6 @@ module RSS [@channel, @image, @textinput, *@item] end - def _tags - rv = [ - [::RSS::URI, "channel"], - [::RSS::URI, "image"], - ].delete_if {|uri, name| __send__(name).nil?} - @item.each do |item| - rv << [::RSS::URI, "item"] - end - rv << [::RSS::URI, "textinput"] if @textinput - rv - end - class Li < Element include RSS10 @@ -142,14 +130,6 @@ module RSS def children @li end - - def _tags - rv = [] - @li.each do |li| - rv << [URI, "li"] - end - rv - end end class Bag < Element @@ -192,14 +172,6 @@ module RSS def children @li end - - def _tags - rv = [] - @li.each do |li| - rv << [URI, "li"] - end - rv - end end class Channel < Element @@ -246,19 +218,6 @@ module RSS [@image, @items, @textinput] end - def _tags - [ - [::RSS::URI, 'title'], - [::RSS::URI, 'link'], - [::RSS::URI, 'description'], - [::RSS::URI, 'image'], - [::RSS::URI, 'items'], - [::RSS::URI, 'textinput'], - ].delete_if do |uri, name| - __send__(name).nil? - end - end - def maker_target(maker) maker.channel end @@ -366,12 +325,6 @@ module RSS def children [@Seq] end - - def _tags - rv = [] - rv << [URI, 'Seq'] unless @Seq.nil? - rv - end end end @@ -408,16 +361,6 @@ module RSS end private - def _tags - [ - [::RSS::URI, 'title'], - [::RSS::URI, 'url'], - [::RSS::URI, 'link'], - ].delete_if do |uri, name| - __send__(name).nil? - end - end - def maker_target(maker) maker.image end @@ -461,16 +404,6 @@ module RSS end private - def _tags - [ - [::RSS::URI, 'title'], - [::RSS::URI, 'link'], - [::RSS::URI, 'description'], - ].delete_if do |uri, name| - __send__(name).nil? - end - end - def maker_target(items) if items.respond_to?("items") # For backward compatibility @@ -513,17 +446,6 @@ module RSS end private - def _tags - [ - [::RSS::URI, 'title'], - [::RSS::URI, 'description'], - [::RSS::URI, 'name'], - [::RSS::URI, 'link'], - ].delete_if do |uri, name| - __send__(name).nil? - end - end - def maker_target(maker) maker.textinput end diff --git a/lib/rss/2.0.rb b/lib/rss/2.0.rb index 24cfb7c6e5..398aa0845a 100644 --- a/lib/rss/2.0.rb +++ b/lib/rss/2.0.rb @@ -32,21 +32,6 @@ module RSS children09 + @category.compact end - alias _tags09 _tags - def _tags - rv = %w(generator ttl).delete_if do |name| - __send__(name).nil? - end.collect do |elem| - ["", elem] - end + _tags09 - - @category.each do - rv << ["", "category"] - end - - rv - end - Category = Item::Category class Item @@ -78,15 +63,6 @@ module RSS children09 + [@guid].compact end - alias _tags09 _tags - def _tags - %w(comments author pubDate guid).delete_if do |name| - __send__(name).nil? - end.collect do |elem| - ["", elem] - end + _tags09 - end - alias _setup_maker_element setup_maker_element def setup_maker_element(item) _setup_maker_element(item) diff --git a/lib/rss/image.rb b/lib/rss/image.rb index 3058c84a59..a9e9e9094e 100644 --- a/lib/rss/image.rb +++ b/lib/rss/image.rb @@ -92,15 +92,6 @@ module RSS end private - def _tags - [ - [IMAGE_URI, 'width'], - [IMAGE_URI, 'height'], - ].delete_if do |uri, name| - __send__(name).nil? - end - end - def maker_target(target) target.image_item end diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb index 02cde9b36e..2b7a3111fa 100644 --- a/lib/rss/rss.rb +++ b/lib/rss/rss.rb @@ -144,7 +144,7 @@ module RSS def install_have_child_element(tag_name, uri, occurs, name=nil) name ||= tag_name add_need_initialize_variable(name) - install_model(tag_name, uri, occurs) + install_model(tag_name, uri, occurs, name) attr_accessor name install_element(name) do |n, elem_name| @@ -164,7 +164,7 @@ EOC plural_name ||= "#{name}s" add_have_children_element(name, plural_name) add_plural_form(name, plural_name) - install_model(tag_name, uri, occurs) + install_model(tag_name, uri, occurs, plural_name) def_children_accessor(name, plural_name) install_element(name, "s") do |n, elem_name| @@ -184,7 +184,7 @@ EOC disp_name ||= name self::ELEMENTS << name add_need_initialize_variable(name) - install_model(tag_name, uri, occurs) + install_model(tag_name, uri, occurs, name) def_corresponded_attr_writer name, type, disp_name convert_attr_reader name @@ -213,7 +213,7 @@ EOC disp_name ||= name self::ELEMENTS << name add_need_initialize_variable(name) - install_model(tag_name, uri, occurs) + install_model(tag_name, uri, occurs, name) # accessor convert_attr_reader name @@ -477,11 +477,12 @@ EOC MUST_CALL_VALIDATORS[uri] = prefix end - def self.install_model(tag, uri, occurs=nil) - if m = MODELS.find {|t, u, o| t == tag and u == uri} + def self.install_model(tag, uri, occurs=nil, getter=nil) + getter ||= tag + if m = MODELS.find {|t, u, o, g| t == tag and u == uri} m[2] = occurs else - MODELS << [tag, uri, occurs] + MODELS << [tag, uri, occurs, getter] end end @@ -776,7 +777,17 @@ EOC # default #validate() argument. def _tags - [] + rv = [] + self.class.models.each do |name, uri, occurs, getter| + value = __send__(getter) + next if value.nil? + if value.is_a?(Array) + rv.concat([[uri, name]] * value.size) + else + rv << [uri, name] + end + end + rv end def _attrs @@ -824,7 +835,7 @@ EOC end models.each_with_index do |model, i| - name, model_uri, occurs = model + name, model_uri, occurs, getter = model if DEBUG p "before" diff --git a/lib/rss/taxonomy.rb b/lib/rss/taxonomy.rb index b90820aac6..399857aedb 100644 --- a/lib/rss/taxonomy.rb +++ b/lib/rss/taxonomy.rb @@ -87,12 +87,6 @@ module RSS def children [@Bag] end - - def _tags - rv = [] - rv << [RDF::URI, 'Bag'] unless @Bag.nil? - rv - end end end @@ -148,13 +142,6 @@ module RSS def children [@taxo_link, *@taxo_topics] end - - def _tags - rv = [] - rv << [TAXO_URI, "link"] unless @taxo_link.nil? - rv.concat([TAXO_URI, "topics"] * @taxo_topics.size) - rv - end end end |