diff --git a/ChangeLog b/ChangeLog index 7e1c6019dd..a3fd99e15e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +Wed Nov 3 15:38:28 2004 Kouhei Sutou + + * test/rss/*.rb: removed tab width configuration headers. + + * test/rss/test_maker_{0.9,1.0}.rb: sort -> do_sort. + + * lib/rss/maker/*.rb: changed API to RSS version independence. + + * lib/rss/maker/base.rb + (RSS::Maker::XMLStyleSheets::XMLStyleSheet): checked required + (pseudo) attributes. + + * lib/rss/maker/base.rb (RSS::Maker::Items): sort -> do_sort. + + * lib/rss/rss.rb (RSS::BaseModel.install_date_element): avoided + warning. + + * lib/rss/0.9.rb (RSS::Rss#textinput): added convenience method. + Tue Nov 2 16:35:57 2004 Yukihiro Matsumoto * ext/enumerator/enumerator.c (each_cons_i): pass copy of an @@ -20,7 +39,7 @@ Tue Nov 2 01:20:09 2004 Yukihiro Matsumoto Mon Nov 1 22:25:56 2004 Kouhei Sutou * lib/rss/maker/base.rb: changed xml-stylesheet's API of RSS Maker - like item's one. + like to item's one. * lib/rss/xml-stylesheet.rb (RSS::XMLStyleSheet#guess_type): fixed regular expression bug. diff --git a/lib/rss/0.9.rb b/lib/rss/0.9.rb index d5c6b3a89d..c772e80870 100644 --- a/lib/rss/0.9.rb +++ b/lib/rss/0.9.rb @@ -51,6 +51,14 @@ module RSS end end + def textinput + if @channel + @channel.textInput + else + nil + end + end + def to_s(convert=true, indent=calc_indent) next_indent = indent + INDENT rv = <<-EOR diff --git a/lib/rss/content.rb b/lib/rss/content.rb index 4367d16d92..280bbb8d6b 100644 --- a/lib/rss/content.rb +++ b/lib/rss/content.rb @@ -16,7 +16,7 @@ module RSS def self.append_features(klass) super - klass.module_eval(<<-EOC) + klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1)) %w(encoded).each do |x| install_text_element("\#{CONTENT_PREFIX}_\#{x}") end diff --git a/lib/rss/dublincore.rb b/lib/rss/dublincore.rb index 417ab5b179..7ea9cf31dd 100644 --- a/lib/rss/dublincore.rb +++ b/lib/rss/dublincore.rb @@ -16,7 +16,7 @@ module RSS def self.append_features(klass) super - klass.module_eval(<<-EOC) + klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1)) %w(title description creator subject publisher contributor type format identifier source language relation coverage rights).each do |x| diff --git a/lib/rss/maker/0.9.rb b/lib/rss/maker/0.9.rb index 7223246647..05578082b0 100644 --- a/lib/rss/maker/0.9.rb +++ b/lib/rss/maker/0.9.rb @@ -30,9 +30,6 @@ module RSS class Channel < ChannelBase - alias_method(:pubDate, :date) - alias_method(:pubDate=, :date=) - def to_rss(rss) channel = Rss::Channel.new set = setup_values(channel) @@ -150,7 +147,7 @@ module RSS setup_other_elements(rss) end end - + private def have_required_values? @title and @description and @name and @link diff --git a/lib/rss/maker/2.0.rb b/lib/rss/maker/2.0.rb index 2fa61e80e6..05fc46480a 100644 --- a/lib/rss/maker/2.0.rb +++ b/lib/rss/maker/2.0.rb @@ -48,8 +48,6 @@ module RSS class Item < RSS09::Items::Item - alias_method(:pubDate, :date) - def have_required_values? @title or @description end diff --git a/lib/rss/maker/base.rb b/lib/rss/maker/base.rb index eb61f37ee2..21222351f2 100644 --- a/lib/rss/maker/base.rb +++ b/lib/rss/maker/base.rb @@ -16,26 +16,34 @@ module RSS NEED_INITIALIZE_VARIABLES = [] def self.inherited(subclass) - subclass.const_set("OTHER_ELEMENTS", - OTHER_ELEMENTS.dup) - subclass.const_set("NEED_INITIALIZE_VARIABLES", - NEED_INITIALIZE_VARIABLES.dup) + subclass.const_set("OTHER_ELEMENTS", []) + subclass.const_set("NEED_INITIALIZE_VARIABLES", []) + + subclass.module_eval(<<-EOEOC, __FILE__, __LINE__) + def self.other_elements + const_get("OTHER_ELEMENTS") + super + end + + def self.need_initialize_variables + const_get("NEED_INITIALIZE_VARIABLES") + super + end + EOEOC end def self.add_other_element(variable_name) const_get("OTHER_ELEMENTS") << variable_name end - + def self.other_elements - const_get("OTHER_ELEMENTS") + OTHER_ELEMENTS end def self.add_need_initialize_variable(variable_name) const_get("NEED_INITIALIZE_VARIABLES") << variable_name end - + def self.need_initialize_variables - const_get("NEED_INITIALIZE_VARIABLES") + NEED_INITIALIZE_VARIABLES end EOC end @@ -84,10 +92,10 @@ module RSS end end - + class RSSBase include Base - + class << self def make(&block) new.make(&block) @@ -151,10 +159,12 @@ module RSS class XMLStyleSheets include Base + include Enumerable extend Forwardable def_delegators(:@xml_stylesheets, :<<, :[], :[]=, :first, :last) def_delegators(:@xml_stylesheets, :push, :pop, :shift, :unshift) + def_delegators(:@xml_stylesheets, :each) def initialize(maker) super @@ -183,11 +193,24 @@ module RSS def to_rss(rss) xss = ::RSS::XMLStyleSheet.new + guess_type_if_need(xss) set = setup_values(xss) if set rss.xml_stylesheets << xss end end + + def have_required_values? + @href and @type + end + + private + def guess_type_if_need(xss) + if @type.nil? + xss.href = @href + @type = xss.type + end + end end end @@ -204,6 +227,9 @@ module RSS add_need_initialize_variable(element) end + alias_method(:pubDate, :date) + alias_method(:pubDate=, :date=) + def initialize(maker) super @cloud = make_cloud @@ -253,17 +279,19 @@ module RSS class ItemsBase include Base + include Enumerable extend Forwardable def_delegators(:@items, :<<, :[], :[]=, :first, :last) def_delegators(:@items, :push, :pop, :shift, :unshift) + def_delegators(:@items, :each) - attr_accessor :sort + attr_accessor :do_sort def initialize(maker) super @items = [] - @sort = false + @do_sort = false end def normalize @@ -282,11 +310,11 @@ module RSS private def sort_if_need - if @sort.respond_to?(:call) + if @do_sort.respond_to?(:call) @items.sort do |x, y| - @sort.call(x, y) + @do_sort.call(x, y) end - elsif @sort + elsif @do_sort @items.sort do |x, y| y <=> x end @@ -318,6 +346,9 @@ EOC add_need_initialize_variable(element) end + alias_method(:pubDate, :date) + alias_method(:pubDate=, :date=) + def initialize(maker) super @guid = make_guid diff --git a/lib/rss/maker/content.rb b/lib/rss/maker/content.rb index 67b237f4ef..96f3ccb6d9 100644 --- a/lib/rss/maker/content.rb +++ b/lib/rss/maker/content.rb @@ -13,17 +13,17 @@ module RSS klass.__send__(:attr_accessor, element) klass.module_eval(<<-EOC, __FILE__, __LINE__) def setup_#{element}(rss, current) - current.#{element} = @#{element} if @#{element} + if #{element} and current.respond_to?(:#{element}=) + current.#{element} = @#{element} if @#{element} + end end -EOC + EOC end end end - class RSS10 - class Items - class Item; include ContentModel; end - end + class ItemsBase + class ItemBase; include ContentModel; end end end end diff --git a/lib/rss/maker/dublincore.rb b/lib/rss/maker/dublincore.rb index 6a4c64a464..a9b8d58715 100644 --- a/lib/rss/maker/dublincore.rb +++ b/lib/rss/maker/dublincore.rb @@ -13,35 +13,35 @@ module RSS klass.__send__(:attr_accessor, element) klass.module_eval(<<-EOC, __FILE__, __LINE__) def setup_#{element}(rss, current) - current.#{element} = #{element} if #{element} + if #{element} and current.respond_to?(:#{element}=) + current.#{element} = #{element} + end end EOC end end end - class RSS10 - class Channel - include DublinCoreModel + class ChannelBase + include DublinCoreModel - alias_method(:_dc_date, :dc_date) - alias_method(:_dc_date=, :dc_date=) + undef_method(:dc_date) + undef_method(:dc_date=) + alias_method(:dc_date, :date) + alias_method(:dc_date=, :date=) + end + + class ImageBase; include DublinCoreModel; end + class ItemsBase + class ItemBase + include DublinCoreModel + + undef_method(:dc_date) + undef_method(:dc_date=) alias_method(:dc_date, :date) alias_method(:dc_date=, :date=) end - - class Image; include DublinCoreModel; end - class Items - class Item - include DublinCoreModel - - alias_method(:_dc_date, :dc_date) - alias_method(:_dc_date=, :dc_date=) - alias_method(:dc_date, :date) - alias_method(:dc_date=, :date=) - end - end - class Textinput; include DublinCoreModel; end end + class TextinputBase; include DublinCoreModel; end end end diff --git a/lib/rss/maker/syndication.rb b/lib/rss/maker/syndication.rb index ad846413ae..72d00c63ea 100644 --- a/lib/rss/maker/syndication.rb +++ b/lib/rss/maker/syndication.rb @@ -13,15 +13,15 @@ module RSS klass.__send__(:attr_accessor, element) klass.module_eval(<<-EOC, __FILE__, __LINE__) def setup_#{element}(rss, current) - current.#{element} = @#{element} if @#{element} + if #{element} and current.respond_to?(:#{element}=) + current.#{element} = @#{element} if @#{element} + end end -EOC + EOC end end end - class RSS10 - class Channel; include SyndicationModel; end - end + class ChannelBase; include SyndicationModel; end end end diff --git a/lib/rss/maker/trackback.rb b/lib/rss/maker/trackback.rb index ff0e1abe44..1ec59ab0b0 100644 --- a/lib/rss/maker/trackback.rb +++ b/lib/rss/maker/trackback.rb @@ -14,17 +14,17 @@ module RSS klass.__send__(:attr_accessor, name) klass.module_eval(<<-EOC, __FILE__, __LINE__) def setup_#{name}(rss, current) - current.#{name} = @#{name} if @#{name} + if #{name} and current.respond_to?(:#{name}=) + current.#{name} = @#{name} if @#{name} + end end -EOC + EOC end end end - class RSS10 - class Items - class Item; include TrackBackModel; end - end + class ItemsBase + class ItemBase; include TrackBackModel; end end end end diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb index 231fb1fb62..b6afa24b93 100644 --- a/lib/rss/rss.rb +++ b/lib/rss/rss.rb @@ -4,6 +4,7 @@ # Author:: Kouhei Sutou # Tutorial:: http://www.cozmixng.org/~rwiki/?cmd=view;name=RSS+Parser%3A%3ATutorial.en + require "time" class Time @@ -234,7 +235,7 @@ EOC # Is it need? if @#{name} class << @#{name} - alias_method(:_to_s, :to_s) unless respond_to?(:_to_s) + undef_method(:to_s) alias_method(:to_s, :#{type}) end end diff --git a/lib/rss/syndication.rb b/lib/rss/syndication.rb index b8200ad70d..c274ff8c82 100644 --- a/lib/rss/syndication.rb +++ b/lib/rss/syndication.rb @@ -16,7 +16,7 @@ module RSS def self.append_features(klass) super - klass.module_eval(<<-EOC) + klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1)) %w(updatePeriod updateFrequency).each do |x| install_text_element("\#{SY_PREFIX}_\#{x}") end diff --git a/test/rss/test_1.0.rb b/test/rss/test_1.0.rb index 43a168d035..e6a81af2bd 100644 --- a/test/rss/test_1.0.rb +++ b/test/rss/test_1.0.rb @@ -1,5 +1,3 @@ -# -*- tab-width: 2 -*- vim: ts=2 - require "rexml/document" require "rss-testcase" diff --git a/test/rss/test_accessor.rb b/test/rss/test_accessor.rb index 1b92f9d98c..5281a81c2c 100644 --- a/test/rss/test_accessor.rb +++ b/test/rss/test_accessor.rb @@ -1,5 +1,3 @@ -# -*- tab-width: 2 -*- vim: ts=2 - require "rss-testcase" require "rss/1.0" diff --git a/test/rss/test_content.rb b/test/rss/test_content.rb index c0f6e4292f..77cd1c7005 100644 --- a/test/rss/test_content.rb +++ b/test/rss/test_content.rb @@ -1,5 +1,3 @@ -# -*- tab-width: 2 -*- vim: ts=2 - require "cgi" require "rexml/document" diff --git a/test/rss/test_dublincore.rb b/test/rss/test_dublincore.rb index 796666cdb5..d95d31f24e 100644 --- a/test/rss/test_dublincore.rb +++ b/test/rss/test_dublincore.rb @@ -1,5 +1,3 @@ -# -*- tab-width: 2 -*- vim: ts=2 - require "cgi" require "rexml/document" diff --git a/test/rss/test_maker_0.9.rb b/test/rss/test_maker_0.9.rb index 4ccae45405..df8cd5fe11 100644 --- a/test/rss/test_maker_0.9.rb +++ b/test/rss/test_maker_0.9.rb @@ -279,7 +279,7 @@ module RSS item.link = "#{link}#{i}" item.description = "#{description}#{i}" end - maker.items.sort + maker.items.do_sort = true end assert_equal(item_size, rss.items.size) rss.channel.items.each_with_index do |item, i| @@ -298,7 +298,7 @@ module RSS item.link = "#{link}#{i}" item.description = "#{description}#{i}" end - maker.items.sort = Proc.new do |x, y| + maker.items.do_sort = Proc.new do |x, y| y.title[-1] <=> x.title[-1] end end diff --git a/test/rss/test_maker_1.0.rb b/test/rss/test_maker_1.0.rb index 91ba29d711..8f80f6e2fe 100644 --- a/test/rss/test_maker_1.0.rb +++ b/test/rss/test_maker_1.0.rb @@ -220,7 +220,7 @@ module RSS item.link = "#{link}#{i}" item.description = "#{description}#{i}" end - maker.items.sort = true + maker.items.do_sort = true end assert_equal(item_size, rss.items.size) rss.items.each_with_index do |item, i| @@ -239,7 +239,7 @@ module RSS item.link = "#{link}#{i}" item.description = "#{description}#{i}" end - maker.items.sort = Proc.new do |x, y| + maker.items.do_sort = Proc.new do |x, y| y.title[-1] <=> x.title[-1] end end diff --git a/test/rss/test_maker_2.0.rb b/test/rss/test_maker_2.0.rb index 54375934c4..b0752f985f 100644 --- a/test/rss/test_maker_2.0.rb +++ b/test/rss/test_maker_2.0.rb @@ -340,6 +340,7 @@ module RSS item.comments = "#{comments}#{i}" item.date = pubDate end + maker.items.do_sort = true end assert_equal(item_size, rss.items.size) rss.channel.items.each_with_index do |item, i| @@ -363,7 +364,7 @@ module RSS item.comments = "#{comments}#{i}" item.date = pubDate end - maker.items.sort = Proc.new do |x, y| + maker.items.do_sort = Proc.new do |x, y| y.title[-1] <=> x.title[-1] end end diff --git a/test/rss/test_maker_xml-stylesheet.rb b/test/rss/test_maker_xml-stylesheet.rb index b959073554..bbdfdc682b 100644 --- a/test/rss/test_maker_xml-stylesheet.rb +++ b/test/rss/test_maker_xml-stylesheet.rb @@ -5,7 +5,7 @@ require "rss/maker" module RSS class TestMakerXMLStyleSheet < TestCase - def test_rss10 + def test_xml_stylesheet href = 'a.xsl' type = 'text/xsl' title = 'sample' @@ -47,6 +47,29 @@ module RSS assert_equal(href, xss.href) assert_equal(type, xss.type) end + + def test_not_valid_xml_stylesheet + href = 'xss.XXX' + type = "text/xsl" + + rss = RSS::Maker.make("1.0") do |maker| + xss = maker.xml_stylesheets.new_xml_stylesheet + # xss.href = href + xss.type = type + + setup_dummy_channel(maker) + end + assert(rss.xml_stylesheets.empty?) + + rss = RSS::Maker.make("1.0") do |maker| + xss = maker.xml_stylesheets.new_xml_stylesheet + xss.href = href + # xss.type = type + + setup_dummy_channel(maker) + end + assert(rss.xml_stylesheets.empty?) + end end end diff --git a/test/rss/test_parser.rb b/test/rss/test_parser.rb index 3fd26bffb4..de4894997f 100644 --- a/test/rss/test_parser.rb +++ b/test/rss/test_parser.rb @@ -1,5 +1,3 @@ -# -*- tab-width: 2 -*- vim: ts=2 - require "rss-testcase" require "rss/1.0" diff --git a/test/rss/test_syndication.rb b/test/rss/test_syndication.rb index 9d620089e1..a3dd763c83 100644 --- a/test/rss/test_syndication.rb +++ b/test/rss/test_syndication.rb @@ -1,5 +1,3 @@ -# -*- tab-width: 2 -*- vim: ts=2 - require "cgi" require "rexml/document" diff --git a/test/rss/test_trackback.rb b/test/rss/test_trackback.rb index 9c4b086cae..bfe39d005b 100644 --- a/test/rss/test_trackback.rb +++ b/test/rss/test_trackback.rb @@ -1,5 +1,3 @@ -# -*- tab-width: 2 -*- vim: ts=2 - require "cgi" require "rexml/document" diff --git a/test/rss/test_xml-stylesheet.rb b/test/rss/test_xml-stylesheet.rb index f3dee2c63b..ab16d6e2ff 100644 --- a/test/rss/test_xml-stylesheet.rb +++ b/test/rss/test_xml-stylesheet.rb @@ -1,5 +1,3 @@ -# -*- tab-width: 2 -*- vim: ts=2 - require "rexml/document" require "rss-testcase"