From 6cfd4dd1228831ea476be2f2c60e0bdd69d23eeb Mon Sep 17 00:00:00 2001 From: kou Date: Sun, 18 Jun 2006 15:06:55 +0000 Subject: * lib/rss/rss.rb: automatically detected attributes. * lib/rss/0.9.rb: removed #_attrs. * lib/rss/1.0.rb: ditto. * lib/rss/2.0.rb: ditto. * lib/rss/image.rb: ditto. * lib/rss/taxonomy.rb: ditto. * lib/rss/trackback.rb: ditto. * lib/rss/parser.rb: followed new internal API. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10320 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 13 +++++++++++ lib/rss/0.9.rb | 31 +----------------------- lib/rss/1.0.rb | 66 +++++++++++----------------------------------------- lib/rss/2.0.rb | 6 ----- lib/rss/image.rb | 30 +++++++----------------- lib/rss/parser.rb | 2 +- lib/rss/rss.rb | 11 ++++++--- lib/rss/taxonomy.rb | 9 ++----- lib/rss/trackback.rb | 25 +++++--------------- 9 files changed, 54 insertions(+), 139 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8b2d890266..76a6994c51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Mon Jun 19 00:02:17 2006 Kouhei Sutou + + * lib/rss/rss.rb: automatically detected attributes. + + * lib/rss/0.9.rb: removed #_attrs. + * lib/rss/1.0.rb: ditto. + * lib/rss/2.0.rb: ditto. + * lib/rss/image.rb: ditto. + * lib/rss/taxonomy.rb: ditto. + * lib/rss/trackback.rb: ditto. + + * lib/rss/parser.rb: followed new internal API. + Mon Jun 19 00:00:17 2006 Hidetoshi NAGAI * ext/tk/lib/multi-tk.rb: fix bug: initialize improper tables. diff --git a/lib/rss/0.9.rb b/lib/rss/0.9.rb index f614eff0c8..4bb6a6e4b3 100644 --- a/lib/rss/0.9.rb +++ b/lib/rss/0.9.rb @@ -395,7 +395,7 @@ module RSS class Cloud < Element include RSS09 - + [ ["domain", "", true], ["port", "", true, :integer], @@ -424,14 +424,6 @@ module RSS rv = convert(rv) if need_convert rv end - - private - def _attrs - %w(domain port path registerProcedure protocol).collect do |attr| - [attr, true] - end - end - end class Item < Element @@ -540,13 +532,6 @@ module RSS [] end - def _attrs - [ - ["url", true] - ] - end - - def maker_target(item) item.source end @@ -587,14 +572,6 @@ module RSS end private - def _attrs - [ - ["url", true], - ["length", true], - ["type", true], - ] - end - def maker_target(item) item.enclosure end @@ -629,12 +606,6 @@ module RSS end private - def _attrs - [ - ["domain", false] - ] - end - def maker_target(item) item.new_category end diff --git a/lib/rss/1.0.rb b/lib/rss/1.0.rb index 4438c40d33..9410fceb6a 100644 --- a/lib/rss/1.0.rb +++ b/lib/rss/1.0.rb @@ -125,13 +125,6 @@ module RSS rv = convert(rv) if need_convert rv end - - private - def _attrs - [ - ["resource", true] - ] - end end class Seq < Element @@ -277,7 +270,8 @@ module RSS [ ["about", URI, true] ].each do |name, uri, required| - install_get_attribute(name, uri, required) + install_get_attribute(name, uri, required, nil, nil, + "#{PREFIX}:#{name}") end %w(title link description).each do |name| @@ -342,12 +336,6 @@ module RSS end end - def _attrs - [ - ["#{PREFIX}:about", true, "about"] - ] - end - def maker_target(maker) maker.channel end @@ -371,7 +359,8 @@ module RSS [ ["resource", URI, true] ].each do |name, uri, required| - install_get_attribute(name, uri, required) + install_get_attribute(name, uri, required, nil, nil, + "#{PREFIX}:#{name}") end def initialize(*args) @@ -388,13 +377,6 @@ module RSS rv = convert(rv) if need_convert rv end - - private - def _attrs - [ - ["#{PREFIX}:resource", true, "resource"] - ] - end end class Textinput < Element @@ -412,7 +394,8 @@ module RSS [ ["resource", URI, true] ].each do |name, uri, required| - install_get_attribute(name, uri, required) + install_get_attribute(name, uri, required, nil, nil, + "#{PREFIX}:#{name}") end def initialize(*args) @@ -429,13 +412,6 @@ module RSS rv = convert(rv) if need_convert rv end - - private - def _attrs - [ - ["#{PREFIX}:resource", true, "resource"] - ] - end end class Items < Element @@ -513,11 +489,12 @@ module RSS end end - + [ ["about", URI, true] ].each do |name, uri, required| - install_get_attribute(name, uri, required) + install_get_attribute(name, uri, required, nil, nil, + "#{PREFIX}:#{name}") end %w(title url link).each do |name| @@ -565,12 +542,6 @@ module RSS end end - def _attrs - [ - ["#{PREFIX}:about", true, "about"] - ] - end - def maker_target(maker) maker.image end @@ -588,10 +559,12 @@ module RSS end + [ ["about", URI, true] ].each do |name, uri, required| - install_get_attribute(name, uri, required) + install_get_attribute(name, uri, required, nil, nil, + "#{PREFIX}:#{name}") end %w(title link description).each do |name| @@ -639,12 +612,6 @@ module RSS end end - def _attrs - [ - ["#{PREFIX}:about", true, "about"] - ] - end - def maker_target(items) if items.respond_to?("items") # For backward compatibility @@ -669,7 +636,8 @@ module RSS [ ["about", URI, true] ].each do |name, uri, required| - install_get_attribute(name, uri, required) + install_get_attribute(name, uri, required, nil, nil, + "#{PREFIX}:#{name}") end %w(title description name link).each do |name| @@ -719,12 +687,6 @@ module RSS __send__(name).nil? end end - - def _attrs - [ - ["#{PREFIX}:about", true, "about"] - ] - end def maker_target(maker) maker.textinput diff --git a/lib/rss/2.0.rb b/lib/rss/2.0.rb index 6ba22805b0..5f8da1f4f7 100644 --- a/lib/rss/2.0.rb +++ b/lib/rss/2.0.rb @@ -149,12 +149,6 @@ EOT end private - def _attrs - [ - ["isPermaLink", false] - ] - end - def maker_target(item) item.guid end diff --git a/lib/rss/image.rb b/lib/rss/image.rb index 9b86644ff7..e4557bfeb9 100644 --- a/lib/rss/image.rb +++ b/lib/rss/image.rb @@ -55,12 +55,13 @@ module RSS IMAGE_URI end end - + [ ["about", ::RSS::RDF::URI, true], ["resource", ::RSS::RDF::URI, false], ].each do |name, uri, required| - install_get_attribute(name, uri, required) + install_get_attribute(name, uri, required, nil, nil, + "#{::RSS::RDF::PREFIX}:#{name}") end %w(width height).each do |tag| @@ -108,13 +109,6 @@ module RSS __send__(name).nil? end end - - def _attrs - [ - ["#{::RSS::RDF::PREFIX}:about", true, "about"], - ["#{::RSS::RDF::PREFIX}:resource", false, "resource"], - ] - end def maker_target(target) target.image_item @@ -158,12 +152,13 @@ module RSS IMAGE_URI end end - + [ - ["about", ::RSS::RDF::URI, true], - ["size", IMAGE_URI, true], - ].each do |name, uri, required| - install_get_attribute(name, uri, required) + ["about", ::RSS::RDF::URI, true, ::RSS::RDF::PREFIX], + ["size", IMAGE_URI, true, IMAGE_PREFIX], + ].each do |name, uri, required, prefix| + install_get_attribute(name, uri, required, nil, nil, + "#{prefix}:#{name}") end AVAILABLE_SIZES = %w(small medium large) @@ -208,13 +203,6 @@ module RSS end private - def _attrs - [ - ["#{::RSS::RDF::PREFIX}:about", true, "about"], - ["#{IMAGE_PREFIX}:size", true, "size"], - ] - end - def maker_target(target) target.image_favicon end diff --git a/lib/rss/parser.rb b/lib/rss/parser.rb index 9b9163dad2..a59c16f007 100644 --- a/lib/rss/parser.rb +++ b/lib/rss/parser.rb @@ -378,7 +378,7 @@ module RSS check_ns(tag_name, prefix, ns, klass.required_uri) attributes = {} - klass.get_attributes.each do |a_name, a_uri, required| + klass.get_attributes.each do |a_name, a_uri, required, element_name| if a_uri.is_a?(String) or !a_uri.respond_to?(:include?) a_uri = [a_uri] diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb index 5900d5078c..ab4dd1d87a 100644 --- a/lib/rss/rss.rb +++ b/lib/rss/rss.rb @@ -482,13 +482,16 @@ EOC end def self.install_get_attribute(name, uri, required=true, - type=nil, disp_name=name) + type=nil, disp_name=nil, + element_name=nil) + disp_name ||= name + element_name ||= name def_corresponded_attr_writer name, type, disp_name convert_attr_reader name if type == :boolean and /^is/ =~ name alias_method "\#{$POSTMATCH}?", name end - GET_ATTRIBUTES << [name, uri, required] + GET_ATTRIBUTES << [name, uri, required, element_name] add_need_initialize_variable(disp_name) end @@ -751,7 +754,9 @@ EOC end def _attrs - [] + self.class.get_attributes.collect do |name, uri, required, element_name| + [element_name, required, name] + end end def __validate(ignore_unknown_element, tags=_tags, recursive=true) diff --git a/lib/rss/taxonomy.rb b/lib/rss/taxonomy.rb index 70a9d442cd..7dd22707f7 100644 --- a/lib/rss/taxonomy.rb +++ b/lib/rss/taxonomy.rb @@ -157,7 +157,8 @@ module RSS @tag_name = "topic" - install_get_attribute("about", ::RSS::RDF::URI, true) + install_get_attribute("about", ::RSS::RDF::URI, true, nil, nil, + "#{RDF::PREFIX}:about") install_text_element("#{TAXO_PREFIX}_link") def initialize(*args) @@ -205,12 +206,6 @@ module RSS [@taxo_link, @taxo_topics] end - def _attrs - [ - ["#{RDF::PREFIX}:about", true, "about"] - ] - end - def _tags rv = [] rv << [TAXO_URI, "link"] unless @taxo_link.nil? diff --git a/lib/rss/trackback.rb b/lib/rss/trackback.rb index 32e431c674..277bb738d5 100644 --- a/lib/rss/trackback.rb +++ b/lib/rss/trackback.rb @@ -126,16 +126,16 @@ module RSS end @tag_name = "ping" - + [ ["resource", ::RSS::RDF::URI, true] ].each do |name, uri, required| - install_get_attribute(name, uri, required) + install_get_attribute(name, uri, required, nil, nil, + "#{::RSS::RDF::PREFIX}:#{name}") end alias_method(:value, :resource) alias_method(:value=, :resource=) - def initialize(*args) if Utils.element_initialize_arguments?(args) super @@ -154,14 +154,6 @@ module RSS rv = convert(rv) if need_convert rv end - - private - def _attrs - [ - ["#{::RSS::RDF::PREFIX}:resource", true, "resource"], - ] - end - end class TrackBackAbout < Element @@ -180,11 +172,12 @@ module RSS end @tag_name = "about" - + [ ["resource", ::RSS::RDF::URI, true] ].each do |name, uri, required| - install_get_attribute(name, uri, required) + install_get_attribute(name, uri, required, nil, nil, + "#{::RSS::RDF::PREFIX}:#{name}") end alias_method(:value, :resource) @@ -210,12 +203,6 @@ module RSS end private - def _attrs - [ - ["#{::RSS::RDF::PREFIX}:resource", true, "resource"], - ] - end - def maker_target(abouts) abouts.new_about end -- cgit v1.2.3