зеркало из https://github.com/github/ruby.git
* lib/rss/content.rb, lib/rss/content/, lib/rss/maker/content.rb,
test/rss/test_content.rb, test/rss/test_maker_content.rb, test/rss/rss-testcase.rb (RSS::TestCase): supported content:encoded with RSS 2.0. Suggested by Sam Lown. Thanks. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13805 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
a7f1c72e90
Коммит
79041dfc8d
|
@ -1,3 +1,11 @@
|
||||||
|
Fri Nov 2 20:55:49 2007 Kouhei Sutou <kou@cozmixng.org>
|
||||||
|
|
||||||
|
* lib/rss/content.rb, lib/rss/content/, lib/rss/maker/content.rb,
|
||||||
|
test/rss/test_content.rb, test/rss/test_maker_content.rb,
|
||||||
|
test/rss/rss-testcase.rb (RSS::TestCase): supported
|
||||||
|
content:encoded with RSS 2.0.
|
||||||
|
Suggested by Sam Lown. Thanks.
|
||||||
|
|
||||||
Fri Nov 2 20:47:04 2007 Kouhei Sutou <kou@cozmixng.org>
|
Fri Nov 2 20:47:04 2007 Kouhei Sutou <kou@cozmixng.org>
|
||||||
|
|
||||||
* lib/rss/rss.rb, test/rss/test_version.rb: 0.2.0 -> 0.2.1.
|
* lib/rss/rss.rb, test/rss/test_version.rb: 0.2.0 -> 0.2.1.
|
||||||
|
|
|
@ -1,38 +1,31 @@
|
||||||
require "rss/1.0"
|
require "rss/rss"
|
||||||
|
|
||||||
module RSS
|
module RSS
|
||||||
|
|
||||||
CONTENT_PREFIX = 'content'
|
CONTENT_PREFIX = 'content'
|
||||||
CONTENT_URI = "http://purl.org/rss/1.0/modules/content/"
|
CONTENT_URI = "http://purl.org/rss/1.0/modules/content/"
|
||||||
|
|
||||||
RDF.install_ns(CONTENT_PREFIX, CONTENT_URI)
|
|
||||||
|
|
||||||
module ContentModel
|
module ContentModel
|
||||||
|
|
||||||
extend BaseModel
|
extend BaseModel
|
||||||
|
|
||||||
ELEMENTS = []
|
ELEMENTS = ["#{CONTENT_PREFIX}_encoded"]
|
||||||
|
|
||||||
def self.append_features(klass)
|
def self.append_features(klass)
|
||||||
super
|
super
|
||||||
|
|
||||||
klass.install_must_call_validator(CONTENT_PREFIX, CONTENT_URI)
|
klass.install_must_call_validator(CONTENT_PREFIX, CONTENT_URI)
|
||||||
%w(encoded).each do |name|
|
ELEMENTS.each do |full_name|
|
||||||
klass.install_text_element(name, CONTENT_URI, "?",
|
name = full_name[(CONTENT_PREFIX.size + 1)..-1]
|
||||||
"#{CONTENT_PREFIX}_#{name}")
|
klass.install_text_element(name, CONTENT_URI, "?", full_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class RDF
|
|
||||||
class Item; include ContentModel; end
|
|
||||||
end
|
|
||||||
|
|
||||||
prefix_size = CONTENT_PREFIX.size + 1
|
prefix_size = CONTENT_PREFIX.size + 1
|
||||||
ContentModel::ELEMENTS.uniq!
|
|
||||||
ContentModel::ELEMENTS.each do |full_name|
|
ContentModel::ELEMENTS.each do |full_name|
|
||||||
name = full_name[prefix_size..-1]
|
name = full_name[prefix_size..-1]
|
||||||
BaseListener.install_get_text_element(CONTENT_URI, name, full_name)
|
BaseListener.install_get_text_element(CONTENT_URI, name, full_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require 'rss/content/1.0'
|
||||||
|
require 'rss/content/2.0'
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
require 'rss/1.0'
|
||||||
|
require 'rss/content'
|
||||||
|
|
||||||
|
module RSS
|
||||||
|
RDF.install_ns(CONTENT_PREFIX, CONTENT_URI)
|
||||||
|
|
||||||
|
class RDF
|
||||||
|
class Item; include ContentModel; end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,12 @@
|
||||||
|
require "rss/2.0"
|
||||||
|
require "rss/content"
|
||||||
|
|
||||||
|
module RSS
|
||||||
|
Rss.install_ns(CONTENT_PREFIX, CONTENT_URI)
|
||||||
|
|
||||||
|
class Rss
|
||||||
|
class Channel
|
||||||
|
class Item; include ContentModel; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,5 +1,6 @@
|
||||||
require 'rss/content'
|
require 'rss/content'
|
||||||
require 'rss/maker/1.0'
|
require 'rss/maker/1.0'
|
||||||
|
require 'rss/maker/2.0'
|
||||||
|
|
||||||
module RSS
|
module RSS
|
||||||
module Maker
|
module Maker
|
||||||
|
|
|
@ -208,7 +208,7 @@ EOC
|
||||||
disp_name=nil)
|
disp_name=nil)
|
||||||
name ||= tag_name
|
name ||= tag_name
|
||||||
disp_name ||= name
|
disp_name ||= name
|
||||||
self::ELEMENTS << name
|
self::ELEMENTS << name unless self::ELEMENTS.include?(name)
|
||||||
add_need_initialize_variable(name)
|
add_need_initialize_variable(name)
|
||||||
install_model(tag_name, uri, occurs, name)
|
install_model(tag_name, uri, occurs, name)
|
||||||
|
|
||||||
|
|
|
@ -326,11 +326,18 @@ EOA
|
||||||
attrs_str = attrs.collect do |name, value|
|
attrs_str = attrs.collect do |name, value|
|
||||||
"#{h name}='#{h value}'"
|
"#{h name}='#{h value}'"
|
||||||
end.join(" ")
|
end.join(" ")
|
||||||
contents_str = contents.collect do |name, value|
|
attrs_str = " #{attrs_str}" unless attrs_str.empty?
|
||||||
"#{Element::INDENT}<#{h name}>#{h value}</#{h name}>"
|
|
||||||
end.join("\n")
|
|
||||||
|
|
||||||
"<#{h elem_name} #{attrs_str}>\n#{contents_str}\n</#{h elem_name}>"
|
if contents.is_a?(String)
|
||||||
|
contents_str = h(contents)
|
||||||
|
else
|
||||||
|
contents_str = contents.collect do |name, value|
|
||||||
|
"#{Element::INDENT}<#{h name}>#{h value}</#{h name}>"
|
||||||
|
end.join("\n")
|
||||||
|
contents_str = "\n#{contents_str}\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
"<#{h elem_name}#{attrs_str}>#{contents_str}</#{h elem_name}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def xmlns_container(xmlns_decls, content)
|
def xmlns_container(xmlns_decls, content)
|
||||||
|
|
|
@ -3,18 +3,14 @@ require "rexml/document"
|
||||||
|
|
||||||
require "rss-testcase"
|
require "rss-testcase"
|
||||||
|
|
||||||
require "rss/1.0"
|
|
||||||
require "rss/content"
|
require "rss/content"
|
||||||
|
|
||||||
module RSS
|
module RSS
|
||||||
class TestContent < TestCase
|
class TestContent < TestCase
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@prefix = "content"
|
@prefix = "content"
|
||||||
@uri = "http://purl.org/rss/1.0/modules/content/"
|
@uri = "http://purl.org/rss/1.0/modules/content/"
|
||||||
|
|
||||||
@parents = %w(item)
|
|
||||||
|
|
||||||
@elems = {
|
@elems = {
|
||||||
:encoded => "<em>ATTENTION</em>",
|
:encoded => "<em>ATTENTION</em>",
|
||||||
}
|
}
|
||||||
|
@ -23,63 +19,79 @@ module RSS
|
||||||
"<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
|
"<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
|
||||||
end.join("\n")
|
end.join("\n")
|
||||||
|
|
||||||
@rss_source = make_RDF(<<-EOR, {@prefix => @uri})
|
@rss10_source = make_RDF(<<-EOR, {@prefix => @uri})
|
||||||
#{make_channel()}
|
#{make_channel()}
|
||||||
#{make_image()}
|
#{make_image()}
|
||||||
#{make_item(@content_nodes)}
|
#{make_item(@content_nodes)}
|
||||||
#{make_textinput()}
|
#{make_textinput()}
|
||||||
EOR
|
EOR
|
||||||
|
|
||||||
@rss = Parser.parse(@rss_source)
|
@rss10 = Parser.parse(@rss10_source)
|
||||||
|
|
||||||
|
|
||||||
|
@rss20_source = make_rss20(<<-EOR, {@prefix => @uri})
|
||||||
|
#{make_channel20(make_item20(@content_nodes))}
|
||||||
|
EOR
|
||||||
|
|
||||||
|
@rss20 = Parser.parse(@rss20_source)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_parser
|
def test_parser
|
||||||
|
assert_nothing_raised do
|
||||||
|
Parser.parse(@rss10_source)
|
||||||
|
end
|
||||||
|
|
||||||
assert_nothing_raised do
|
assert_nothing_raised do
|
||||||
Parser.parse(@rss_source)
|
Parser.parse(@rss20_source)
|
||||||
end
|
end
|
||||||
|
|
||||||
@elems.each do |tag, value|
|
@elems.each do |tag, value|
|
||||||
|
tag_name = "#{@prefix}:#{tag}"
|
||||||
|
content_encodes = make_element(tag_name, {}, value) * 2
|
||||||
|
|
||||||
assert_too_much_tag(tag.to_s, "item") do
|
assert_too_much_tag(tag.to_s, "item") do
|
||||||
Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
|
Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
|
||||||
#{make_channel()}
|
#{make_channel}
|
||||||
#{make_item(("<" + @prefix + ":" + tag.to_s + ">" +
|
#{make_item(content_encodes)}
|
||||||
CGI.escapeHTML(value.to_s) +
|
EOR
|
||||||
"</" + @prefix + ":" + tag.to_s + ">") * 2)}
|
end
|
||||||
|
|
||||||
|
assert_too_much_tag(tag.to_s, "item") do
|
||||||
|
Parser.parse(make_rss20(<<-EOR, {@prefix => @uri}))
|
||||||
|
#{make_channel20(make_item20(content_encodes))}
|
||||||
EOR
|
EOR
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_accessor
|
def test_accessor
|
||||||
|
|
||||||
new_value = {
|
new_value = {
|
||||||
:encoded => "<![CDATA[<it>hoge</it>]]>",
|
:encoded => "<![CDATA[<it>hoge</it>]]>",
|
||||||
}
|
}
|
||||||
|
|
||||||
@elems.each do |name, value|
|
@elems.each do |name, value|
|
||||||
@parents.each do |parent|
|
[@rss10, @rss20].each do |rss|
|
||||||
meth = "#{RSS::CONTENT_PREFIX}_#{name}"
|
meth = "#{RSS::CONTENT_PREFIX}_#{name}"
|
||||||
assert_equal(value, @rss.__send__(parent).__send__(meth))
|
parent = rss.items.last
|
||||||
@rss.__send__(parent).__send__("#{meth}=", new_value[name].to_s)
|
assert_equal(value, parent.__send__(meth))
|
||||||
assert_equal(new_value[name], @rss.__send__(parent).__send__(meth))
|
parent.__send__("#{meth}=", new_value[name].to_s)
|
||||||
|
assert_equal(new_value[name], parent.__send__(meth))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_to_s
|
def test_to_s
|
||||||
@elems.each do |name, value|
|
@elems.each do |name, value|
|
||||||
excepted = "<#{@prefix}:#{name}>#{CGI.escapeHTML(value)}</#{@prefix}:#{name}>"
|
excepted = make_element("#{@prefix}:#{name}", {}, value)
|
||||||
@parents.each do |parent|
|
meth = "#{RSS::CONTENT_PREFIX}_#{name}_element"
|
||||||
meth = "#{RSS::CONTENT_PREFIX}_#{name}_element"
|
[@rss10, @rss20].each do |rss|
|
||||||
assert_equal(excepted, @rss.__send__(parent).__send!(meth))
|
assert_equal(excepted, rss.items.last.__send!(meth))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
REXML::Document.new(@rss_source).root.each_element do |parent|
|
[@rss10_source, @rss20_source].each do |source|
|
||||||
if @parents.include?(parent.name)
|
REXML::Document.new(source).root.each_element do |parent|
|
||||||
|
next unless parent.name != "item"
|
||||||
parent.each_element do |elem|
|
parent.each_element do |elem|
|
||||||
if elem.namespace == @uri
|
if elem.namespace == @uri
|
||||||
assert_equal(elem.text, @elems[elem.name.intern].to_s)
|
assert_equal(elem.text, @elems[elem.name.intern].to_s)
|
||||||
|
@ -87,8 +99,6 @@ EOR
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,6 +26,19 @@ module RSS
|
||||||
assert_content(@elements, rss.items.last)
|
assert_content(@elements, rss.items.last)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_rss20
|
||||||
|
rss = RSS::Maker.make("2.0") do |maker|
|
||||||
|
setup_dummy_channel(maker)
|
||||||
|
|
||||||
|
setup_dummy_item(maker)
|
||||||
|
item = maker.items.last
|
||||||
|
@elements.each do |name, value|
|
||||||
|
item.__send__("#{accessor_name(name)}=", value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert_content(@elements, rss.items.last)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def accessor_name(name)
|
def accessor_name(name)
|
||||||
"content_#{name}"
|
"content_#{name}"
|
||||||
|
|
Загрузка…
Ссылка в новой задаче