1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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)


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@17677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kou 2008-06-29 09:12:56 +00:00
parent 8272251f6d
commit 51bd9cada8
16 changed files with 120 additions and 60 deletions

View file

@ -1,3 +1,14 @@
Sun Jun 29 18:09:00 2008 Kouhei Sutou <kou@cozmixng.org>
* 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 <akr@fsij.org>
* math.c (domain_check): fix preprocess condition.

8
NEWS
View file

@ -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

View file

@ -1,4 +1,3 @@
require 'base64'
require 'rss/parser'
module RSS

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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,

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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 youre a Blue person. Or " +
"Red state if you're a Blue person. Or " +
"vice versa.",
maker_readers, feed_readers)
end

View file

@ -509,3 +509,4 @@ EOR
end
end
end

View file

@ -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