diff options
author | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-12-04 09:53:01 +0000 |
---|---|---|
committer | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-12-04 09:53:01 +0000 |
commit | 636e37fcb940f845c2323e055f063cd4aec5f7d4 (patch) | |
tree | 618a183f3d527c76f31bb169a349671feac04faa | |
parent | 5262bd8a2c445534408d947bd5d96c4da488e8c9 (diff) | |
download | ruby-636e37fcb940f845c2323e055f063cd4aec5f7d4.tar.gz |
* lib/rss/rss.rb (RSS::VERSION): 0.1.1 -> 0.1.2
* lib/rss/rss.rb: #item=/#set_item and so on are obsolete.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/rss/maker/2.0.rb | 4 | ||||
-rw-r--r-- | lib/rss/parser.rb | 7 | ||||
-rw-r--r-- | lib/rss/rss.rb | 31 |
4 files changed, 40 insertions, 8 deletions
@@ -1,3 +1,9 @@ +Sat Dec 4 18:49:09 2004 Kouhei Sutou <kou@cozmixng.org> + + * lib/rss/rss.rb (RSS::VERSION): 0.1.1 -> 0.1.2 + + * lib/rss/rss.rb: #item=/#set_item and so on are obsolete. + Sat Dec 4 14:28:56 2004 Dave Thomas <dave@pragprog.com> * lib/rdoc/code_objects.rb (RDoc::Context::Section::set_comment): diff --git a/lib/rss/maker/2.0.rb b/lib/rss/maker/2.0.rb index 9094b1e73b..a958661614 100644 --- a/lib/rss/maker/2.0.rb +++ b/lib/rss/maker/2.0.rb @@ -59,7 +59,7 @@ module RSS category = Rss::Channel::Category.new set = setup_values(category) if set - channel.category = category + channel.categories << category setup_other_elements(rss) end end @@ -145,7 +145,7 @@ module RSS category = Rss::Channel::Item::Category.new set = setup_values(category) if set - item.category = category + item.categories << category setup_other_elements(rss) end end diff --git a/lib/rss/parser.rb b/lib/rss/parser.rb index e1da24418a..1030c8f5d4 100644 --- a/lib/rss/parser.rb +++ b/lib/rss/parser.rb @@ -364,10 +364,9 @@ module RSS previous = @last_element next_element = klass.send(:new, *args) next_element.do_validate = @do_validate - setter = "" - setter << "#{klass.required_prefix}_" if klass.required_prefix - setter << "#{tag_name}=" - @last_element.send(setter, next_element) + prefix = "" + prefix << "#{klass.required_prefix}_" if klass.required_prefix + previous.__send__(:set_next_element, prefix, tag_name, next_element) @last_element = next_element @proc_stack.push Proc.new { |text, tags| p(@last_element.class) if DEBUG diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb index c180a70b5d..fc1dabf518 100644 --- a/lib/rss/rss.rb +++ b/lib/rss/rss.rb @@ -58,7 +58,7 @@ require "rss/xml-stylesheet" module RSS - VERSION = "0.1.1" + VERSION = "0.1.2" URI = "http://purl.org/rss/1.0/" @@ -176,6 +176,7 @@ EOC def install_have_children_element(name, plural_name=nil) plural_name ||= "#{name}s" add_have_children_element(name, plural_name) + add_plural_form(name, plural_name) def_children_accessor(name, plural_name) install_element(name, "s") do |n, elem_name| @@ -312,8 +313,12 @@ EOC @#{accessor_name}.send("[]", *args) end end - + def #{accessor_name}=(*args) + warn("Warning:\#{caller.first.sub(/:in `.*'\z/, '')}: " \ + "Don't use `#{accessor_name} = XXX'/`set_#{accessor_name}(XXX)'. " \ + "Those APIs are not sense of Ruby. " \ + "Use `#{plural_name} << XXX' instead of them.") if args.size == 1 @#{accessor_name}.push(args[0]) else @@ -428,6 +433,16 @@ EOC @@need_initialize_variables end + @@plural_forms = {} + + def self.add_plural_form(singular, plural) + @@plural_forms[singular] = plural + end + + def self.plural_forms + @@plural_forms + end + EOC end @@ -604,6 +619,18 @@ EOC end end end + + def set_next_element(prefix, tag_name, next_element) + klass = next_element.class + prefix = "" + prefix << "#{klass.required_prefix}_" if klass.required_prefix + if self.class.plural_forms.has_key?(tag_name) + ary = __send__("#{prefix}#{self.class.plural_forms[tag_name]}") + ary << next_element + else + __send__("#{prefix}#{tag_name}=", next_element) + end + end # not String class children. def children |