diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/rss.rb | 1 | ||||
-rw-r--r-- | lib/rss/itunes.rb | 2 | ||||
-rw-r--r-- | lib/rss/maker.rb | 1 | ||||
-rw-r--r-- | lib/rss/maker/base.rb | 14 | ||||
-rw-r--r-- | lib/rss/maker/itunes.rb | 8 | ||||
-rw-r--r-- | lib/rss/maker/slash.rb | 33 | ||||
-rw-r--r-- | lib/rss/parser.rb | 3 | ||||
-rw-r--r-- | lib/rss/rss.rb | 22 | ||||
-rw-r--r-- | lib/rss/slash.rb | 49 | ||||
-rw-r--r-- | lib/rss/utils.rb | 6 | ||||
-rw-r--r-- | test/rss/rss-assertions.rb | 12 | ||||
-rw-r--r-- | test/rss/test_maker_slash.rb | 37 | ||||
-rw-r--r-- | test/rss/test_parser.rb | 2 | ||||
-rw-r--r-- | test/rss/test_parser_1.0.rb | 8 | ||||
-rw-r--r-- | test/rss/test_setup_maker_slash.rb | 38 | ||||
-rw-r--r-- | test/rss/test_slash.rb | 64 | ||||
-rw-r--r-- | test/rss/test_version.rb | 2 | ||||
-rw-r--r-- | version.h | 6 |
19 files changed, 296 insertions, 18 deletions
@@ -1,3 +1,9 @@ +Sat Sep 15 13:31:21 2007 Kouhei Sutou <kou@cozmixng.org> + + * lib/rss.rb, lib/rss/, test/rss/: + - 0.1.9 -> 0.2.0. + - supported Slash module. + Fri Sep 14 22:20:01 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> * ext/win32ole/win32ole.c (fev_unadvise): no needs to reset diff --git a/lib/rss.rb b/lib/rss.rb index 8eb860358..a1d0f76ba 100644 --- a/lib/rss.rb +++ b/lib/rss.rb @@ -11,6 +11,7 @@ require 'rss/content' require 'rss/dublincore' require 'rss/image' require 'rss/itunes' +require 'rss/slash' require 'rss/syndication' require 'rss/taxonomy' require 'rss/trackback' diff --git a/lib/rss/itunes.rb b/lib/rss/itunes.rb index 7414bc511..f95ca7aa2 100644 --- a/lib/rss/itunes.rb +++ b/lib/rss/itunes.rb @@ -398,9 +398,9 @@ module RSS element_infos = ITunesChannelModel::ELEMENT_INFOS + ITunesItemModel::ELEMENT_INFOS element_infos.each do |name, type| - class_name = Utils.to_class_name(name) case type when :element, :elements, :attribute + class_name = Utils.to_class_name(name) BaseListener.install_class_name(ITUNES_URI, name, "ITunes#{class_name}") else accessor_base = "#{ITUNES_PREFIX}_#{name.gsub(/-/, '_')}" diff --git a/lib/rss/maker.rb b/lib/rss/maker.rb index e362e785f..666dfa872 100644 --- a/lib/rss/maker.rb +++ b/lib/rss/maker.rb @@ -36,6 +36,7 @@ require "rss/maker/feed" require "rss/maker/entry" require "rss/maker/content" require "rss/maker/dublincore" +require "rss/maker/slash" require "rss/maker/syndication" require "rss/maker/taxonomy" require "rss/maker/trackback" diff --git a/lib/rss/maker/base.rb b/lib/rss/maker/base.rb index 752b2fa58..fdb8946ef 100644 --- a/lib/rss/maker/base.rb +++ b/lib/rss/maker/base.rb @@ -151,6 +151,20 @@ module RSS end EOC end + + def def_csv_element(name, type=nil) + def_other_element_without_accessor(name) + attr_reader(name) + converter = "" + if type == :integer + converter = "{|v| Integer(v)}" + end + module_eval(<<-EOC, __FILE__, __LINE__ + 1) + def #{name}=(value) + @#{name} = Utils::CSV.parse(value)#{converter} + end + EOC + end end attr_reader :maker diff --git a/lib/rss/maker/itunes.rb b/lib/rss/maker/itunes.rb index 86f41e2fd..f02db2882 100644 --- a/lib/rss/maker/itunes.rb +++ b/lib/rss/maker/itunes.rb @@ -52,13 +52,7 @@ module RSS end def def_csv_accessor(klass, full_name) - klass.def_other_element_without_accessor(full_name) - klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1) - attr_reader :#{full_name} - def #{full_name}=(value) - @#{full_name} = Utils::CSV.parse(value) - end - EOC + klass.def_csv_element(full_name) end def def_elements_class_accessor(klass, full_name, full_plural_name, diff --git a/lib/rss/maker/slash.rb b/lib/rss/maker/slash.rb new file mode 100644 index 000000000..27adef383 --- /dev/null +++ b/lib/rss/maker/slash.rb @@ -0,0 +1,33 @@ +require 'rss/slash' +require 'rss/maker/1.0' + +module RSS + module Maker + module SlashModel + def self.append_features(klass) + super + + ::RSS::SlashModel::ELEMENT_INFOS.each do |name, type| + full_name = "#{RSS::SLASH_PREFIX}_#{name}" + case type + when :csv_integer + klass.def_csv_element(full_name, :integer) + else + klass.def_other_element(full_name) + end + end + + klass.module_eval do + alias_method(:slash_hit_parades, :slash_hit_parade) + alias_method(:slash_hit_parades=, :slash_hit_parade=) + end + end + end + + class ItemsBase + class ItemBase + include SlashModel + end + end + end +end diff --git a/lib/rss/parser.rb b/lib/rss/parser.rb index bf3b0b5d0..5856bddf2 100644 --- a/lib/rss/parser.rb +++ b/lib/rss/parser.rb @@ -365,7 +365,8 @@ module RSS def start_else_element(local, prefix, attrs, ns) class_name = self.class.class_name(_ns(ns, prefix), local) current_class = @last_element.class - if current_class.const_defined?(class_name) + if current_class.const_defined?(class_name, false) or + current_class.constants.include?(class_name.to_sym) next_class = current_class.const_get(class_name) start_have_something_element(local, prefix, attrs, ns, next_class) else diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb index db507f78c..e381c8540 100644 --- a/lib/rss/rss.rb +++ b/lib/rss/rss.rb @@ -53,7 +53,7 @@ require "rss/xml-stylesheet" module RSS - VERSION = "0.1.9" + VERSION = "0.2.0" URI = "http://purl.org/rss/1.0/" @@ -361,6 +361,12 @@ EOC end def csv_attr_reader(*attrs) + separator = nil + if attrs.last.is_a?(Hash) + options = attrs.pop + separator = options[:separator] + end + separator ||= ", " attrs.each do |attr| attr = attr.id2name if attr.kind_of?(Integer) module_eval(<<-EOC, __FILE__, __LINE__ + 1) @@ -369,7 +375,7 @@ EOC if @#{attr}.nil? @#{attr} else - @#{attr}.join(", ") + @#{attr}.join(#{separator.dump}) end end EOC @@ -531,6 +537,14 @@ EOC EOC end + def csv_integer_writer(name, disp_name=name) + module_eval(<<-EOC, __FILE__, __LINE__ + 1) + def #{name}=(new_value) + @#{name} = Utils::CSV.parse(new_value) {|v| Integer(v)} + end + EOC + end + def def_children_accessor(accessor_name, plural_name) module_eval(<<-EOC, *get_file_and_line_from_caller(2)) def #{plural_name} @@ -720,6 +734,8 @@ EOC yes_other_writer name, disp_name when :csv csv_writer name + when :csv_integer + csv_integer_writer name else attr_writer name end @@ -737,6 +753,8 @@ EOC yes_other_attr_reader name when :csv csv_attr_reader name + when :csv_integer + csv_attr_reader name, :separator => "," else convert_attr_reader name end diff --git a/lib/rss/slash.rb b/lib/rss/slash.rb new file mode 100644 index 000000000..f102413b4 --- /dev/null +++ b/lib/rss/slash.rb @@ -0,0 +1,49 @@ +require 'rss/1.0' + +module RSS + SLASH_PREFIX = 'slash' + SLASH_URI = "http://purl.org/rss/1.0/modules/slash/" + + RDF.install_ns(SLASH_PREFIX, SLASH_URI) + + module SlashModel + extend BaseModel + + ELEMENT_INFOS = \ + [ + ["section"], + ["department"], + ["comments", :positive_integer], + ["hit_parade", :csv_integer], + ] + + class << self + def append_features(klass) + super + + return if klass.instance_of?(Module) + klass.install_must_call_validator(SLASH_PREFIX, SLASH_URI) + ELEMENT_INFOS.each do |name, type, *additional_infos| + full_name = "#{SLASH_PREFIX}_#{name}" + klass.install_text_element(full_name, SLASH_URI, "?", + full_name, type, name) + end + + klass.module_eval do + alias_method(:slash_hit_parades, :slash_hit_parade) + undef_method(:slash_hit_parade) + alias_method(:slash_hit_parade, :slash_hit_parade_content) + end + end + end + end + + class RDF + class Item; include SlashModel; end + end + + SlashModel::ELEMENT_INFOS.each do |name, type| + accessor_base = "#{SLASH_PREFIX}_#{name}" + BaseListener.install_get_text_element(SLASH_URI, name, accessor_base) + end +end diff --git a/lib/rss/utils.rb b/lib/rss/utils.rb index 0b53a19d3..a24fc173d 100644 --- a/lib/rss/utils.rb +++ b/lib/rss/utils.rb @@ -62,9 +62,11 @@ module RSS module CSV module_function - def parse(value) + def parse(value, &block) if value.is_a?(String) - value.strip.split(/\s*,\s*/) + value = value.strip.split(/\s*,\s*/) + value = value.collect(&block) if block_given? + value else value end diff --git a/test/rss/rss-assertions.rb b/test/rss/rss-assertions.rb index 3b212c794..41e6cd62c 100644 --- a/test/rss/rss-assertions.rb +++ b/test/rss/rss-assertions.rb @@ -2018,6 +2018,18 @@ EOA end end + def assert_slash_elements(expected, target) + assert_equal(expected, + { + "section" => target.slash_section, + "department" => target.slash_department, + "comments" => target.slash_comments, + "hit_parades" => target.slash_hit_parades, + }) + assert_equal(expected["hit_parades"].join(","), + target.slash_hit_parade) + end + def chain_reader(target, readers, &block) readers.inject(target) do |result, reader| return nil if result.nil? diff --git a/test/rss/test_maker_slash.rb b/test/rss/test_maker_slash.rb new file mode 100644 index 000000000..f2fbf9a23 --- /dev/null +++ b/test/rss/test_maker_slash.rb @@ -0,0 +1,37 @@ +require "rss-testcase" + +require "rss/maker" + +module RSS + class TestMakerSlash < TestCase + def setup + @elements = { + "section" => "articles", + "department" => "not-an-ocean-unless-there-are-lobsters", + "comments" => 177, + "hit_parades" => [177, 155, 105, 33, 6, 3, 0], + } + end + + def test_rss10 + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + setup_dummy_item(maker) + item = maker.items.last + @elements.each do |name, value| + item.send("slash_#{name}=", value) + end + end + + item = rss.items.last + assert_not_nil(item) + assert_slash_elements(item) + end + + private + def assert_slash_elements(target) + super(@elements, target) + end + end +end diff --git a/test/rss/test_parser.rb b/test/rss/test_parser.rb index 45f31e201..59458ef51 100644 --- a/test/rss/test_parser.rb +++ b/test/rss/test_parser.rb @@ -1,4 +1,4 @@ -require 'fileutils' +require "fileutils" require "rss-testcase" diff --git a/test/rss/test_parser_1.0.rb b/test/rss/test_parser_1.0.rb index 472602b04..1c4e53c1d 100644 --- a/test/rss/test_parser_1.0.rb +++ b/test/rss/test_parser_1.0.rb @@ -498,6 +498,14 @@ EOR Parser.parse(rss, true, false) end end + + def test_unknown_duplicated_element + assert_parse(make_RDF(<<-EOR), :nothing_raised) + #{make_channel("<test:string/>")} + #{make_item} + #{make_image} + EOR + end end end diff --git a/test/rss/test_setup_maker_slash.rb b/test/rss/test_setup_maker_slash.rb new file mode 100644 index 000000000..07fa5bb34 --- /dev/null +++ b/test/rss/test_setup_maker_slash.rb @@ -0,0 +1,38 @@ +require "rss-testcase" + +require "rss/maker" + +module RSS + class TestSetupMakerSlash < TestCase + def test_setup_maker + elements = { + "section" => "articles", + "department" => "not-an-ocean-unless-there-are-lobsters", + "comments" => 177, + "hit_parades" => [177, 155, 105, 33, 6, 3, 0], + } + + rss = RSS::Maker.make("rss1.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + item = maker.items.last + item.slash_section = elements["section"] + item.slash_department = elements["department"] + item.slash_comments = elements["comments"] + item.slash_hit_parade = elements["hit_parades"].join(",") + end + assert_not_nil(rss) + + new_rss = RSS::Maker.make("rss1.0") do |maker| + rss.setup_maker(maker) + end + assert_not_nil(new_rss) + + item = new_rss.items.last + assert_not_nil(item) + + assert_slash_elements(elements, item) + end + end +end diff --git a/test/rss/test_slash.rb b/test/rss/test_slash.rb new file mode 100644 index 000000000..aec0a868f --- /dev/null +++ b/test/rss/test_slash.rb @@ -0,0 +1,64 @@ +require "cgi" +require "rexml/document" + +require "rss-testcase" + +require "rss/1.0" +require "rss/slash" + +module RSS + class TestSlash < TestCase + def setup + @elements = { + "section" => "articles", + "department" => "not-an-ocean-unless-there-are-lobsters", + "comments" => 177, + "hit_parades" => [177, 155, 105, 33, 6, 3, 0], + } + + slash_nodes = @elements.collect do |name, value| + if name == "hit_parades" + name = "hit_parade" + value = value.join(",") + end + "<slash:#{name}>#{value}</slash:#{name}>" + end.join("\n") + + slash_ns = {"slash" => "http://purl.org/rss/1.0/modules/slash/"} + @source = make_RDF(<<-EOR, slash_ns) +#{make_channel} +#{make_image} +#{make_item(slash_nodes)} +#{make_textinput} +EOR + end + + def test_parser + rss = RSS::Parser.parse(@source) + + assert_not_nil(rss) + + item = rss.items[0] + assert_not_nil(item) + + assert_slash_elements(item) + end + + def test_to_s + rss = RSS::Parser.parse(@source) + rss = RSS::Parser.parse(rss.to_s) + + assert_not_nil(rss) + + item = rss.items[0] + assert_not_nil(item) + + assert_slash_elements(item) + end + + private + def assert_slash_elements(target) + super(@elements, target) + end + end +end diff --git a/test/rss/test_version.rb b/test/rss/test_version.rb index 8e63af7c2..9b64f0d4e 100644 --- a/test/rss/test_version.rb +++ b/test/rss/test_version.rb @@ -3,7 +3,7 @@ require "rss-testcase" module RSS class TestVersion < TestCase def test_version - assert_equal("0.1.9", ::RSS::VERSION) + assert_equal("0.2.0", ::RSS::VERSION) end end end @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.9.0" -#define RUBY_RELEASE_DATE "2007-09-14" +#define RUBY_RELEASE_DATE "2007-09-15" #define RUBY_VERSION_CODE 190 -#define RUBY_RELEASE_CODE 20070914 +#define RUBY_RELEASE_CODE 20070915 #define RUBY_PATCHLEVEL 0 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 0 #define RUBY_RELEASE_YEAR 2007 #define RUBY_RELEASE_MONTH 9 -#define RUBY_RELEASE_DAY 14 +#define RUBY_RELEASE_DAY 15 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; |