* test/rss/test_trackback.rb: added tests for TrackBack with RSS
2.0. * test/rss/common.rb: added methods make RSS 2.0. * lib/rss/trackback.rb: TrackBack API is decided. * lib/rss/rss.rb: RSS::VERSION 0.0.7 -> 0.0.8 * lib/rss/parser.rb, lib/rss/rss.rb: replaced $DEBUG by RSS::DEBUG. * lib/rss/2.0.rb: removed RSS 2.0 URI. Because RSS 2.0 doesn't have URI. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
82482f67e2
commit
c0306157d9
16
ChangeLog
16
ChangeLog
@ -1,3 +1,19 @@
|
|||||||
|
Fri Feb 13 19:57:01 2004 Kouhei Sutou <kou@cozmixng.org>
|
||||||
|
|
||||||
|
* test/rss/test_trackback.rb: added tests for TrackBack with RSS
|
||||||
|
2.0.
|
||||||
|
|
||||||
|
* test/rss/common.rb: added methods make RSS 2.0.
|
||||||
|
|
||||||
|
* lib/rss/trackback.rb: TrackBack API is decided.
|
||||||
|
|
||||||
|
* lib/rss/rss.rb: RSS::VERSION 0.0.7 -> 0.0.8.
|
||||||
|
|
||||||
|
* lib/rss/parser.rb, lib/rss/rss.rb: replaced $DEBUG by RSS::DEBUG.
|
||||||
|
|
||||||
|
* lib/rss/2.0.rb: removed RSS 2.0 URI. Because RSS 2.0 doesn't
|
||||||
|
have URI.
|
||||||
|
|
||||||
Fri Feb 13 14:41:00 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
Fri Feb 13 14:41:00 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||||
|
|
||||||
* ext/tk/lib/tk.rb: en-bugged at last commit (Feb 11 23:24:22 2004)
|
* ext/tk/lib/tk.rb: en-bugged at last commit (Feb 11 23:24:22 2004)
|
||||||
|
@ -4,19 +4,19 @@ module RSS
|
|||||||
|
|
||||||
class Rss
|
class Rss
|
||||||
|
|
||||||
URI = "http://backend.userland.com/rss2"
|
# URI = "http://backend.userland.com/rss2"
|
||||||
|
|
||||||
install_ns('', URI)
|
# install_ns('', URI)
|
||||||
|
|
||||||
def self.required_uri
|
# def self.required_uri
|
||||||
URI
|
# URI
|
||||||
end
|
# end
|
||||||
|
|
||||||
class Channel
|
class Channel
|
||||||
|
|
||||||
def self.required_uri
|
# def self.required_uri
|
||||||
URI
|
# URI
|
||||||
end
|
# end
|
||||||
|
|
||||||
%w(generator ttl).each do |x|
|
%w(generator ttl).each do |x|
|
||||||
install_text_element(x)
|
install_text_element(x)
|
||||||
@ -42,15 +42,15 @@ EOT
|
|||||||
end
|
end
|
||||||
|
|
||||||
Category = Item::Category
|
Category = Item::Category
|
||||||
def Category.required_uri
|
# def Category.required_uri
|
||||||
URI
|
# URI
|
||||||
end
|
# end
|
||||||
|
|
||||||
class Item
|
class Item
|
||||||
|
|
||||||
def self.required_uri
|
# def self.required_uri
|
||||||
URI
|
# URI
|
||||||
end
|
# end
|
||||||
|
|
||||||
[
|
[
|
||||||
["pubDate", '?'],
|
["pubDate", '?'],
|
||||||
@ -78,9 +78,9 @@ EOT
|
|||||||
|
|
||||||
include RSS09
|
include RSS09
|
||||||
|
|
||||||
def self.required_uri
|
# def self.required_uri
|
||||||
URI
|
# URI
|
||||||
end
|
# end
|
||||||
|
|
||||||
[
|
[
|
||||||
["isPermaLink", nil, false]
|
["isPermaLink", nil, false]
|
||||||
@ -124,14 +124,15 @@ EOT
|
|||||||
end
|
end
|
||||||
|
|
||||||
RSS09::ELEMENTS.each do |x|
|
RSS09::ELEMENTS.each do |x|
|
||||||
BaseListener.install_get_text_element(x, Rss::URI, "#{x}=")
|
# BaseListener.install_get_text_element(x, Rss::URI, "#{x}=")
|
||||||
|
BaseListener.install_get_text_element(x, nil, "#{x}=")
|
||||||
end
|
end
|
||||||
|
|
||||||
module ListenerMixin
|
module ListenerMixin
|
||||||
private
|
private
|
||||||
alias start_rss09 start_rss
|
alias start_rss09 start_rss
|
||||||
def start_rss(tag_name, prefix, attrs, ns)
|
def start_rss(tag_name, prefix, attrs, ns)
|
||||||
check_ns(tag_name, prefix, ns, Rss::URI)
|
# check_ns(tag_name, prefix, ns, Rss::URI)
|
||||||
|
|
||||||
@rss = Rss.new(attrs['version'], @version, @encoding, @standalone)
|
@rss = Rss.new(attrs['version'], @version, @encoding, @standalone)
|
||||||
@last_element = @rss
|
@last_element = @rss
|
||||||
@ -139,7 +140,7 @@ EOT
|
|||||||
@rss.validate_for_stream(tags) if @do_validate
|
@rss.validate_for_stream(tags) if @do_validate
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -222,7 +222,7 @@ module RSS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def tag_end(name)
|
def tag_end(name)
|
||||||
if $DEBUG
|
if DEBUG
|
||||||
p "end tag #{name}"
|
p "end tag #{name}"
|
||||||
p @tag_stack
|
p @tag_stack
|
||||||
end
|
end
|
||||||
@ -336,7 +336,7 @@ module RSS
|
|||||||
@last_element.send(setter, next_element)
|
@last_element.send(setter, next_element)
|
||||||
@last_element = next_element
|
@last_element = next_element
|
||||||
@proc_stack.push Proc.new { |text, tags|
|
@proc_stack.push Proc.new { |text, tags|
|
||||||
p(@last_element.class) if $DEBUG
|
p(@last_element.class) if DEBUG
|
||||||
@last_element.content = text if klass.have_content?
|
@last_element.content = text if klass.have_content?
|
||||||
@last_element.validate_for_stream(tags) if @do_validate
|
@last_element.validate_for_stream(tags) if @do_validate
|
||||||
@last_element = previous
|
@last_element = previous
|
||||||
|
@ -5,7 +5,9 @@ require "rss/converter"
|
|||||||
|
|
||||||
module RSS
|
module RSS
|
||||||
|
|
||||||
VERSION = "0.0.7"
|
VERSION = "0.0.8"
|
||||||
|
|
||||||
|
DEBUG = false
|
||||||
|
|
||||||
class Error < StandardError; end
|
class Error < StandardError; end
|
||||||
|
|
||||||
@ -363,6 +365,7 @@ EOC
|
|||||||
|
|
||||||
def initialize(do_validate=true)
|
def initialize(do_validate=true)
|
||||||
@converter = nil
|
@converter = nil
|
||||||
|
@output_encoding = nil
|
||||||
@do_validate = do_validate
|
@do_validate = do_validate
|
||||||
initialize_variables
|
initialize_variables
|
||||||
end
|
end
|
||||||
@ -393,6 +396,7 @@ EOC
|
|||||||
instance_eval("@#{variable_name} = nil")
|
instance_eval("@#{variable_name} = nil")
|
||||||
end
|
end
|
||||||
initialize_have_children_elements
|
initialize_have_children_elements
|
||||||
|
@content = "" if self.class.have_content?
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize_have_children_elements
|
def initialize_have_children_elements
|
||||||
@ -423,7 +427,7 @@ EOC
|
|||||||
end
|
end
|
||||||
must_call_validators = self.class::must_call_validators
|
must_call_validators = self.class::must_call_validators
|
||||||
tags = tag_filter(tags.dup)
|
tags = tag_filter(tags.dup)
|
||||||
p tags if $DEBUG
|
p tags if DEBUG
|
||||||
self.class::NSPOOL.each do |prefix, uri|
|
self.class::NSPOOL.each do |prefix, uri|
|
||||||
if tags.has_key?(uri) and !must_call_validators.has_key?(uri)
|
if tags.has_key?(uri) and !must_call_validators.has_key?(uri)
|
||||||
meth = "#{prefix}_validate"
|
meth = "#{prefix}_validate"
|
||||||
@ -463,7 +467,7 @@ EOC
|
|||||||
|
|
||||||
model.each_with_index do |elem, i|
|
model.each_with_index do |elem, i|
|
||||||
|
|
||||||
if $DEBUG
|
if DEBUG
|
||||||
p "before"
|
p "before"
|
||||||
p tags
|
p tags
|
||||||
p elem
|
p elem
|
||||||
@ -478,7 +482,7 @@ EOC
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if $DEBUG
|
if DEBUG
|
||||||
p "mid"
|
p "mid"
|
||||||
p count
|
p count
|
||||||
end
|
end
|
||||||
@ -523,7 +527,7 @@ EOC
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if $DEBUG
|
if DEBUG
|
||||||
p "after"
|
p "after"
|
||||||
p not_shift
|
p not_shift
|
||||||
p do_redo
|
p do_redo
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
# ATTENSION:
|
|
||||||
# TrackBack handling API MUST be CHANGED!!!!
|
|
||||||
|
|
||||||
require 'rss/1.0'
|
require 'rss/1.0'
|
||||||
require 'rss/2.0'
|
require 'rss/2.0'
|
||||||
|
|
||||||
@ -154,13 +151,82 @@ module RSS
|
|||||||
|
|
||||||
unless klass.class == Module
|
unless klass.class == Module
|
||||||
%w(ping).each do |x|
|
%w(ping).each do |x|
|
||||||
klass.install_have_child_element("#{TRACKBACK_PREFIX}_#{x}")
|
var_name = "#{TRACKBACK_PREFIX}_#{x}"
|
||||||
|
klass.install_have_child_element(var_name)
|
||||||
|
klass.module_eval(<<-EOC)
|
||||||
|
alias _#{var_name} #{var_name}
|
||||||
|
def #{var_name}
|
||||||
|
@#{var_name} and @#{var_name}.content
|
||||||
|
end
|
||||||
|
|
||||||
|
alias _#{var_name}= #{var_name}=
|
||||||
|
def #{var_name}=(content)
|
||||||
|
@#{var_name} = new_with_content_if_need(#{x.capitalize}, content)
|
||||||
|
end
|
||||||
|
EOC
|
||||||
end
|
end
|
||||||
|
|
||||||
%w(about).each do |x|
|
[%w(about s)].each do |x, postfix|
|
||||||
klass.install_have_children_element("#{TRACKBACK_PREFIX}_#{x}")
|
var_name = "#{TRACKBACK_PREFIX}_#{x}"
|
||||||
|
klass.install_have_children_element(var_name)
|
||||||
|
klass.module_eval(<<-EOC)
|
||||||
|
alias _#{var_name}#{postfix} #{var_name}#{postfix}
|
||||||
|
def #{var_name}#{postfix}
|
||||||
|
@#{var_name}.collect {|x| x.content}
|
||||||
|
end
|
||||||
|
|
||||||
|
alias _#{var_name} #{var_name}
|
||||||
|
def #{var_name}(*args)
|
||||||
|
if args.empty?
|
||||||
|
@#{var_name}.first and @#{var_name}.first.content
|
||||||
|
else
|
||||||
|
ret = @#{var_name}.send("[]", *args)
|
||||||
|
if ret.is_a?(Array)
|
||||||
|
ret.collect {|x| x.content}
|
||||||
|
else
|
||||||
|
ret.content
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
alias _#{var_name}= #{var_name}=
|
||||||
|
alias _set_#{var_name} set_#{var_name}
|
||||||
|
def #{var_name}=(*args)
|
||||||
|
if args.size == 1
|
||||||
|
item = new_with_content_if_need(#{x.capitalize}, args[0])
|
||||||
|
@#{var_name}.push(item)
|
||||||
|
else
|
||||||
|
new_val = args.last
|
||||||
|
if new_val.is_a?(Array)
|
||||||
|
new_val = new_value.collect do |val|
|
||||||
|
new_with_content_if_need(#{x.capitalize}, val)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
new_val = new_with_content_if_need(#{x.capitalize}, new_val)
|
||||||
|
end
|
||||||
|
@#{var_name}.send("[]=", *(args[0..-2] + [new_val]))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
alias set_#{var_name} #{var_name}=
|
||||||
|
EOC
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def new_with_content(klass, content)
|
||||||
|
obj = klass.new
|
||||||
|
obj.content = content
|
||||||
|
obj
|
||||||
|
end
|
||||||
|
|
||||||
|
def new_with_content_if_need(klass, content)
|
||||||
|
if content.is_a?(klass)
|
||||||
|
content
|
||||||
|
else
|
||||||
|
new_with_content(klass, content)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Ping < Element
|
class Ping < Element
|
||||||
|
@ -99,4 +99,49 @@ EOI
|
|||||||
</textinput>
|
</textinput>
|
||||||
EOT
|
EOT
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def make_Rss2(content=nil, xmlns=[])
|
||||||
|
<<-EORSS
|
||||||
|
#{make_xmldecl}
|
||||||
|
<rss version="2.0"
|
||||||
|
#{xmlns.collect {|pre, uri| "xmlns:#{pre}='#{uri}'"}.join(' ')}>
|
||||||
|
#{block_given? ? yield : content}
|
||||||
|
</rss>
|
||||||
|
EORSS
|
||||||
|
end
|
||||||
|
|
||||||
|
def make_channel2(content=nil)
|
||||||
|
<<-EOC
|
||||||
|
<channel>
|
||||||
|
<title>#{TITLE_VALUE}</title>
|
||||||
|
<link>#{LINK_VALUE}</link>
|
||||||
|
<description>#{DESCRIPTION_VALUE}</description>
|
||||||
|
|
||||||
|
<image>
|
||||||
|
<url>#{RDF_RESOURCE}</url>
|
||||||
|
<title>#{TITLE_VALUE}</title>
|
||||||
|
<link>#{LINK_VALUE}</link>
|
||||||
|
</image>
|
||||||
|
|
||||||
|
#{RESOURCES.collect do |res| '<item><link>' + res + '</link></item>' end.join("\n")}
|
||||||
|
|
||||||
|
<textInput>
|
||||||
|
<link>#{RDF_RESOURCE}</link>
|
||||||
|
</textInput>
|
||||||
|
|
||||||
|
#{block_given? ? yield : content}
|
||||||
|
</channel>
|
||||||
|
EOC
|
||||||
|
end
|
||||||
|
|
||||||
|
def make_item2(content=nil)
|
||||||
|
<<-EOI
|
||||||
|
<item>
|
||||||
|
<title>#{TITLE_VALUE}</title>
|
||||||
|
<link>#{LINK_VALUE}</link>
|
||||||
|
<description>#{DESCRIPTION_VALUE}</description>
|
||||||
|
#{block_given? ? yield : content}
|
||||||
|
</item>
|
||||||
|
EOI
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,6 +5,7 @@ require "cgi-lib"
|
|||||||
require "rexml/document"
|
require "rexml/document"
|
||||||
|
|
||||||
require "rss/1.0"
|
require "rss/1.0"
|
||||||
|
require "rss/2.0"
|
||||||
require "rss/trackback"
|
require "rss/trackback"
|
||||||
require "common"
|
require "common"
|
||||||
|
|
||||||
@ -26,6 +27,10 @@ class TestTrackBack < Test::Unit::TestCase
|
|||||||
"<#{@prefix}:#{name} rdf:resource=\"#{CGI.escapeHTML(value.to_s)}\"/>"
|
"<#{@prefix}:#{name} rdf:resource=\"#{CGI.escapeHTML(value.to_s)}\"/>"
|
||||||
end.join("\n")
|
end.join("\n")
|
||||||
|
|
||||||
|
@content_nodes2 = @elems.collect do |name, value|
|
||||||
|
"<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
|
||||||
|
end.join("\n")
|
||||||
|
|
||||||
@rss_source = make_RDF(<<-EOR, {@prefix => @uri})
|
@rss_source = make_RDF(<<-EOR, {@prefix => @uri})
|
||||||
#{make_channel()}
|
#{make_channel()}
|
||||||
#{make_image()}
|
#{make_image()}
|
||||||
@ -34,6 +39,14 @@ class TestTrackBack < Test::Unit::TestCase
|
|||||||
EOR
|
EOR
|
||||||
|
|
||||||
@rss = Parser.parse(@rss_source)
|
@rss = Parser.parse(@rss_source)
|
||||||
|
|
||||||
|
@rss2_source = make_Rss2(nil, {@prefix => @uri}) do
|
||||||
|
make_channel2(nil) do
|
||||||
|
make_item2(@content_nodes2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@rss2 = Parser.parse(@rss2_source, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_parser
|
def test_parser
|
||||||
@ -76,11 +89,21 @@ EOR
|
|||||||
|
|
||||||
@elems.each do |name, value|
|
@elems.each do |name, value|
|
||||||
@parents.each do |parent|
|
@parents.each do |parent|
|
||||||
elem = @rss.send(parent).send("#{RSS::TRACKBACK_PREFIX}_#{name}")
|
accessor = "#{RSS::TRACKBACK_PREFIX}_#{name}"
|
||||||
meth = "resource"
|
target_accessor = "resource"
|
||||||
assert_equal(value, elem.send(meth))
|
target = @rss.send(parent).send(accessor)
|
||||||
elem.send("#{meth}=", new_value[name].to_s)
|
target2 = @rss2.channel.send(parent, -1)
|
||||||
assert_equal(new_value[name], elem.send(meth))
|
assert_equal(value, target.send(target_accessor))
|
||||||
|
assert_equal(value, target2.send(accessor))
|
||||||
|
target.send("#{target_accessor}=", new_value[name].to_s)
|
||||||
|
if name == :about
|
||||||
|
# abount is zero or more
|
||||||
|
target2.send("#{accessor}=", 0, new_value[name].to_s)
|
||||||
|
else
|
||||||
|
target2.send("#{accessor}=", new_value[name].to_s)
|
||||||
|
end
|
||||||
|
assert_equal(new_value[name], target.send(target_accessor))
|
||||||
|
assert_equal(new_value[name], target2.send(accessor))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user