* 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:
kou 2004-02-13 11:02:03 +00:00
Родитель 82482f67e2
Коммит c0306157d9
7 изменённых файлов: 193 добавлений и 38 удалений

Просмотреть файл

@ -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>
* ext/tk/lib/tk.rb: en-bugged at last commit (Feb 11 23:24:22 2004)

Просмотреть файл

@ -4,19 +4,19 @@ module 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
URI
end
# def self.required_uri
# URI
# end
class Channel
def self.required_uri
URI
end
# def self.required_uri
# URI
# end
%w(generator ttl).each do |x|
install_text_element(x)
@ -42,15 +42,15 @@ EOT
end
Category = Item::Category
def Category.required_uri
URI
end
# def Category.required_uri
# URI
# end
class Item
def self.required_uri
URI
end
# def self.required_uri
# URI
# end
[
["pubDate", '?'],
@ -78,9 +78,9 @@ EOT
include RSS09
def self.required_uri
URI
end
# def self.required_uri
# URI
# end
[
["isPermaLink", nil, false]
@ -124,14 +124,15 @@ EOT
end
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
module ListenerMixin
private
alias start_rss09 start_rss
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)
@last_element = @rss
@ -139,7 +140,7 @@ EOT
@rss.validate_for_stream(tags) if @do_validate
}
end
end
end

Просмотреть файл

@ -222,7 +222,7 @@ module RSS
end
def tag_end(name)
if $DEBUG
if DEBUG
p "end tag #{name}"
p @tag_stack
end
@ -336,7 +336,7 @@ module RSS
@last_element.send(setter, next_element)
@last_element = next_element
@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.validate_for_stream(tags) if @do_validate
@last_element = previous

Просмотреть файл

@ -5,7 +5,9 @@ require "rss/converter"
module RSS
VERSION = "0.0.7"
VERSION = "0.0.8"
DEBUG = false
class Error < StandardError; end
@ -363,6 +365,7 @@ EOC
def initialize(do_validate=true)
@converter = nil
@output_encoding = nil
@do_validate = do_validate
initialize_variables
end
@ -393,6 +396,7 @@ EOC
instance_eval("@#{variable_name} = nil")
end
initialize_have_children_elements
@content = "" if self.class.have_content?
end
def initialize_have_children_elements
@ -423,7 +427,7 @@ EOC
end
must_call_validators = self.class::must_call_validators
tags = tag_filter(tags.dup)
p tags if $DEBUG
p tags if DEBUG
self.class::NSPOOL.each do |prefix, uri|
if tags.has_key?(uri) and !must_call_validators.has_key?(uri)
meth = "#{prefix}_validate"
@ -463,7 +467,7 @@ EOC
model.each_with_index do |elem, i|
if $DEBUG
if DEBUG
p "before"
p tags
p elem
@ -478,7 +482,7 @@ EOC
end
end
if $DEBUG
if DEBUG
p "mid"
p count
end
@ -523,7 +527,7 @@ EOC
end
end
if $DEBUG
if DEBUG
p "after"
p not_shift
p do_redo

Просмотреть файл

@ -1,6 +1,3 @@
# ATTENSION:
# TrackBack handling API MUST be CHANGED!!!!
require 'rss/1.0'
require 'rss/2.0'
@ -154,13 +151,82 @@ module RSS
unless klass.class == Module
%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
%w(about).each do |x|
klass.install_have_children_element("#{TRACKBACK_PREFIX}_#{x}")
[%w(about s)].each do |x, postfix|
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
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
class Ping < Element

Просмотреть файл

@ -99,4 +99,49 @@ EOI
</textinput>
EOT
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

Просмотреть файл

@ -5,6 +5,7 @@ require "cgi-lib"
require "rexml/document"
require "rss/1.0"
require "rss/2.0"
require "rss/trackback"
require "common"
@ -26,6 +27,10 @@ class TestTrackBack < Test::Unit::TestCase
"<#{@prefix}:#{name} rdf:resource=\"#{CGI.escapeHTML(value.to_s)}\"/>"
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})
#{make_channel()}
#{make_image()}
@ -34,6 +39,14 @@ class TestTrackBack < Test::Unit::TestCase
EOR
@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
def test_parser
@ -76,11 +89,21 @@ EOR
@elems.each do |name, value|
@parents.each do |parent|
elem = @rss.send(parent).send("#{RSS::TRACKBACK_PREFIX}_#{name}")
meth = "resource"
assert_equal(value, elem.send(meth))
elem.send("#{meth}=", new_value[name].to_s)
assert_equal(new_value[name], elem.send(meth))
accessor = "#{RSS::TRACKBACK_PREFIX}_#{name}"
target_accessor = "resource"
target = @rss.send(parent).send(accessor)
target2 = @rss2.channel.send(parent, -1)
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