summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--NEWS8
-rw-r--r--lib/rss/atom.rb1
-rw-r--r--lib/rss/maker/base.rb46
-rw-r--r--lib/rss/maker/itunes.rb2
-rw-r--r--lib/rss/parser.rb30
-rw-r--r--lib/rss/rss.rb5
-rw-r--r--test/rss/rss-assertions.rb48
-rw-r--r--test/rss/test_atom.rb2
-rw-r--r--test/rss/test_maker_0.9.rb5
-rw-r--r--test/rss/test_maker_1.0.rb7
-rw-r--r--test/rss/test_maker_2.0.rb5
-rw-r--r--test/rss/test_maker_dc.rb5
-rw-r--r--test/rss/test_maker_itunes.rb2
-rw-r--r--test/rss/test_parser_1.0.rb1
-rw-r--r--test/rss/test_version.rb2
16 files changed, 120 insertions, 60 deletions
diff --git a/ChangeLog b/ChangeLog
index 7b4db6b74b..37bae634f6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Sun Jun 29 18:09:00 2008 Kouhei Sutou <[email protected]>
+
+ * NEWS: add an entry for rss.
+
+ * lib/rss/, test/rss/: merge from trunk.
+ - 0.2.4 -> 0.2.5.
+ - RSS::Maker.make raise an exception not returns nil for invalid
+ feed making.
+ - RSS::Maker.make requires block.
+ - don't use instance_variable to initialize variables. (speed up)
+
Sun Jun 29 10:59:12 2008 Tanaka Akira <[email protected]>
* math.c (domain_check): fix preprocess condition.
diff --git a/NEWS b/NEWS
index 492f02339c..2a3ba7bffa 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,14 @@ with all sufficient information, see the ChangeLog file.
Return an enumerator if no block is given.
+* rss
+
+ * 0.2.4 -> 0.2.5
+
+ * RSS::Maker.make
+ * raise an exception not returns nil for invalid feed making.
+ * requires block.
+
== Changes since the 1.8.6 release
=== Configuration changes
diff --git a/lib/rss/atom.rb b/lib/rss/atom.rb
index 7cba934feb..10282a8743 100644
--- a/lib/rss/atom.rb
+++ b/lib/rss/atom.rb
@@ -1,4 +1,3 @@
-require 'base64'
require 'rss/parser'
module RSS
diff --git a/lib/rss/maker/base.rb b/lib/rss/maker/base.rb
index 56bf04657e..2262a764ec 100644
--- a/lib/rss/maker/base.rb
+++ b/lib/rss/maker/base.rb
@@ -31,7 +31,9 @@ module RSS
self::OTHER_ELEMENTS << variable_name
end
- def add_need_initialize_variable(variable_name, init_value="nil")
+ def add_need_initialize_variable(variable_name, init_value=nil,
+ &init_block)
+ init_value ||= init_block
self::NEED_INITIALIZE_VARIABLES << [variable_name, init_value]
end
@@ -45,7 +47,7 @@ module RSS
def_delegators("@#{plural}", :push, :pop, :shift, :unshift)
def_delegators("@#{plural}", :each, :size, :empty?, :clear)
- add_need_initialize_variable(plural, "[]")
+ add_need_initialize_variable(plural) {[]}
module_eval(<<-EOC, __FILE__, __LINE__ + 1)
def new_#{name}
@@ -74,7 +76,9 @@ module RSS
def def_classed_element_without_accessor(name, class_name=nil)
class_name ||= Utils.to_class_name(name)
add_other_element(name)
- add_need_initialize_variable(name, "make_#{name}")
+ add_need_initialize_variable(name) do |object|
+ object.send("make_#{name}")
+ end
module_eval(<<-EOC, __FILE__, __LINE__ + 1)
private
def setup_#{name}(feed, current)
@@ -185,7 +189,19 @@ module RSS
private
def initialize_variables
self.class.need_initialize_variables.each do |variable_name, init_value|
- instance_eval("@#{variable_name} = #{init_value}", __FILE__, __LINE__)
+ if init_value.nil?
+ value = nil
+ else
+ if init_value.respond_to?(:call)
+ value = init_value.call(self)
+ elsif init_value.is_a?(String)
+ # just for backward compatibility
+ value = instance_eval(init_value, __FILE__, __LINE__)
+ else
+ value = init_value
+ end
+ end
+ instance_variable_set("@#{variable_name}", value)
end
end
@@ -238,7 +254,8 @@ module RSS
def variables
self.class.need_initialize_variables.find_all do |name, init|
- "nil" == init
+ # init == "nil" is just for backward compatibility
+ init.nil? or init == "nil"
end.collect do |name, init|
name
end
@@ -364,7 +381,9 @@ module RSS
%w(xml_stylesheets channel image items textinput).each do |element|
attr_reader element
- add_need_initialize_variable(element, "make_#{element}")
+ add_need_initialize_variable(element) do |object|
+ object.send("make_#{element}")
+ end
module_eval(<<-EOC, __FILE__, __LINE__)
private
def setup_#{element}(feed)
@@ -392,12 +411,8 @@ module RSS
end
def make
- if block_given?
- yield(self)
- to_feed
- else
- nil
- end
+ yield(self)
+ to_feed
end
def to_feed
@@ -405,11 +420,8 @@ module RSS
setup_xml_stylesheets(feed)
setup_elements(feed)
setup_other_elements(feed)
- if feed.valid?
- feed
- else
- nil
- end
+ feed.validate
+ feed
end
private
diff --git a/lib/rss/maker/itunes.rb b/lib/rss/maker/itunes.rb
index 7c5049129d..8b7420da3c 100644
--- a/lib/rss/maker/itunes.rb
+++ b/lib/rss/maker/itunes.rb
@@ -176,7 +176,7 @@ module RSS
%w(hour minute second).each do |name|
attr_reader(name)
- add_need_initialize_variable(name, '0')
+ add_need_initialize_variable(name, 0)
end
def content=(content)
diff --git a/lib/rss/parser.rb b/lib/rss/parser.rb
index 9e4919223c..9b28f0fa8a 100644
--- a/lib/rss/parser.rb
+++ b/lib/rss/parser.rb
@@ -34,8 +34,8 @@ module RSS
class NotValidXMLParser < Error
def initialize(parser)
super("#{parser} is not an available XML parser. " <<
- "Available XML parser"<<
- (AVAILABLE_PARSERS.size > 1 ? "s are ": " is ") <<
+ "Available XML parser" <<
+ (AVAILABLE_PARSERS.size > 1 ? "s are " : " is ") <<
"#{AVAILABLE_PARSERS.inspect}.")
end
end
@@ -113,7 +113,7 @@ module RSS
source.is_a?(String) and /</ =~ source
end
- # Attempt to convert rss to a URI, but just return it if
+ # Attempt to convert rss to a URI, but just return it if
# there's a ::URI::Error
def to_uri(rss)
return rss if rss.is_a?(::URI::Generic)
@@ -220,9 +220,7 @@ module RSS
name = (@@class_names[uri] || {})[tag_name]
return name if name
- tag_name = tag_name.gsub(/[_\-]([a-z]?)/) do
- $1.upcase
- end
+ tag_name = tag_name.gsub(/[_\-]([a-z]?)/) {$1.upcase}
tag_name[0, 1].upcase + tag_name[1..-1]
end
@@ -389,9 +387,7 @@ 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 class_name and
- (current_class.const_defined?(class_name) or
- current_class.constants.include?(class_name))
+ if known_class?(current_class, class_name)
next_class = current_class.const_get(class_name)
start_have_something_element(local, prefix, attrs, ns, next_class)
else
@@ -407,6 +403,20 @@ module RSS
end
end
+ if Module.method(:const_defined?).arity == -1
+ def known_class?(target_class, class_name)
+ class_name and
+ (target_class.const_defined?(class_name, false) or
+ target_class.constants.include?(class_name.to_sym))
+ end
+ else
+ def known_class?(target_class, class_name)
+ class_name and
+ (target_class.const_defined?(class_name) or
+ target_class.constants.include?(class_name))
+ end
+ end
+
NAMESPLIT = /^(?:([\w:][-\w\d.]*):)?([\w:][-\w\d.]*)/
def split_name(name)
name =~ NAMESPLIT
@@ -504,7 +514,7 @@ module RSS
else
if klass.have_content?
if @last_element.need_base64_encode?
- text = Base64.decode64(text.lstrip)
+ text = text.lstrip.unpack("m").first
end
@last_element.content = text
end
diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb
index 5aa4a2cedd..4b943ec55b 100644
--- a/lib/rss/rss.rb
+++ b/lib/rss/rss.rb
@@ -45,6 +45,7 @@ class Time
end
end
+
require "English"
require "rss/utils"
require "rss/converter"
@@ -52,7 +53,7 @@ require "rss/xml-stylesheet"
module RSS
- VERSION = "0.2.4"
+ VERSION = "0.2.5"
URI = "http://purl.org/rss/1.0/"
@@ -1200,7 +1201,7 @@ EOC
__send__(self.class.xml_getter).to_s
else
_content = content
- _content = Base64.encode64(_content) if need_base64_encode?
+ _content = [_content].pack("m").delete("\n") if need_base64_encode?
h(_content)
end
end
diff --git a/test/rss/rss-assertions.rb b/test/rss/rss-assertions.rb
index 41e6cd62c5..f396e9a446 100644
--- a/test/rss/rss-assertions.rb
+++ b/test/rss/rss-assertions.rb
@@ -570,7 +570,7 @@ EOA
text << char
char.succ!
end
- base64_content = Base64.encode64(Zlib::Deflate.deflate(text))
+ base64_content = [Zlib::Deflate.deflate(text)].pack("m").delete("\n")
[false, true].each do |with_space|
xml_content = base64_content
@@ -1272,22 +1272,32 @@ EOA
invalid_feed_checker=nil)
_wrap_assertion do
elements = []
- invalid_feed = false
- feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
- yield maker
- targets = chain_reader(maker, maker_readers)
- targets.each do |target|
- element = maker_extractor.call(target)
- elements << element if element
+ invalid_feed_exception = nil
+ feed = nil
+ begin
+ feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
+ yield maker
+ targets = chain_reader(maker, maker_readers)
+ targets.each do |target|
+ element = maker_extractor.call(target)
+ elements << element if element
+ end
+ if invalid_feed_checker
+ invalid_feed_exception = invalid_feed_checker.call(targets)
+ end
end
- if invalid_feed_checker
- invalid_feed = invalid_feed_checker.call(targets)
+ rescue RSS::Error
+ if invalid_feed_exception.is_a?(RSS::TooMuchTagError)
+ assert_too_much_tag(invalid_feed_exception.tag,
+ invalid_feed_exception.parent) do
+ raise
+ end
+ else
+ raise
end
end
- if invalid_feed
- assert_nil(feed)
- else
+ if invalid_feed_exception.nil?
actual_elements = chain_reader(feed, feed_readers) || []
actual_elements = actual_elements.collect do |target|
feed_extractor.call(target)
@@ -1542,18 +1552,24 @@ EOA
:length => target.length,
}
end
+
+ if feed_readers.first == "entries"
+ parent = "entry"
+ else
+ parent = feed_type
+ end
invalid_feed_checker = Proc.new do |targets|
infos = {}
- invalid = false
+ invalid_exception = nil
targets.each do |target|
key = [target.hreflang, target.type]
if infos.has_key?(key)
- invalid = true
+ invalid_exception = RSS::TooMuchTagError.new("link", parent)
break
end
infos[key] = true if target.rel.nil? or target.rel == "alternate"
end
- invalid
+ invalid_exception
end
invalid_feed_checker = nil if allow_duplication
_assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
diff --git a/test/rss/test_atom.rb b/test/rss/test_atom.rb
index c442c753b2..1f65008fa0 100644
--- a/test/rss/test_atom.rb
+++ b/test/rss/test_atom.rb
@@ -658,7 +658,7 @@ module RSS
content.content = original_content
xml = REXML::Document.new(content.to_s).root
assert_rexml_element([], {"type" => type},
- Base64.encode64(original_content), xml)
+ [original_content].pack("m").delete("\n"), xml)
end
end
diff --git a/test/rss/test_maker_0.9.rb b/test/rss/test_maker_0.9.rb
index c211bf605b..815f9e3952 100644
--- a/test/rss/test_maker_0.9.rb
+++ b/test/rss/test_maker_0.9.rb
@@ -6,8 +6,9 @@ module RSS
class TestMaker09 < TestCase
def test_rss
- rss = RSS::Maker.make("0.91")
- assert_nil(rss)
+ assert_raise(LocalJumpError) do
+ RSS::Maker.make("0.91")
+ end
rss = RSS::Maker.make("0.9") do |maker|
setup_dummy_channel(maker)
diff --git a/test/rss/test_maker_1.0.rb b/test/rss/test_maker_1.0.rb
index 60cc3708a7..49d506bf6f 100644
--- a/test/rss/test_maker_1.0.rb
+++ b/test/rss/test_maker_1.0.rb
@@ -6,6 +6,10 @@ module RSS
class TestMaker10 < TestCase
def test_rdf
+ assert_raise(LocalJumpError) do
+ RSS::Maker.make("1.0")
+ end
+
rss = RSS::Maker.make("1.0") do |maker|
setup_dummy_channel(maker)
setup_dummy_item(maker)
@@ -48,9 +52,6 @@ module RSS
link = "http://hoge.com"
description = "fugafugafugafuga"
- rss = RSS::Maker.make("1.0")
- assert_nil(rss)
-
rss = RSS::Maker.make("1.0") do |maker|
maker.channel.about = about
maker.channel.title = title
diff --git a/test/rss/test_maker_2.0.rb b/test/rss/test_maker_2.0.rb
index c338e343a3..f6d4a11dc3 100644
--- a/test/rss/test_maker_2.0.rb
+++ b/test/rss/test_maker_2.0.rb
@@ -6,8 +6,9 @@ module RSS
class TestMaker20 < TestCase
def test_rss
- rss = RSS::Maker.make("2.0")
- assert_nil(rss)
+ assert_raise(LocalJumpError) do
+ RSS::Maker.make("2.0")
+ end
rss = RSS::Maker.make("2.0") do |maker|
setup_dummy_channel(maker)
diff --git a/test/rss/test_maker_dc.rb b/test/rss/test_maker_dc.rb
index c9df36a1ce..72a967231a 100644
--- a/test/rss/test_maker_dc.rb
+++ b/test/rss/test_maker_dc.rb
@@ -86,9 +86,8 @@ module RSS
elems.each do |name, values, plural|
dc_elems = item.__send__("dc_#{plural}")
values.each do |value|
- dc_elems.__send__("new_#{name}") do |elem|
- elem.value = value
- end
+ elem = dc_elems.__send__("new_#{name}")
+ elem.value = value
end
end
diff --git a/test/rss/test_maker_itunes.rb b/test/rss/test_maker_itunes.rb
index 1d4e323057..21a4dd1f29 100644
--- a/test/rss/test_maker_itunes.rb
+++ b/test/rss/test_maker_itunes.rb
@@ -462,7 +462,7 @@ module RSS
"all of your answers here.",
maker_readers, feed_readers)
_assert_maker_itunes_summary("This week we talk about surviving in a " +
- "Red state if you’re a Blue person. Or " +
+ "Red state if you're a Blue person. Or " +
"vice versa.",
maker_readers, feed_readers)
end
diff --git a/test/rss/test_parser_1.0.rb b/test/rss/test_parser_1.0.rb
index 819ce286a5..216881b767 100644
--- a/test/rss/test_parser_1.0.rb
+++ b/test/rss/test_parser_1.0.rb
@@ -509,3 +509,4 @@ EOR
end
end
end
+
diff --git a/test/rss/test_version.rb b/test/rss/test_version.rb
index 64f6f0482e..fefdb1e0f0 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.2.4", ::RSS::VERSION)
+ assert_equal("0.2.5", ::RSS::VERSION)
end
end
end