mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/rss, test/rss, sample/rss: backported from CVS HEAD.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
67c5b057e6
commit
bcf72db844
30 changed files with 1967 additions and 990 deletions
|
@ -1,3 +1,7 @@
|
|||
Wed Dec 8 21:56:31 2004 Kouhei Sutou <kou@cozmixng.org>
|
||||
|
||||
* lib/rss, test/rss, sample/rss: backported from CVS HEAD.
|
||||
|
||||
Wed Dec 8 14:31:36 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* io.c (io_fwrite): change dereference for cosmetic reason.
|
||||
|
|
367
lib/rss/0.9.rb
367
lib/rss/0.9.rb
|
@ -60,17 +60,14 @@ module RSS
|
|||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
next_indent = indent + INDENT
|
||||
rv = <<-EOR
|
||||
#{xmldecl}
|
||||
#{xml_stylesheet_pi}
|
||||
#{indent}<rss version="#{@rss_version}"#{ns_declaration(next_indent)}>
|
||||
#{channel_element(false, next_indent)}
|
||||
#{other_element(false, next_indent)}
|
||||
#{indent}</rss>
|
||||
EOR
|
||||
rv = tag(indent, ns_declarations) do |next_indent|
|
||||
[
|
||||
channel_element(false, next_indent),
|
||||
other_element(false, next_indent),
|
||||
]
|
||||
end
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
remove_empty_newline(rv)
|
||||
rv
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -86,7 +83,7 @@ EOR
|
|||
|
||||
def _attrs
|
||||
[
|
||||
["version", true],
|
||||
["version", true, "rss_version"],
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -104,8 +101,6 @@ EOR
|
|||
["webMaster", "?"],
|
||||
["rating", "?"],
|
||||
["docs", "?"],
|
||||
["skipDays", "?"],
|
||||
["skipHours", "?"],
|
||||
].each do |x, occurs|
|
||||
install_text_element(x)
|
||||
install_model(x, occurs)
|
||||
|
@ -120,6 +115,8 @@ EOR
|
|||
end
|
||||
|
||||
[
|
||||
["skipDays", "?"],
|
||||
["skipHours", "?"],
|
||||
["image", nil],
|
||||
["textInput", "?"],
|
||||
].each do |x, occurs|
|
||||
|
@ -146,35 +143,35 @@ EOR
|
|||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
next_indent = indent + INDENT
|
||||
rv = <<-EOT
|
||||
#{indent}<channel>
|
||||
#{title_element(false, next_indent)}
|
||||
#{link_element(false, next_indent)}
|
||||
#{description_element(false, next_indent)}
|
||||
#{language_element(false, next_indent)}
|
||||
#{copyright_element(false, next_indent)}
|
||||
#{managingEditor_element(false, next_indent)}
|
||||
#{webMaster_element(false, next_indent)}
|
||||
#{rating_element(false, next_indent)}
|
||||
#{pubDate_element(false, next_indent)}
|
||||
#{lastBuildDate_element(false, next_indent)}
|
||||
#{docs_element(false, next_indent)}
|
||||
#{skipDays_element(false, next_indent)}
|
||||
#{skipHours_element(false, next_indent)}
|
||||
#{image_element(false, next_indent)}
|
||||
#{item_elements(false, next_indent)}
|
||||
#{textInput_element(false, next_indent)}
|
||||
#{other_element(false, next_indent)}
|
||||
#{indent}</channel>
|
||||
EOT
|
||||
rv = tag(indent) do |next_indent|
|
||||
[
|
||||
title_element(false, next_indent),
|
||||
link_element(false, next_indent),
|
||||
description_element(false, next_indent),
|
||||
language_element(false, next_indent),
|
||||
copyright_element(false, next_indent),
|
||||
managingEditor_element(false, next_indent),
|
||||
webMaster_element(false, next_indent),
|
||||
rating_element(false, next_indent),
|
||||
pubDate_element(false, next_indent),
|
||||
lastBuildDate_element(false, next_indent),
|
||||
docs_element(false, next_indent),
|
||||
cloud_element(false, next_indent),
|
||||
skipDays_element(false, next_indent),
|
||||
skipHours_element(false, next_indent),
|
||||
image_element(false, next_indent),
|
||||
item_elements(false, next_indent),
|
||||
textInput_element(false, next_indent),
|
||||
other_element(false, next_indent),
|
||||
]
|
||||
end
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
end
|
||||
|
||||
private
|
||||
def children
|
||||
[@image, @textInput, @cloud, *@item]
|
||||
[@skipDays, @skipHours, @image, @textInput, @cloud, *@item]
|
||||
end
|
||||
|
||||
def _tags
|
||||
|
@ -206,6 +203,121 @@ EOT
|
|||
rv
|
||||
end
|
||||
|
||||
def maker_target(maker)
|
||||
maker.channel
|
||||
end
|
||||
|
||||
def setup_maker_elements(channel)
|
||||
super
|
||||
[
|
||||
[skipDays, "day"],
|
||||
[skipHours, "hour"],
|
||||
].each do |skip, key|
|
||||
if skip
|
||||
skip.__send__("#{key}s").each do |val|
|
||||
target_skips = channel.__send__("skip#{key.capitalize}s")
|
||||
new_target = target_skips.__send__("new_#{key}")
|
||||
new_target.content = val.content
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class SkipDays < Element
|
||||
include RSS09
|
||||
|
||||
[
|
||||
["day", "*"]
|
||||
].each do |x, occurs|
|
||||
install_have_children_element(x)
|
||||
install_model(x, occurs)
|
||||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
rv = tag(indent) do |next_indent|
|
||||
[
|
||||
day_elements(false, next_indent)
|
||||
]
|
||||
end
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
end
|
||||
|
||||
private
|
||||
def children
|
||||
@day
|
||||
end
|
||||
|
||||
def _tags
|
||||
@day.compact.collect do
|
||||
[nil, "day"]
|
||||
end
|
||||
end
|
||||
|
||||
class Day < Element
|
||||
include RSS09
|
||||
|
||||
content_setup
|
||||
|
||||
def initialize(content=nil)
|
||||
super()
|
||||
@content = content
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class SkipHours < Element
|
||||
include RSS09
|
||||
|
||||
[
|
||||
["hour", "*"]
|
||||
].each do |x, occurs|
|
||||
install_have_children_element(x)
|
||||
install_model(x, occurs)
|
||||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
rv = tag(indent) do |next_indent|
|
||||
[
|
||||
hour_elements(false, next_indent)
|
||||
]
|
||||
end
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
end
|
||||
|
||||
private
|
||||
def children
|
||||
@hour
|
||||
end
|
||||
|
||||
def _tags
|
||||
@hour.compact.collect do
|
||||
[nil, "hour"]
|
||||
end
|
||||
end
|
||||
|
||||
class Hour < Element
|
||||
include RSS09
|
||||
|
||||
content_setup
|
||||
|
||||
def initialize(content=nil)
|
||||
super()
|
||||
@content = content
|
||||
end
|
||||
|
||||
remove_method :content=
|
||||
def content=(value)
|
||||
@content = value.to_i
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Image < Element
|
||||
|
||||
include RSS09
|
||||
|
@ -220,19 +332,18 @@ EOT
|
|||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
next_indent = indent + INDENT
|
||||
rv = <<-EOT
|
||||
#{indent}<image>
|
||||
#{url_element(false, next_indent)}
|
||||
#{title_element(false, next_indent)}
|
||||
#{link_element(false, next_indent)}
|
||||
#{width_element(false, next_indent)}
|
||||
#{height_element(false, next_indent)}
|
||||
#{description_element(false, next_indent)}
|
||||
#{other_element(false, next_indent)}
|
||||
#{indent}</image>
|
||||
EOT
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv = tag(indent) do |next_indent|
|
||||
[
|
||||
url_element(false, next_indent),
|
||||
title_element(false, next_indent),
|
||||
link_element(false, next_indent),
|
||||
width_element(false, next_indent),
|
||||
height_element(false, next_indent),
|
||||
description_element(false, next_indent),
|
||||
other_element(false, next_indent),
|
||||
]
|
||||
end
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
end
|
||||
|
||||
|
@ -244,8 +355,12 @@ EOT
|
|||
[nil, elem]
|
||||
end
|
||||
end
|
||||
|
||||
def maker_target(maker)
|
||||
maker.image
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class Cloud < Element
|
||||
|
||||
include RSS09
|
||||
|
@ -270,16 +385,8 @@ EOT
|
|||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
next_indent = indent + INDENT
|
||||
rv = <<-EOT
|
||||
#{indent}<cloud
|
||||
#{next_indent}domain="#{h @domain}"
|
||||
#{next_indent}port="#{h @port}"
|
||||
#{next_indent}path="#{h @path}"
|
||||
#{next_indent}registerProcedure="#{h @registerProcedure}"
|
||||
#{next_indent}protocol="#{h @protocol}"/>
|
||||
EOT
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv = tag(indent)
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
end
|
||||
|
||||
|
@ -300,15 +407,21 @@ EOT
|
|||
install_text_element(x)
|
||||
end
|
||||
|
||||
%w(category source enclosure).each do |x|
|
||||
%w(source enclosure).each do |x|
|
||||
install_have_child_element(x)
|
||||
end
|
||||
|
||||
[
|
||||
%w(category categories),
|
||||
].each do |name, plural_name|
|
||||
install_have_children_element(name, plural_name)
|
||||
end
|
||||
|
||||
[
|
||||
["title", '?'],
|
||||
["link", '?'],
|
||||
["description", '?'],
|
||||
["category", '?'],
|
||||
["category", '*'],
|
||||
["source", '?'],
|
||||
["enclosure", '?'],
|
||||
].each do |tag, occurs|
|
||||
|
@ -316,36 +429,51 @@ EOT
|
|||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
next_indent = indent + INDENT
|
||||
rv = <<-EOT
|
||||
#{indent}<item>
|
||||
#{title_element(false, next_indent)}
|
||||
#{link_element(false, next_indent)}
|
||||
#{description_element(false, next_indent)}
|
||||
#{category_element(false, next_indent)}
|
||||
#{source_element(false, next_indent)}
|
||||
#{enclosure_element(false, next_indent)}
|
||||
#{other_element(false, next_indent)}
|
||||
#{indent}</item>
|
||||
EOT
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv = tag(indent) do |next_indent|
|
||||
[
|
||||
title_element(false, next_indent),
|
||||
link_element(false, next_indent),
|
||||
description_element(false, next_indent),
|
||||
category_elements(false, next_indent),
|
||||
source_element(false, next_indent),
|
||||
enclosure_element(false, next_indent),
|
||||
other_element(false, next_indent),
|
||||
]
|
||||
end
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
end
|
||||
|
||||
private
|
||||
def children
|
||||
[@category, @source, @enclosure,].compact
|
||||
[@source, @enclosure, *@category].compact
|
||||
end
|
||||
|
||||
def _tags
|
||||
%w(title link description author comments category
|
||||
rv = %w(title link description author comments
|
||||
source enclosure).delete_if do |x|
|
||||
send(x).nil?
|
||||
end.collect do |x|
|
||||
[nil, x]
|
||||
end
|
||||
|
||||
@category.each do
|
||||
rv << [nil, "category"]
|
||||
end
|
||||
|
||||
rv
|
||||
end
|
||||
|
||||
def maker_target(maker)
|
||||
maker.items.new_item
|
||||
end
|
||||
|
||||
def setup_maker_element(item)
|
||||
super
|
||||
@enclosure.setup_maker(item) if @enclosure
|
||||
@source.setup_maker(item) if @source
|
||||
end
|
||||
|
||||
class Source < Element
|
||||
|
||||
include RSS09
|
||||
|
@ -364,17 +492,6 @@ EOT
|
|||
@content = content
|
||||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
if @url
|
||||
rv = %Q! <source url="#{@url}">!
|
||||
rv << %Q!#{@content}</source>!
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def _tags
|
||||
[]
|
||||
|
@ -386,6 +503,15 @@ EOT
|
|||
]
|
||||
end
|
||||
|
||||
|
||||
def maker_target(item)
|
||||
item.source
|
||||
end
|
||||
|
||||
def setup_maker_attributes(source)
|
||||
source.url = url
|
||||
source.content = content
|
||||
end
|
||||
end
|
||||
|
||||
class Enclosure < Element
|
||||
|
@ -408,14 +534,9 @@ EOT
|
|||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
if @url and @length and @type
|
||||
rv = %Q!<enclosure url="#{h @url}" !
|
||||
rv << %Q!length="#{h @length}" type="#{h @type}"/>!
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
else
|
||||
''
|
||||
end
|
||||
rv = tag(indent)
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -427,6 +548,15 @@ EOT
|
|||
]
|
||||
end
|
||||
|
||||
def maker_target(item)
|
||||
item.enclosure
|
||||
end
|
||||
|
||||
def setup_maker_attributes(enclosure)
|
||||
enclosure.url = url
|
||||
enclosure.length = length
|
||||
enclosure.type = type
|
||||
end
|
||||
end
|
||||
|
||||
class Category < Element
|
||||
|
@ -447,17 +577,6 @@ EOT
|
|||
@content = content
|
||||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
if @domain
|
||||
rv = %Q!<category domain="#{h @domain}">!
|
||||
rv << %Q!#{h @content}</category>!
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def _attrs
|
||||
[
|
||||
|
@ -465,12 +584,21 @@ EOT
|
|||
]
|
||||
end
|
||||
|
||||
def maker_target(item)
|
||||
item.new_category
|
||||
end
|
||||
|
||||
def setup_maker_attributes(category)
|
||||
category.domain = domain
|
||||
category.content = content
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class TextInput < Element
|
||||
|
||||
|
||||
include RSS09
|
||||
|
||||
%w(title description name link).each do |x|
|
||||
|
@ -479,16 +607,15 @@ EOT
|
|||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
next_indent = indent + INDENT
|
||||
rv = <<-EOT
|
||||
#{indent}<textInput>
|
||||
#{title_element(false, next_indent)}
|
||||
#{description_element(false, next_indent)}
|
||||
#{name_element(false, next_indent)}
|
||||
#{link_element(false, next_indent)}
|
||||
#{other_element(false, next_indent)}
|
||||
#{indent}</textInput>
|
||||
EOT
|
||||
rv = tag(indent) do |next_indent|
|
||||
[
|
||||
title_element(false, next_indent),
|
||||
description_element(false, next_indent),
|
||||
name_element(false, next_indent),
|
||||
link_element(false, next_indent),
|
||||
other_element(false, next_indent),
|
||||
]
|
||||
end
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
end
|
||||
|
@ -501,6 +628,10 @@ EOT
|
|||
[nil, elem]
|
||||
end
|
||||
end
|
||||
|
||||
def maker_target(maker)
|
||||
maker.textinput
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
209
lib/rss/1.0.rb
209
lib/rss/1.0.rb
|
@ -18,7 +18,6 @@ module RSS
|
|||
|
||||
include RSS10
|
||||
include RootElementMixin
|
||||
include XMLStyleSheetMixin
|
||||
|
||||
class << self
|
||||
|
||||
|
@ -57,21 +56,22 @@ module RSS
|
|||
super('1.0', version, encoding, standalone)
|
||||
end
|
||||
|
||||
def full_name
|
||||
tag_name_with_prefix(PREFIX)
|
||||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
next_indent = indent + INDENT
|
||||
rv = <<-EORDF
|
||||
#{xmldecl}
|
||||
#{xml_stylesheet_pi}
|
||||
#{indent}<#{PREFIX}:RDF#{ns_declaration(next_indent)}>
|
||||
#{channel_element(false, next_indent)}
|
||||
#{image_element(false, next_indent)}
|
||||
#{item_elements(false, next_indent)}
|
||||
#{textinput_element(false, next_indent)}
|
||||
#{other_element(false, next_indent)}
|
||||
#{indent}</#{PREFIX}:RDF>
|
||||
EORDF
|
||||
rv = tag(indent, ns_declarations) do |next_indent|
|
||||
[
|
||||
channel_element(false, next_indent),
|
||||
image_element(false, next_indent),
|
||||
item_elements(false, next_indent),
|
||||
textinput_element(false, next_indent),
|
||||
other_element(false, next_indent),
|
||||
]
|
||||
end
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
remove_empty_newline(rv)
|
||||
rv
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -119,16 +119,19 @@ EORDF
|
|||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
next_indent = indent + INDENT
|
||||
<<-EOT
|
||||
#{indent}<#{PREFIX}:Seq>
|
||||
#{li_elements(convert, next_indent)}
|
||||
#{other_element(convert, next_indent)}
|
||||
#{indent}</#{PREFIX}:Seq>
|
||||
EOT
|
||||
tag(indent) do |next_indent|
|
||||
[
|
||||
li_elements(convert, next_indent),
|
||||
other_element(convert, next_indent),
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def full_name
|
||||
tag_name_with_prefix(PREFIX)
|
||||
end
|
||||
|
||||
private
|
||||
def children
|
||||
@li
|
||||
end
|
||||
|
@ -169,15 +172,15 @@ EOT
|
|||
super()
|
||||
@resource = resource
|
||||
end
|
||||
|
||||
def full_name
|
||||
tag_name_with_prefix(PREFIX)
|
||||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
if @resource
|
||||
rv = %Q!#{indent}<#{PREFIX}:li resource="#{h @resource}" />\n!
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
else
|
||||
''
|
||||
end
|
||||
rv = tag(indent)
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -232,20 +235,17 @@ EOT
|
|||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
next_indent = indent + INDENT
|
||||
about = ''
|
||||
about << %Q!#{PREFIX}:about="#{h @about}"! if @about
|
||||
rv = <<-EOT
|
||||
#{indent}<channel #{about}>
|
||||
#{title_element(false, next_indent)}
|
||||
#{link_element(false, next_indent)}
|
||||
#{description_element(false, next_indent)}
|
||||
#{image_element(false, next_indent)}
|
||||
#{items_element(false, next_indent)}
|
||||
#{textinput_element(false, next_indent)}
|
||||
#{other_element(false, next_indent)}
|
||||
#{indent}</channel>
|
||||
EOT
|
||||
rv = tag(indent) do |next_indent|
|
||||
[
|
||||
title_element(false, next_indent),
|
||||
link_element(false, next_indent),
|
||||
description_element(false, next_indent),
|
||||
image_element(false, next_indent),
|
||||
items_element(false, next_indent),
|
||||
textinput_element(false, next_indent),
|
||||
other_element(false, next_indent),
|
||||
]
|
||||
end
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
end
|
||||
|
@ -270,10 +270,18 @@ EOT
|
|||
|
||||
def _attrs
|
||||
[
|
||||
["about", true]
|
||||
["#{PREFIX}:about", true, "about"]
|
||||
]
|
||||
end
|
||||
|
||||
def maker_target(maker)
|
||||
maker.channel
|
||||
end
|
||||
|
||||
def setup_maker_attributes(channel)
|
||||
channel.about = self.about
|
||||
end
|
||||
|
||||
class Image < Element
|
||||
|
||||
include RSS10
|
||||
|
@ -298,22 +306,17 @@ EOT
|
|||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
if @resource
|
||||
rv = %Q!#{indent}<image #{PREFIX}:resource="#{h @resource}" />!
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
else
|
||||
''
|
||||
end
|
||||
rv = tag(indent)
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
end
|
||||
|
||||
private
|
||||
def _attrs
|
||||
[
|
||||
["resource", true]
|
||||
["#{PREFIX}:resource", true, "resource"]
|
||||
]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Textinput < Element
|
||||
|
@ -340,22 +343,17 @@ EOT
|
|||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
if @resource
|
||||
rv = %Q|#{indent}<textinput #{PREFIX}:resource="#{h @resource}" />|
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
else
|
||||
''
|
||||
end
|
||||
rv = tag(indent)
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
end
|
||||
|
||||
private
|
||||
def _attrs
|
||||
[
|
||||
["resource", true],
|
||||
["#{PREFIX}:resource", true, "resource"]
|
||||
]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Items < Element
|
||||
|
@ -387,13 +385,12 @@ EOT
|
|||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
next_indent = indent + INDENT
|
||||
<<-EOT
|
||||
#{indent}<items>
|
||||
#{Seq_element(convert, next_indent)}
|
||||
#{other_element(convert, next_indent)}
|
||||
#{indent}</items>
|
||||
EOT
|
||||
rv = tag(indent) do |next_indent|
|
||||
[
|
||||
Seq_element(convert, next_indent),
|
||||
other_element(convert, next_indent),
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -452,17 +449,14 @@ EOT
|
|||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
next_indent = indent + INDENT
|
||||
about = ''
|
||||
about << %Q!#{PREFIX}:about="#{h @about}"! if @about
|
||||
rv = <<-EOT
|
||||
#{indent}<image #{about}>
|
||||
#{title_element(false, next_indent)}
|
||||
#{url_element(false, next_indent)}
|
||||
#{link_element(false, next_indent)}
|
||||
#{other_element(false, next_indent)}
|
||||
#{indent}</image>
|
||||
EOT
|
||||
rv = tag(indent) do |next_indent|
|
||||
[
|
||||
title_element(false, next_indent),
|
||||
url_element(false, next_indent),
|
||||
link_element(false, next_indent),
|
||||
other_element(false, next_indent),
|
||||
]
|
||||
end
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
end
|
||||
|
@ -480,10 +474,13 @@ EOT
|
|||
|
||||
def _attrs
|
||||
[
|
||||
["about", true],
|
||||
["#{PREFIX}:about", true, "about"]
|
||||
]
|
||||
end
|
||||
|
||||
def maker_target(maker)
|
||||
maker.image
|
||||
end
|
||||
end
|
||||
|
||||
class Item < Element
|
||||
|
@ -522,17 +519,14 @@ EOT
|
|||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
next_indent = indent + INDENT
|
||||
about = ''
|
||||
about << %Q!#{PREFIX}:about="#{h @about}"! if @about
|
||||
rv = <<-EOT
|
||||
#{indent}<item #{about}>
|
||||
#{title_element(false, next_indent)}
|
||||
#{link_element(false, next_indent)}
|
||||
#{description_element(false, next_indent)}
|
||||
#{other_element(false, next_indent)}
|
||||
#{indent}</item>
|
||||
EOT
|
||||
rv = tag(indent) do |next_indent|
|
||||
[
|
||||
title_element(false, next_indent),
|
||||
link_element(false, next_indent),
|
||||
description_element(false, next_indent),
|
||||
other_element(false, next_indent),
|
||||
]
|
||||
end
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
end
|
||||
|
@ -550,10 +544,13 @@ EOT
|
|||
|
||||
def _attrs
|
||||
[
|
||||
["about", true],
|
||||
["#{PREFIX}:about", true, "about"]
|
||||
]
|
||||
end
|
||||
|
||||
def maker_target(maker)
|
||||
maker.items.new_item
|
||||
end
|
||||
end
|
||||
|
||||
class Textinput < Element
|
||||
|
@ -593,18 +590,15 @@ EOT
|
|||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
next_indent = indent + INDENT
|
||||
about = ''
|
||||
about << %Q!#{PREFIX}:about="#{h @about}"! if @about
|
||||
rv = <<-EOT
|
||||
#{indent}<textinput #{about}>
|
||||
#{title_element(false, next_indent)}
|
||||
#{description_element(false, next_indent)}
|
||||
#{name_element(false, next_indent)}
|
||||
#{link_element(false, next_indent)}
|
||||
#{other_element(false, next_indent)}
|
||||
#{indent}</textinput>
|
||||
EOT
|
||||
rv = tag(indent) do |next_indent|
|
||||
[
|
||||
title_element(false, next_indent),
|
||||
description_element(false, next_indent),
|
||||
name_element(false, next_indent),
|
||||
link_element(false, next_indent),
|
||||
other_element(false, next_indent),
|
||||
]
|
||||
end
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
end
|
||||
|
@ -623,10 +617,13 @@ EOT
|
|||
|
||||
def _attrs
|
||||
[
|
||||
["about", true],
|
||||
["#{PREFIX}:about", true, "about"]
|
||||
]
|
||||
end
|
||||
|
||||
def maker_target(maker)
|
||||
maker.textinput
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -11,11 +11,18 @@ module RSS
|
|||
install_model(x, '?')
|
||||
end
|
||||
|
||||
%w(category).each do |x|
|
||||
install_have_child_element(x)
|
||||
install_model(x, '?')
|
||||
remove_method :ttl=
|
||||
def ttl=(value)
|
||||
@ttl = value.to_i
|
||||
end
|
||||
|
||||
|
||||
[
|
||||
%w(category categories),
|
||||
].each do |name, plural_name|
|
||||
install_have_children_element(name, plural_name)
|
||||
install_model(name, '*')
|
||||
end
|
||||
|
||||
[
|
||||
["image", "?"],
|
||||
["language", "?"],
|
||||
|
@ -25,7 +32,7 @@ module RSS
|
|||
|
||||
def other_element(convert, indent)
|
||||
rv = <<-EOT
|
||||
#{category_element(convert, indent)}
|
||||
#{category_elements(convert, indent)}
|
||||
#{generator_element(convert, indent)}
|
||||
#{ttl_element(convert, indent)}
|
||||
EOT
|
||||
|
@ -35,16 +42,22 @@ EOT
|
|||
private
|
||||
alias children09 children
|
||||
def children
|
||||
children09 + [@category].compact
|
||||
children09 + @category.compact
|
||||
end
|
||||
|
||||
alias _tags09 _tags
|
||||
def _tags
|
||||
%w(generator ttl category).delete_if do |x|
|
||||
rv = %w(generator ttl).delete_if do |x|
|
||||
send(x).nil?
|
||||
end.collect do |elem|
|
||||
[nil, elem]
|
||||
end + _tags09
|
||||
|
||||
@category.each do
|
||||
rv << [nil, "category"]
|
||||
end
|
||||
|
||||
rv
|
||||
end
|
||||
|
||||
Category = Item::Category
|
||||
|
@ -74,13 +87,15 @@ EOT
|
|||
end
|
||||
|
||||
def other_element(convert, indent)
|
||||
rv = <<-EOT
|
||||
#{author_element(false, indent)}
|
||||
#{comments_element(false, indent)}
|
||||
#{pubDate_element(false, indent)}
|
||||
#{guid_element(false, indent)}
|
||||
EOT
|
||||
rv << super
|
||||
rv = [
|
||||
super,
|
||||
*%w(author comments pubDate guid).collect do |name|
|
||||
__send__("#{name}_element", false, indent)
|
||||
end
|
||||
].reject do |value|
|
||||
/\A\s*\z/.match(value)
|
||||
end
|
||||
rv.join("\n")
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -98,6 +113,12 @@ EOT
|
|||
end + _tags09
|
||||
end
|
||||
|
||||
alias _setup_maker_element setup_maker_element
|
||||
def setup_maker_element(item)
|
||||
_setup_maker_element(item)
|
||||
@guid.setup_maker(item) if @guid
|
||||
end
|
||||
|
||||
class Guid < Element
|
||||
|
||||
include RSS09
|
||||
|
@ -116,18 +137,6 @@ EOT
|
|||
@content = content
|
||||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
if @content
|
||||
rv = %Q!<guid!
|
||||
rv << %Q! isPermaLink="#{h @isPermaLink}"! if @isPermaLink
|
||||
rv << %Q!>#{h @content}</guid>!
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def _attrs
|
||||
[
|
||||
|
@ -135,6 +144,14 @@ EOT
|
|||
]
|
||||
end
|
||||
|
||||
def maker_target(item)
|
||||
item.guid
|
||||
end
|
||||
|
||||
def setup_maker_attributes(guid)
|
||||
guid.isPermaLink = isPermaLink
|
||||
guid.content = content
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -7,12 +7,7 @@ module RSS
|
|||
MAKERS = {}
|
||||
|
||||
class << self
|
||||
def make(version, modules=[], &block)
|
||||
prefix = "rss/maker"
|
||||
require "#{prefix}/#{version}"
|
||||
modules.each do |mod|
|
||||
require "#{prefix}/#{mod}"
|
||||
end
|
||||
def make(version, &block)
|
||||
maker(version).make(&block)
|
||||
end
|
||||
|
||||
|
@ -31,3 +26,10 @@ module RSS
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
require "rss/maker/1.0"
|
||||
require "rss/maker/2.0"
|
||||
require "rss/maker/content"
|
||||
require "rss/maker/dublincore"
|
||||
require "rss/maker/syndication"
|
||||
require "rss/maker/trackback"
|
||||
|
|
|
@ -11,23 +11,15 @@ module RSS
|
|||
super
|
||||
end
|
||||
|
||||
def to_rss
|
||||
rss = Rss.new(@rss_version, @version, @encoding, @standalone)
|
||||
setup_xml_stylesheets(rss)
|
||||
setup_channel(rss)
|
||||
setup_other_elements(rss)
|
||||
if rss.channel
|
||||
rss
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def setup_channel(rss)
|
||||
@channel.to_rss(rss)
|
||||
def make_rss
|
||||
Rss.new(@rss_version, @version, @encoding, @standalone)
|
||||
end
|
||||
|
||||
|
||||
def setup_elements(rss)
|
||||
setup_channel(rss)
|
||||
end
|
||||
|
||||
class Channel < ChannelBase
|
||||
|
||||
def to_rss(rss)
|
||||
|
@ -44,12 +36,13 @@ module RSS
|
|||
else
|
||||
nil
|
||||
end
|
||||
elsif variable_is_set?
|
||||
raise NotSetError.new("maker.channel", not_set_required_variables)
|
||||
end
|
||||
end
|
||||
|
||||
def have_required_values?
|
||||
@title and @link and @description and @language and
|
||||
@maker.image.have_required_values?
|
||||
@title and @link and @description and @language
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -69,9 +62,76 @@ module RSS
|
|||
super + ["pubDate"]
|
||||
end
|
||||
|
||||
def required_variable_names
|
||||
%w(title link description language)
|
||||
end
|
||||
|
||||
class SkipDays < SkipDaysBase
|
||||
def to_rss(rss, channel)
|
||||
unless @days.empty?
|
||||
skipDays = Rss::Channel::SkipDays.new
|
||||
channel.skipDays = skipDays
|
||||
@days.each do |day|
|
||||
day.to_rss(rss, skipDays.days)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Day < DayBase
|
||||
def to_rss(rss, days)
|
||||
day = Rss::Channel::SkipDays::Day.new
|
||||
set = setup_values(day)
|
||||
if set
|
||||
days << day
|
||||
setup_other_elements(rss)
|
||||
end
|
||||
end
|
||||
|
||||
def have_required_values?
|
||||
@content
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class SkipHours < SkipHoursBase
|
||||
def to_rss(rss, channel)
|
||||
unless @hours.empty?
|
||||
skipHours = Rss::Channel::SkipHours.new
|
||||
channel.skipHours = skipHours
|
||||
@hours.each do |hour|
|
||||
hour.to_rss(rss, skipHours.hours)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Hour < HourBase
|
||||
def to_rss(rss, hours)
|
||||
hour = Rss::Channel::SkipHours::Hour.new
|
||||
set = setup_values(hour)
|
||||
if set
|
||||
hours << hour
|
||||
setup_other_elements(rss)
|
||||
end
|
||||
end
|
||||
|
||||
def have_required_values?
|
||||
@content
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Cloud < CloudBase
|
||||
def to_rss(*args)
|
||||
end
|
||||
end
|
||||
|
||||
class Categories < CategoriesBase
|
||||
def to_rss(*args)
|
||||
end
|
||||
|
||||
class Category < CategoryBase
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Image < ImageBase
|
||||
|
@ -130,9 +190,12 @@ module RSS
|
|||
end
|
||||
end
|
||||
|
||||
class Category < CategoryBase
|
||||
class Categories < CategoriesBase
|
||||
def to_rss(*args)
|
||||
end
|
||||
|
||||
class Category < CategoryBase
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -156,5 +219,6 @@ module RSS
|
|||
end
|
||||
|
||||
add_maker(filename_to_version(__FILE__), RSS09)
|
||||
add_maker(filename_to_version(__FILE__) + "1", RSS09)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,41 +11,22 @@ module RSS
|
|||
super("1.0")
|
||||
end
|
||||
|
||||
def to_rss
|
||||
rss = RDF.new(@version, @encoding, @standalone)
|
||||
setup_xml_stylesheets(rss)
|
||||
private
|
||||
def make_rss
|
||||
RDF.new(@version, @encoding, @standalone)
|
||||
end
|
||||
|
||||
def setup_elements(rss)
|
||||
setup_channel(rss)
|
||||
setup_image(rss)
|
||||
setup_items(rss)
|
||||
setup_textinput(rss)
|
||||
setup_other_elements(rss)
|
||||
if rss.channel
|
||||
rss
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def setup_channel(rss)
|
||||
@channel.to_rss(rss)
|
||||
end
|
||||
|
||||
def setup_image(rss)
|
||||
@image.to_rss(rss)
|
||||
end
|
||||
|
||||
def setup_items(rss)
|
||||
@items.to_rss(rss)
|
||||
end
|
||||
|
||||
def setup_textinput(rss)
|
||||
@textinput.to_rss(rss)
|
||||
end
|
||||
|
||||
class Channel < ChannelBase
|
||||
|
||||
def to_rss(rss)
|
||||
set = false
|
||||
if @about
|
||||
channel = RDF::Channel.new(@about)
|
||||
set = setup_values(channel)
|
||||
|
@ -57,12 +38,16 @@ module RSS
|
|||
setup_other_elements(rss)
|
||||
end
|
||||
end
|
||||
|
||||
if (!@about or !set) and variable_is_set?
|
||||
raise NotSetError.new("maker.channel", not_set_required_variables)
|
||||
end
|
||||
end
|
||||
|
||||
def have_required_values?
|
||||
@about and @title and @link and @description
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def setup_items(rss)
|
||||
items = RDF::Channel::Items.new
|
||||
|
@ -86,7 +71,37 @@ module RSS
|
|||
end
|
||||
end
|
||||
|
||||
def required_variable_names
|
||||
%w(about title link description)
|
||||
end
|
||||
|
||||
class SkipDays < SkipDaysBase
|
||||
def to_rss(*args)
|
||||
end
|
||||
|
||||
class Day < DayBase
|
||||
end
|
||||
end
|
||||
|
||||
class SkipHours < SkipHoursBase
|
||||
def to_rss(*args)
|
||||
end
|
||||
|
||||
class Hour < HourBase
|
||||
end
|
||||
end
|
||||
|
||||
class Cloud < CloudBase
|
||||
def to_rss(*args)
|
||||
end
|
||||
end
|
||||
|
||||
class Categories < CategoriesBase
|
||||
def to_rss(*args)
|
||||
end
|
||||
|
||||
class Category < CategoryBase
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -153,9 +168,12 @@ module RSS
|
|||
end
|
||||
end
|
||||
|
||||
class Category < CategoryBase
|
||||
class Categories < CategoriesBase
|
||||
def to_rss(*args)
|
||||
end
|
||||
|
||||
class Category < CategoryBase
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,23 +13,30 @@ module RSS
|
|||
|
||||
class Channel < RSS09::Channel
|
||||
|
||||
add_other_element("cloud")
|
||||
|
||||
def have_required_values?
|
||||
@title and @link and @description
|
||||
end
|
||||
|
||||
private
|
||||
def setup_cloud(rss, current)
|
||||
@maker.channel.cloud.to_rss(rss)
|
||||
def required_variable_names
|
||||
%w(title link description)
|
||||
end
|
||||
|
||||
|
||||
class SkipDays < RSS09::Channel::SkipDays
|
||||
class Day < RSS09::Channel::SkipDays::Day
|
||||
end
|
||||
end
|
||||
|
||||
class SkipHours < RSS09::Channel::SkipHours
|
||||
class Hour < RSS09::Channel::SkipHours::Hour
|
||||
end
|
||||
end
|
||||
|
||||
class Cloud < RSS09::Channel::Cloud
|
||||
def to_rss(rss)
|
||||
def to_rss(rss, channel)
|
||||
cloud = Rss::Channel::Cloud.new
|
||||
set = setup_values(cloud)
|
||||
if set
|
||||
rss.channel.cloud = cloud
|
||||
channel.cloud = cloud
|
||||
setup_other_elements(rss)
|
||||
end
|
||||
end
|
||||
|
@ -39,6 +46,30 @@ module RSS
|
|||
@registerProcedure and @protocol
|
||||
end
|
||||
end
|
||||
|
||||
class Categories < RSS09::Channel::Categories
|
||||
def to_rss(rss, channel)
|
||||
@categories.each do |category|
|
||||
category.to_rss(rss, channel)
|
||||
end
|
||||
end
|
||||
|
||||
class Category < RSS09::Channel::Categories::Category
|
||||
def to_rss(rss, channel)
|
||||
category = Rss::Channel::Category.new
|
||||
set = setup_values(category)
|
||||
if set
|
||||
channel.categories << category
|
||||
setup_other_elements(rss)
|
||||
end
|
||||
end
|
||||
|
||||
def have_required_values?
|
||||
@content
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Image < RSS09::Image
|
||||
|
@ -102,18 +133,26 @@ module RSS
|
|||
end
|
||||
end
|
||||
|
||||
class Category < RSS09::Items::Item::Category
|
||||
class Categories < RSS09::Items::Item::Categories
|
||||
def to_rss(rss, item)
|
||||
category = Rss::Channel::Item::Category.new
|
||||
set = setup_values(category)
|
||||
if set
|
||||
item.category = category
|
||||
setup_other_elements(rss)
|
||||
@categories.each do |category|
|
||||
category.to_rss(rss, item)
|
||||
end
|
||||
end
|
||||
|
||||
def have_required_values?
|
||||
@content
|
||||
|
||||
class Category < RSS09::Items::Item::Categories::Category
|
||||
def to_rss(rss, item)
|
||||
category = Rss::Channel::Item::Category.new
|
||||
set = setup_values(category)
|
||||
if set
|
||||
item.categories << category
|
||||
setup_other_elements(rss)
|
||||
end
|
||||
end
|
||||
|
||||
def have_required_values?
|
||||
@content
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,13 +38,24 @@ module RSS
|
|||
OTHER_ELEMENTS
|
||||
end
|
||||
|
||||
def self.add_need_initialize_variable(variable_name)
|
||||
const_get("NEED_INITIALIZE_VARIABLES") << variable_name
|
||||
def self.add_need_initialize_variable(variable_name, init_value="nil")
|
||||
const_get("NEED_INITIALIZE_VARIABLES") << [variable_name, init_value]
|
||||
end
|
||||
|
||||
def self.need_initialize_variables
|
||||
NEED_INITIALIZE_VARIABLES
|
||||
end
|
||||
|
||||
def self.def_array_element(name)
|
||||
include Enumerable
|
||||
extend Forwardable
|
||||
|
||||
def_delegators("@\#{name}", :<<, :[], :[]=, :first, :last)
|
||||
def_delegators("@\#{name}", :push, :pop, :shift, :unshift)
|
||||
def_delegators("@\#{name}", :each)
|
||||
|
||||
add_need_initialize_variable(name, "[]")
|
||||
end
|
||||
EOC
|
||||
end
|
||||
|
||||
|
@ -59,8 +70,8 @@ module RSS
|
|||
|
||||
private
|
||||
def initialize_variables
|
||||
self.class.need_initialize_variables.each do |variable_name|
|
||||
instance_eval("@#{variable_name} = nil", __FILE__, __LINE__)
|
||||
self.class.need_initialize_variables.each do |variable_name, init_value|
|
||||
instance_eval("@#{variable_name} = #{init_value}", __FILE__, __LINE__)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -88,7 +99,28 @@ module RSS
|
|||
end
|
||||
|
||||
def variables
|
||||
self.class.need_initialize_variables
|
||||
self.class.need_initialize_variables.find_all do |name, init|
|
||||
"nil" == init
|
||||
end.collect do |name, init|
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
def variable_is_set?
|
||||
variables.find {|var| !__send__(var).nil?}
|
||||
end
|
||||
|
||||
def not_set_required_variables
|
||||
required_variable_names.find_all do |var|
|
||||
__send__(var).nil?
|
||||
end
|
||||
end
|
||||
|
||||
def required_variables_are_set?
|
||||
required_variable_names.each do |var|
|
||||
return false if __send__(var).nil?
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -102,9 +134,22 @@ module RSS
|
|||
end
|
||||
end
|
||||
|
||||
attr_reader :rss_version, :xml_stylesheets
|
||||
attr_reader :channel, :image, :items, :textinput
|
||||
%w(xml_stylesheets channel image items textinput).each do |element|
|
||||
attr_reader element
|
||||
add_need_initialize_variable(element, "make_#{element}")
|
||||
module_eval(<<-EOC, __FILE__, __LINE__)
|
||||
private
|
||||
def setup_#{element}(rss)
|
||||
@#{element}.to_rss(rss)
|
||||
end
|
||||
|
||||
def make_#{element}
|
||||
self.class::#{element[0,1].upcase}#{element[1..-1]}.new(self)
|
||||
end
|
||||
EOC
|
||||
end
|
||||
|
||||
attr_reader :rss_version
|
||||
attr_accessor :version, :encoding, :standalone
|
||||
|
||||
def initialize(rss_version)
|
||||
|
@ -113,63 +158,45 @@ module RSS
|
|||
@version = "1.0"
|
||||
@encoding = "UTF-8"
|
||||
@standalone = nil
|
||||
@xml_stylesheets = make_xml_stylesheets
|
||||
@channel = make_channel
|
||||
@image = make_image
|
||||
@items = make_items
|
||||
@textinput = make_textinput
|
||||
end
|
||||
|
||||
def make(&block)
|
||||
block.call(self) if block
|
||||
to_rss
|
||||
def make
|
||||
if block_given?
|
||||
yield(self)
|
||||
to_rss
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def to_rss
|
||||
rss = make_rss
|
||||
setup_xml_stylesheets(rss)
|
||||
setup_elements(rss)
|
||||
setup_other_elements(rss)
|
||||
if rss.channel
|
||||
rss
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def current_element(rss)
|
||||
rss
|
||||
end
|
||||
|
||||
private
|
||||
remove_method :make_xml_stylesheets
|
||||
def make_xml_stylesheets
|
||||
XMLStyleSheets.new(self)
|
||||
end
|
||||
|
||||
def make_channel
|
||||
self.class::Channel.new(self)
|
||||
end
|
||||
|
||||
def make_image
|
||||
self.class::Image.new(self)
|
||||
end
|
||||
|
||||
def make_items
|
||||
self.class::Items.new(self)
|
||||
end
|
||||
|
||||
def make_textinput
|
||||
self.class::Textinput.new(self)
|
||||
end
|
||||
|
||||
def setup_xml_stylesheets(rss)
|
||||
@xml_stylesheets.to_rss(rss)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class XMLStyleSheets
|
||||
include Base
|
||||
|
||||
include Enumerable
|
||||
extend Forwardable
|
||||
|
||||
def_delegators(:@xml_stylesheets, :<<, :[], :[]=, :first, :last)
|
||||
def_delegators(:@xml_stylesheets, :push, :pop, :shift, :unshift)
|
||||
def_delegators(:@xml_stylesheets, :each)
|
||||
|
||||
def initialize(maker)
|
||||
super
|
||||
@xml_stylesheets = []
|
||||
end
|
||||
def_array_element("xml_stylesheets")
|
||||
|
||||
def to_rss(rss)
|
||||
@xml_stylesheets.each do |xss|
|
||||
|
@ -217,12 +244,25 @@ module RSS
|
|||
class ChannelBase
|
||||
include Base
|
||||
|
||||
attr_reader :cloud
|
||||
%w(cloud categories skipDays skipHours).each do |element|
|
||||
attr_reader element
|
||||
add_other_element(element)
|
||||
add_need_initialize_variable(element, "make_#{element}")
|
||||
module_eval(<<-EOC, __FILE__, __LINE__)
|
||||
private
|
||||
def setup_#{element}(rss, current)
|
||||
@#{element}.to_rss(rss, current)
|
||||
end
|
||||
|
||||
def make_#{element}
|
||||
self.class::#{element[0,1].upcase}#{element[1..-1]}.new(@maker)
|
||||
end
|
||||
EOC
|
||||
end
|
||||
|
||||
%w(about title link description language copyright
|
||||
managingEditor webMaster rating docs skipDays
|
||||
skipHours date lastBuildDate category generator ttl
|
||||
).each do |element|
|
||||
managingEditor webMaster rating docs date
|
||||
lastBuildDate generator ttl).each do |element|
|
||||
attr_accessor element
|
||||
add_need_initialize_variable(element)
|
||||
end
|
||||
|
@ -230,18 +270,68 @@ module RSS
|
|||
alias_method(:pubDate, :date)
|
||||
alias_method(:pubDate=, :date=)
|
||||
|
||||
def initialize(maker)
|
||||
super
|
||||
@cloud = make_cloud
|
||||
end
|
||||
|
||||
def current_element(rss)
|
||||
rss.channel
|
||||
end
|
||||
|
||||
private
|
||||
def make_cloud
|
||||
self.class::Cloud.new(@maker)
|
||||
class SkipDaysBase
|
||||
include Base
|
||||
|
||||
def_array_element("days")
|
||||
|
||||
def new_day
|
||||
day = self.class::Day.new(@maker)
|
||||
@days << day
|
||||
day
|
||||
end
|
||||
|
||||
def current_element(rss)
|
||||
rss.channel.skipDays
|
||||
end
|
||||
|
||||
class DayBase
|
||||
include Base
|
||||
|
||||
%w(content).each do |element|
|
||||
attr_accessor element
|
||||
add_need_initialize_variable(element)
|
||||
end
|
||||
|
||||
def current_element(rss)
|
||||
rss.channel.skipDays.last
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
class SkipHoursBase
|
||||
include Base
|
||||
|
||||
def_array_element("hours")
|
||||
|
||||
def new_hour
|
||||
hour = self.class::Hour.new(@maker)
|
||||
@hours << hour
|
||||
hour
|
||||
end
|
||||
|
||||
def current_element(rss)
|
||||
rss.channel.skipHours
|
||||
end
|
||||
|
||||
class HourBase
|
||||
include Base
|
||||
|
||||
%w(content).each do |element|
|
||||
attr_accessor element
|
||||
add_need_initialize_variable(element)
|
||||
end
|
||||
|
||||
def current_element(rss)
|
||||
rss.channel.skipHours.last
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
class CloudBase
|
||||
|
@ -257,6 +347,27 @@ module RSS
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
class CategoriesBase
|
||||
include Base
|
||||
|
||||
def_array_element("categories")
|
||||
|
||||
def new_category
|
||||
category = self.class::Category.new(@maker)
|
||||
@categories << category
|
||||
category
|
||||
end
|
||||
|
||||
class CategoryBase
|
||||
include Base
|
||||
|
||||
%w(domain content).each do |element|
|
||||
attr_accessor element
|
||||
add_need_initialize_variable(element)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ImageBase
|
||||
|
@ -279,23 +390,18 @@ module RSS
|
|||
class ItemsBase
|
||||
include Base
|
||||
|
||||
include Enumerable
|
||||
extend Forwardable
|
||||
|
||||
def_delegators(:@items, :<<, :[], :[]=, :first, :last)
|
||||
def_delegators(:@items, :push, :pop, :shift, :unshift)
|
||||
def_delegators(:@items, :each)
|
||||
def_array_element("items")
|
||||
|
||||
attr_accessor :do_sort
|
||||
attr_accessor :do_sort, :max_size
|
||||
|
||||
def initialize(maker)
|
||||
super
|
||||
@items = []
|
||||
@do_sort = false
|
||||
@max_size = -1
|
||||
end
|
||||
|
||||
def normalize
|
||||
sort_if_need
|
||||
sort_if_need[0..@max_size]
|
||||
end
|
||||
|
||||
def current_element(rss)
|
||||
|
@ -326,9 +432,10 @@ module RSS
|
|||
class ItemBase
|
||||
include Base
|
||||
|
||||
%w(guid enclosure source category).each do |element|
|
||||
%w(guid enclosure source categories).each do |element|
|
||||
attr_reader element
|
||||
add_other_element(element)
|
||||
add_need_initialize_variable(element, "make_#{element}")
|
||||
module_eval(<<-EOC, __FILE__, __LINE__)
|
||||
private
|
||||
def setup_#{element}(rss, current)
|
||||
|
@ -349,14 +456,6 @@ EOC
|
|||
alias_method(:pubDate, :date)
|
||||
alias_method(:pubDate=, :date=)
|
||||
|
||||
def initialize(maker)
|
||||
super
|
||||
@guid = make_guid
|
||||
@enclosure = make_enclosure
|
||||
@source = make_source
|
||||
@category = make_category
|
||||
end
|
||||
|
||||
def <=>(other)
|
||||
if @date and other.date
|
||||
@date <=> other.date
|
||||
|
@ -400,14 +499,7 @@ EOC
|
|||
end
|
||||
end
|
||||
|
||||
class CategoryBase
|
||||
include Base
|
||||
|
||||
%w(domain content).each do |element|
|
||||
attr_accessor element
|
||||
add_need_initialize_variable(element)
|
||||
end
|
||||
end
|
||||
CategoriesBase = ChannelBase::CategoriesBase
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require 'rss/trackback'
|
||||
require 'rss/maker/1.0'
|
||||
require 'rss/maker/2.0'
|
||||
|
||||
module RSS
|
||||
module Maker
|
||||
|
@ -7,18 +8,65 @@ module RSS
|
|||
def self.append_features(klass)
|
||||
super
|
||||
|
||||
%w(ping about).each do |element|
|
||||
name = "#{RSS::TRACKBACK_PREFIX}_#{element}"
|
||||
klass.add_need_initialize_variable(name)
|
||||
klass.add_other_element(name)
|
||||
klass.__send__(:attr_accessor, name)
|
||||
klass.module_eval(<<-EOC, __FILE__, __LINE__)
|
||||
def setup_#{name}(rss, current)
|
||||
if #{name} and current.respond_to?(:#{name}=)
|
||||
current.#{name} = @#{name} if @#{name}
|
||||
end
|
||||
name = "#{RSS::TRACKBACK_PREFIX}_ping"
|
||||
klass.add_need_initialize_variable(name)
|
||||
klass.add_other_element(name)
|
||||
klass.__send__(:attr_accessor, name)
|
||||
klass.module_eval(<<-EOC, __FILE__, __LINE__)
|
||||
def setup_#{name}(rss, current)
|
||||
if #{name} and current.respond_to?(:#{name}=)
|
||||
current.#{name} = #{name}
|
||||
end
|
||||
EOC
|
||||
end
|
||||
EOC
|
||||
|
||||
name = "#{RSS::TRACKBACK_PREFIX}_abouts"
|
||||
klass.add_need_initialize_variable(name, "make_#{name}")
|
||||
klass.add_other_element(name)
|
||||
klass.__send__(:attr_accessor, name)
|
||||
klass.module_eval(<<-EOC, __FILE__, __LINE__)
|
||||
def make_#{name}
|
||||
self.class::TrackBackAbouts.new(self)
|
||||
end
|
||||
|
||||
def setup_#{name}(rss, current)
|
||||
@#{name}.to_rss(rss, current)
|
||||
end
|
||||
EOC
|
||||
end
|
||||
|
||||
class TrackBackAboutsBase
|
||||
include Base
|
||||
|
||||
def_array_element("abouts")
|
||||
|
||||
def new_about
|
||||
about = self.class::About.new(@maker)
|
||||
@abouts << about
|
||||
about
|
||||
end
|
||||
|
||||
def to_rss(rss, current)
|
||||
@abouts.each do |about|
|
||||
about.to_rss(rss, current)
|
||||
end
|
||||
end
|
||||
|
||||
class AboutBase
|
||||
include Base
|
||||
|
||||
attr_accessor :value
|
||||
add_need_initialize_variable(:value)
|
||||
|
||||
alias_method(:resource, :value)
|
||||
alias_method(:resource=, :value=)
|
||||
alias_method(:content, :value)
|
||||
alias_method(:content=, :value=)
|
||||
|
||||
def have_required_values?
|
||||
@value
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -26,5 +74,53 @@ module RSS
|
|||
class ItemsBase
|
||||
class ItemBase; include TrackBackModel; end
|
||||
end
|
||||
|
||||
class RSS10
|
||||
class Items
|
||||
class Item
|
||||
class TrackBackAbouts < TrackBackAboutsBase
|
||||
class About < AboutBase
|
||||
def to_rss(rss, current)
|
||||
if resource
|
||||
about = ::RSS::TrackBackModel10::About.new(resource)
|
||||
current.trackback_abouts << about
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class RSS09
|
||||
class Items
|
||||
class Item
|
||||
class TrackBackAbouts < TrackBackAboutsBase
|
||||
def to_rss(*args)
|
||||
end
|
||||
class About < AboutBase
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class RSS20
|
||||
class Items
|
||||
class Item
|
||||
class TrackBackAbouts < TrackBackAboutsBase
|
||||
class About < AboutBase
|
||||
def to_rss(rss, current)
|
||||
if content
|
||||
about = ::RSS::TrackBackModel20::About.new(content)
|
||||
current.trackback_abouts << about
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -348,6 +348,13 @@ module RSS
|
|||
end
|
||||
|
||||
if @do_validate and required and val.nil?
|
||||
unless a_uri.include?(nil)
|
||||
for prefix, uri in ns
|
||||
if a_uri.include?(uri)
|
||||
a_name = "#{prefix}:#{a_name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
raise MissingAttributeError.new(tag_name, a_name)
|
||||
end
|
||||
|
||||
|
@ -357,10 +364,9 @@ module RSS
|
|||
previous = @last_element
|
||||
next_element = klass.send(:new, *args)
|
||||
next_element.do_validate = @do_validate
|
||||
setter = ""
|
||||
setter << "#{klass.required_prefix}_" if klass.required_prefix
|
||||
setter << "#{tag_name}="
|
||||
@last_element.send(setter, next_element)
|
||||
prefix = ""
|
||||
prefix << "#{klass.required_prefix}_" if klass.required_prefix
|
||||
previous.__send__(:set_next_element, prefix, tag_name, next_element)
|
||||
@last_element = next_element
|
||||
@proc_stack.push Proc.new { |text, tags|
|
||||
p(@last_element.class) if DEBUG
|
||||
|
|
|
@ -36,7 +36,7 @@ module RSS
|
|||
include ListenerMixin
|
||||
|
||||
def xmldecl(version, encoding, standalone)
|
||||
super
|
||||
super(version, encoding, standalone == "yes")
|
||||
# Encoding is converted to UTF-8 when REXML parse XML.
|
||||
@encoding = 'UTF-8'
|
||||
end
|
||||
|
|
256
lib/rss/rss.rb
256
lib/rss/rss.rb
|
@ -58,7 +58,7 @@ require "rss/xml-stylesheet"
|
|||
|
||||
module RSS
|
||||
|
||||
VERSION = "0.1.0"
|
||||
VERSION = "0.1.2"
|
||||
|
||||
URI = "http://purl.org/rss/1.0/"
|
||||
|
||||
|
@ -144,6 +144,15 @@ module RSS
|
|||
end
|
||||
end
|
||||
|
||||
class NotSetError < Error
|
||||
attr_reader :name, :variables
|
||||
def initialize(name, variables)
|
||||
@name = name
|
||||
@variables = variables
|
||||
super("required variables of #{@name} are not set: #{@variables.join(', ')}")
|
||||
end
|
||||
end
|
||||
|
||||
module BaseModel
|
||||
|
||||
include Utils
|
||||
|
@ -164,17 +173,20 @@ EOC
|
|||
end
|
||||
alias_method(:install_have_attribute_element, :install_have_child_element)
|
||||
|
||||
def install_have_children_element(name, postfix="s")
|
||||
add_have_children_element(name)
|
||||
|
||||
def_children_accessor(name, postfix)
|
||||
install_element(name, postfix) do |n, elem_name|
|
||||
def install_have_children_element(name, plural_name=nil)
|
||||
plural_name ||= "#{name}s"
|
||||
add_have_children_element(name, plural_name)
|
||||
add_plural_form(name, plural_name)
|
||||
|
||||
def_children_accessor(name, plural_name)
|
||||
install_element(name, "s") do |n, elem_name|
|
||||
<<-EOC
|
||||
rv = ''
|
||||
rv = []
|
||||
@#{n}.each do |x|
|
||||
rv << "\#{x.to_s(convert, indent)}"
|
||||
value = "\#{x.to_s(convert, indent)}"
|
||||
rv << value if /\\A\\s*\\z/ !~ value
|
||||
end
|
||||
rv
|
||||
rv.join("\n")
|
||||
EOC
|
||||
end
|
||||
end
|
||||
|
@ -289,9 +301,9 @@ EOC
|
|||
end
|
||||
end
|
||||
|
||||
def def_children_accessor(accessor_name, postfix="s")
|
||||
def def_children_accessor(accessor_name, plural_name)
|
||||
module_eval(<<-EOC, *get_file_and_line_from_caller(2))
|
||||
def #{accessor_name}#{postfix}
|
||||
def #{plural_name}
|
||||
@#{accessor_name}
|
||||
end
|
||||
|
||||
|
@ -302,8 +314,12 @@ EOC
|
|||
@#{accessor_name}.send("[]", *args)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def #{accessor_name}=(*args)
|
||||
warn("Warning:\#{caller.first.sub(/:in `.*'\z/, '')}: " \
|
||||
"Don't use `#{accessor_name} = XXX'/`set_#{accessor_name}(XXX)'. " \
|
||||
"Those APIs are not sense of Ruby. " \
|
||||
"Use `#{plural_name} << XXX' instead of them.")
|
||||
if args.size == 1
|
||||
@#{accessor_name}.push(args[0])
|
||||
else
|
||||
|
@ -314,6 +330,22 @@ EOC
|
|||
EOC
|
||||
end
|
||||
|
||||
def def_content_only_to_s
|
||||
module_eval(<<-EOC, *get_file_and_line_from_caller(2))
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
if @content
|
||||
rv = tag(indent) do |next_indent|
|
||||
h(@content)
|
||||
end
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
EOC
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Element
|
||||
|
@ -329,7 +361,8 @@ EOC
|
|||
klass.module_eval(<<-EOC)
|
||||
public
|
||||
|
||||
@tag_name = name.split(/::/).last.downcase
|
||||
@tag_name = name.split(/::/).last
|
||||
@tag_name[0,1] = @tag_name[0,1].downcase
|
||||
@indent_size = name.split(/::/).size - 2
|
||||
|
||||
@@must_call_validators = {}
|
||||
|
@ -373,6 +406,7 @@ EOC
|
|||
def self.content_setup
|
||||
attr_writer :content
|
||||
convert_attr_reader :content
|
||||
def_content_only_to_s
|
||||
@@have_content = true
|
||||
end
|
||||
|
||||
|
@ -386,8 +420,8 @@ EOC
|
|||
@@have_children_elements
|
||||
end
|
||||
|
||||
def self.add_have_children_element(variable_name)
|
||||
@@have_children_elements << variable_name
|
||||
def self.add_have_children_element(variable_name, plural_name)
|
||||
@@have_children_elements << [variable_name, plural_name]
|
||||
end
|
||||
|
||||
@@need_initialize_variables = []
|
||||
|
@ -400,6 +434,16 @@ EOC
|
|||
@@need_initialize_variables
|
||||
end
|
||||
|
||||
@@plural_forms = {}
|
||||
|
||||
def self.add_plural_form(singular, plural)
|
||||
@@plural_forms[singular] = plural
|
||||
end
|
||||
|
||||
def self.plural_forms
|
||||
@@plural_forms
|
||||
end
|
||||
|
||||
EOC
|
||||
end
|
||||
|
||||
|
@ -440,6 +484,14 @@ EOC
|
|||
self.class.tag_name
|
||||
end
|
||||
|
||||
def full_name
|
||||
tag_name
|
||||
end
|
||||
|
||||
def indent_size
|
||||
self.class.indent_size
|
||||
end
|
||||
|
||||
def converter=(converter)
|
||||
@converter = converter
|
||||
children.each do |child|
|
||||
|
@ -457,6 +509,15 @@ EOC
|
|||
__validate(tags, false)
|
||||
end
|
||||
|
||||
def setup_maker(maker)
|
||||
target = maker_target(maker)
|
||||
unless target.nil?
|
||||
setup_maker_attributes(target)
|
||||
setup_maker_element(target)
|
||||
setup_maker_elements(target)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def initialize_variables
|
||||
self.class.need_initialize_variables.each do |variable_name|
|
||||
|
@ -467,11 +528,111 @@ EOC
|
|||
end
|
||||
|
||||
def initialize_have_children_elements
|
||||
self.class.have_children_elements.each do |variable_name|
|
||||
self.class.have_children_elements.each do |variable_name, plural_name|
|
||||
instance_eval("@#{variable_name} = []")
|
||||
end
|
||||
end
|
||||
|
||||
def tag(indent, additional_attrs=[], &block)
|
||||
next_indent = indent + INDENT
|
||||
|
||||
attrs = collect_attrs
|
||||
return "" if attrs.nil?
|
||||
|
||||
attrs += additional_attrs
|
||||
start_tag = make_start_tag(indent, next_indent, attrs)
|
||||
|
||||
if block
|
||||
content = block.call(next_indent)
|
||||
else
|
||||
content = []
|
||||
end
|
||||
|
||||
if content.is_a?(String)
|
||||
content = [content]
|
||||
start_tag << ">"
|
||||
end_tag = "</#{full_name}>"
|
||||
else
|
||||
content = content.reject{|x| x.empty?}
|
||||
if content.empty?
|
||||
end_tag = "/>"
|
||||
else
|
||||
start_tag << ">\n"
|
||||
end_tag = "\n#{indent}</#{full_name}>"
|
||||
end
|
||||
end
|
||||
|
||||
start_tag + content.join("\n") + end_tag
|
||||
end
|
||||
|
||||
def make_start_tag(indent, next_indent, attrs)
|
||||
start_tag = ["#{indent}<#{full_name}"]
|
||||
unless attrs.empty?
|
||||
start_tag << attrs.collect do |key, value|
|
||||
%Q[#{h key}="#{h value}"]
|
||||
end.join("\n#{next_indent}")
|
||||
end
|
||||
start_tag.join(" ")
|
||||
end
|
||||
|
||||
def collect_attrs
|
||||
_attrs.collect do |name, required, alias_name|
|
||||
value = __send__(alias_name || name)
|
||||
return nil if required and value.nil?
|
||||
[name, value]
|
||||
end.reject do |name, value|
|
||||
value.nil?
|
||||
end
|
||||
end
|
||||
|
||||
def tag_name_with_prefix(prefix)
|
||||
"#{prefix}:#{tag_name}"
|
||||
end
|
||||
|
||||
def calc_indent
|
||||
INDENT * (self.class.indent_size)
|
||||
end
|
||||
|
||||
def maker_target(maker)
|
||||
nil
|
||||
end
|
||||
|
||||
def setup_maker_attributes(target)
|
||||
end
|
||||
|
||||
def setup_maker_element(target)
|
||||
self.class.need_initialize_variables.each do |var|
|
||||
setter = "#{var}="
|
||||
if target.respond_to?(setter)
|
||||
target.__send__(setter, __send__(var))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def setup_maker_elements(parent)
|
||||
self.class.have_children_elements.each do |name, plural_name|
|
||||
real_name = name.sub(/^[^_]+_/, '')
|
||||
if parent.respond_to?(plural_name)
|
||||
target = parent.__send__(plural_name)
|
||||
__send__(plural_name).each do |elem|
|
||||
elem.__send__("setup_maker", target)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def set_next_element(prefix, tag_name, next_element)
|
||||
klass = next_element.class
|
||||
prefix = ""
|
||||
prefix << "#{klass.required_prefix}_" if klass.required_prefix
|
||||
if self.class.plural_forms.has_key?(tag_name)
|
||||
ary = __send__("#{prefix}#{self.class.plural_forms[tag_name]}")
|
||||
ary << next_element
|
||||
else
|
||||
__send__("#{prefix}#{tag_name}=", next_element)
|
||||
end
|
||||
end
|
||||
|
||||
# not String class children.
|
||||
def children
|
||||
[]
|
||||
|
@ -507,23 +668,23 @@ EOC
|
|||
end
|
||||
|
||||
def validate_attribute
|
||||
_attrs.each do |a_name, required|
|
||||
if required and send(a_name).nil?
|
||||
raise MissingAttributeError.new(self.class.tag_name, a_name)
|
||||
_attrs.each do |a_name, required, alias_name|
|
||||
if required and __send__(alias_name || a_name).nil?
|
||||
raise MissingAttributeError.new(tag_name, a_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def other_element(convert, indent='')
|
||||
rv = ''
|
||||
rv = []
|
||||
private_methods.each do |meth|
|
||||
if /\A([^_]+)_[^_]+_elements?\z/ =~ meth and
|
||||
self.class::NSPOOL.has_key?($1)
|
||||
res = send(meth, convert)
|
||||
rv << "#{indent}#{res}\n" if /\A\s*\z/ !~ res
|
||||
res = __send__(meth, convert)
|
||||
rv << "#{indent}#{res}" if /\A\s*\z/ !~ res
|
||||
end
|
||||
end
|
||||
rv
|
||||
rv.join("\n")
|
||||
end
|
||||
|
||||
def _validate(tags, model=self.class.model)
|
||||
|
@ -626,19 +787,12 @@ EOC
|
|||
rv
|
||||
end
|
||||
|
||||
private
|
||||
def calc_indent
|
||||
INDENT * (self.class.indent_size)
|
||||
end
|
||||
|
||||
def remove_empty_newline(string)
|
||||
string.gsub(/^\s*$(?:\r?\n?)/, '')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module RootElementMixin
|
||||
|
||||
include XMLStyleSheetMixin
|
||||
|
||||
attr_reader :output_encoding
|
||||
|
||||
def initialize(rss_version, version=nil, encoding=nil, standalone=nil)
|
||||
|
@ -655,26 +809,50 @@ EOC
|
|||
self.converter = Converter.new(@output_encoding, @encoding)
|
||||
end
|
||||
|
||||
def setup_maker(maker)
|
||||
maker.version = version
|
||||
maker.encoding = encoding
|
||||
maker.standalone = standalone
|
||||
|
||||
xml_stylesheets.each do |xss|
|
||||
xss.setup_maker(maker)
|
||||
end
|
||||
|
||||
setup_maker_elements(maker)
|
||||
end
|
||||
|
||||
private
|
||||
def tag(indent, attrs, &block)
|
||||
rv = xmldecl + xml_stylesheet_pi
|
||||
rv << super(indent, attrs, &block)
|
||||
rv
|
||||
end
|
||||
|
||||
def xmldecl
|
||||
rv = %Q[<?xml version="#{@version}"]
|
||||
if @output_encoding or @encoding
|
||||
rv << %Q[ encoding="#{@output_encoding or @encoding}"]
|
||||
end
|
||||
rv << %Q[ standalone="#{@standalone}"] if @standalone
|
||||
rv << '?>'
|
||||
rv << %Q[ standalone="yes"] if @standalone
|
||||
rv << "?>\n"
|
||||
rv
|
||||
end
|
||||
|
||||
def ns_declaration(indent)
|
||||
rv = ''
|
||||
self.class::NSPOOL.each do |prefix, uri|
|
||||
def ns_declarations
|
||||
self.class::NSPOOL.collect do |prefix, uri|
|
||||
prefix = ":#{prefix}" unless prefix.empty?
|
||||
rv << %Q|\n#{indent}xmlns#{prefix}="#{html_escape(uri)}"|
|
||||
["xmlns#{prefix}", uri]
|
||||
end
|
||||
rv
|
||||
end
|
||||
|
||||
def setup_maker_elements(maker)
|
||||
channel.setup_maker(maker) if channel
|
||||
image.setup_maker(maker) if image
|
||||
textinput.setup_maker(maker) if textinput
|
||||
items.each do |item|
|
||||
item.setup_maker(maker)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -9,7 +9,16 @@ module RSS
|
|||
RDF.install_ns(TRACKBACK_PREFIX, TRACKBACK_URI)
|
||||
Rss.install_ns(TRACKBACK_PREFIX, TRACKBACK_URI)
|
||||
|
||||
module BaseTrackBackModel
|
||||
module TrackBackUtils
|
||||
private
|
||||
def new_with_value_if_need(klass, value)
|
||||
if value.is_a?(klass)
|
||||
value
|
||||
else
|
||||
klass.new(value)
|
||||
end
|
||||
end
|
||||
|
||||
def trackback_validate(tags)
|
||||
counter = {}
|
||||
%w(ping about).each do |x|
|
||||
|
@ -31,179 +40,64 @@ module RSS
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
module TrackBackModel10
|
||||
extend BaseModel
|
||||
include BaseTrackBackModel
|
||||
|
||||
def self.append_features(klass)
|
||||
|
||||
module BaseTrackBackModel
|
||||
def append_features(klass)
|
||||
super
|
||||
|
||||
unless klass.class == Module
|
||||
%w(ping).each do |x|
|
||||
klass.install_have_child_element("#{TRACKBACK_PREFIX}_#{x}")
|
||||
end
|
||||
|
||||
%w(about).each do |x|
|
||||
klass.install_have_children_element("#{TRACKBACK_PREFIX}_#{x}")
|
||||
end
|
||||
end
|
||||
end
|
||||
klass.__send__(:include, TrackBackUtils)
|
||||
|
||||
class Ping < Element
|
||||
include RSS10
|
||||
|
||||
class << self
|
||||
|
||||
def required_prefix
|
||||
TRACKBACK_PREFIX
|
||||
end
|
||||
|
||||
def required_uri
|
||||
TRACKBACK_URI
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
[
|
||||
["resource", ::RSS::RDF::URI, true]
|
||||
].each do |name, uri, required|
|
||||
install_get_attribute(name, uri, required)
|
||||
end
|
||||
|
||||
def initialize(resource=nil)
|
||||
super()
|
||||
@resource = resource
|
||||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
if @resource
|
||||
rv = %Q[#{indent}<#{TRACKBACK_PREFIX}:ping ]
|
||||
rv << %Q[#{::RSS::RDF::PREFIX}:resource="#{h @resource}"/>]
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def _attrs
|
||||
[
|
||||
["resource", true],
|
||||
]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class About < Element
|
||||
include RSS10
|
||||
|
||||
class << self
|
||||
|
||||
def required_prefix
|
||||
TRACKBACK_PREFIX
|
||||
end
|
||||
|
||||
def required_uri
|
||||
TRACKBACK_URI
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
[
|
||||
["resource", ::RSS::RDF::URI, true]
|
||||
].each do |name, uri, required|
|
||||
install_get_attribute(name, uri, required)
|
||||
end
|
||||
|
||||
def initialize(resource=nil)
|
||||
super()
|
||||
@resource = resource
|
||||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
if @resource
|
||||
rv = %Q[#{indent}<#{TRACKBACK_PREFIX}:about ]
|
||||
rv << %Q[#{::RSS::RDF::PREFIX}:resource="#{h @resource}"/>]
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def _attrs
|
||||
[
|
||||
["resource", true],
|
||||
]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
module TrackBackModel20
|
||||
include BaseTrackBackModel
|
||||
extend BaseModel
|
||||
|
||||
def self.append_features(klass)
|
||||
super
|
||||
|
||||
unless klass.class == Module
|
||||
%w(ping).each do |x|
|
||||
var_name = "#{TRACKBACK_PREFIX}_#{x}"
|
||||
klass_name = x.capitalize
|
||||
klass.install_have_child_element(var_name)
|
||||
klass.module_eval(<<-EOC)
|
||||
alias _#{var_name} #{var_name}
|
||||
klass.module_eval(<<-EOC, __FILE__, __LINE__)
|
||||
remove_method :#{var_name}
|
||||
def #{var_name}
|
||||
@#{var_name} and @#{var_name}.content
|
||||
@#{var_name} and @#{var_name}.value
|
||||
end
|
||||
|
||||
alias _#{var_name}= #{var_name}=
|
||||
def #{var_name}=(content)
|
||||
@#{var_name} = new_with_content_if_need(#{x.capitalize}, content)
|
||||
remove_method :#{var_name}=
|
||||
def #{var_name}=(value)
|
||||
@#{var_name} = new_with_value_if_need(#{klass_name}, value)
|
||||
end
|
||||
EOC
|
||||
end
|
||||
|
||||
[%w(about s)].each do |x, postfix|
|
||||
var_name = "#{TRACKBACK_PREFIX}_#{x}"
|
||||
[%w(about s)].each do |name, postfix|
|
||||
var_name = "#{TRACKBACK_PREFIX}_#{name}"
|
||||
klass_name = name.capitalize
|
||||
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}
|
||||
klass.module_eval(<<-EOC, __FILE__, __LINE__)
|
||||
remove_method :#{var_name}
|
||||
def #{var_name}(*args)
|
||||
if args.empty?
|
||||
@#{var_name}.first and @#{var_name}.first.content
|
||||
@#{var_name}.first and @#{var_name}.first.value
|
||||
else
|
||||
ret = @#{var_name}.send("[]", *args)
|
||||
if ret.is_a?(Array)
|
||||
ret.collect {|x| x.content}
|
||||
ret.collect {|x| x.value}
|
||||
else
|
||||
ret.content
|
||||
ret.value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
alias _#{var_name}= #{var_name}=
|
||||
alias _set_#{var_name} set_#{var_name}
|
||||
remove_method :#{var_name}=
|
||||
remove_method :set_#{var_name}
|
||||
def #{var_name}=(*args)
|
||||
if args.size == 1
|
||||
item = new_with_content_if_need(#{x.capitalize}, args[0])
|
||||
item = new_with_value_if_need(#{klass_name}, 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)
|
||||
new_with_value_if_need(#{klass_name}, val)
|
||||
end
|
||||
else
|
||||
new_val = new_with_content_if_need(#{x.capitalize}, new_val)
|
||||
new_val = new_with_value_if_need(#{klass_name}, new_val)
|
||||
end
|
||||
@#{var_name}.send("[]=", *(args[0..-2] + [new_val]))
|
||||
end
|
||||
|
@ -213,22 +107,120 @@ module RSS
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def new_with_content(klass, content)
|
||||
obj = klass.new
|
||||
obj.content = content
|
||||
obj
|
||||
end
|
||||
module TrackBackModel10
|
||||
extend BaseModel
|
||||
extend BaseTrackBackModel
|
||||
|
||||
class Ping < Element
|
||||
include RSS10
|
||||
|
||||
class << self
|
||||
|
||||
def required_prefix
|
||||
TRACKBACK_PREFIX
|
||||
end
|
||||
|
||||
def required_uri
|
||||
TRACKBACK_URI
|
||||
end
|
||||
|
||||
def new_with_content_if_need(klass, content)
|
||||
if content.is_a?(klass)
|
||||
content
|
||||
else
|
||||
new_with_content(klass, content)
|
||||
end
|
||||
|
||||
[
|
||||
["resource", ::RSS::RDF::URI, true]
|
||||
].each do |name, uri, required|
|
||||
install_get_attribute(name, uri, required)
|
||||
end
|
||||
|
||||
alias_method(:value, :resource)
|
||||
alias_method(:value=, :resource=)
|
||||
|
||||
def initialize(resource=nil)
|
||||
super()
|
||||
@resource = resource
|
||||
end
|
||||
|
||||
def full_name
|
||||
tag_name_with_prefix(TRACKBACK_PREFIX)
|
||||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
rv = tag(indent)
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
end
|
||||
|
||||
private
|
||||
def _attrs
|
||||
[
|
||||
["#{::RSS::RDF::PREFIX}:resource", true, "resource"],
|
||||
]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class About < Element
|
||||
include RSS10
|
||||
|
||||
class << self
|
||||
|
||||
def required_prefix
|
||||
TRACKBACK_PREFIX
|
||||
end
|
||||
|
||||
def required_uri
|
||||
TRACKBACK_URI
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
[
|
||||
["resource", ::RSS::RDF::URI, true]
|
||||
].each do |name, uri, required|
|
||||
install_get_attribute(name, uri, required)
|
||||
end
|
||||
|
||||
alias_method(:value, :resource)
|
||||
alias_method(:value=, :resource=)
|
||||
|
||||
def initialize(resource=nil)
|
||||
super()
|
||||
@resource = resource
|
||||
end
|
||||
|
||||
def full_name
|
||||
tag_name_with_prefix(TRACKBACK_PREFIX)
|
||||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
rv = tag(indent)
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
end
|
||||
|
||||
private
|
||||
def _attrs
|
||||
[
|
||||
["#{::RSS::RDF::PREFIX}:resource", true, "resource"],
|
||||
]
|
||||
end
|
||||
|
||||
def maker_target(abouts)
|
||||
abouts.new_about
|
||||
end
|
||||
|
||||
def setup_maker_attributes(about)
|
||||
about.resource = self.resource
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
module TrackBackModel20
|
||||
extend BaseModel
|
||||
extend BaseTrackBackModel
|
||||
|
||||
class Ping < Element
|
||||
include RSS09
|
||||
|
@ -247,18 +239,18 @@ module RSS
|
|||
|
||||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
if @content
|
||||
rv = %Q[#{indent}<#{TRACKBACK_PREFIX}:ping>]
|
||||
rv << h(@content)
|
||||
rv << %Q[</#{TRACKBACK_PREFIX}:ping>]
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
alias_method(:value, :content)
|
||||
alias_method(:value=, :content=)
|
||||
|
||||
def initialize(content=nil)
|
||||
super()
|
||||
@content = content
|
||||
end
|
||||
|
||||
def full_name
|
||||
tag_name_with_prefix(TRACKBACK_PREFIX)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class About < Element
|
||||
|
@ -277,19 +269,19 @@ module RSS
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
def to_s(convert=true, indent=calc_indent)
|
||||
if @content
|
||||
rv = %Q[#{indent}<#{TRACKBACK_PREFIX}:about>]
|
||||
rv << h(@content)
|
||||
rv << %Q[</#{TRACKBACK_PREFIX}:about>]
|
||||
rv = @converter.convert(rv) if convert and @converter
|
||||
rv
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
alias_method(:value, :content)
|
||||
alias_method(:value=, :content=)
|
||||
|
||||
def initialize(content=nil)
|
||||
super()
|
||||
@content = content
|
||||
end
|
||||
|
||||
def full_name
|
||||
tag_name_with_prefix(TRACKBACK_PREFIX)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -84,6 +84,13 @@ module RSS
|
|||
@alternate
|
||||
end
|
||||
|
||||
def setup_maker(maker)
|
||||
xss = maker.xml_stylesheets.new_xml_stylesheet
|
||||
ATTRIBUTES.each do |attr|
|
||||
xss.__send__("#{attr}=", __send__(attr))
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def guess_type(filename)
|
||||
/\.([^.]+)$/ =~ filename
|
||||
|
|
|
@ -45,7 +45,7 @@ module RSS
|
|||
end
|
||||
|
||||
def on_xmldecl_end
|
||||
xmldecl(@version, @encoding, @standalone)
|
||||
xmldecl(@version, @encoding, @standalone == "yes")
|
||||
end
|
||||
|
||||
alias_method(:on_pi, :instruction)
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
require "nkf"
|
||||
class String
|
||||
# From tdiary.rb
|
||||
def shorten( len = 120 )
|
||||
lines = NKF::nkf( "-e -m0 -f#{len}", self.gsub( /\n/, ' ' ) ).split( /\n/ )
|
||||
lines[0].concat( '...' ) if lines[0] and lines[1]
|
||||
lines[0]
|
||||
end
|
||||
# From tdiary.rb
|
||||
def shorten( len = 120 )
|
||||
lines = NKF::nkf( "-e -m0 -f#{len}", self.gsub( /\n/, ' ' ) ).split( /\n/ )
|
||||
lines[0].concat( '...' ) if lines[0] and lines[1]
|
||||
lines[0]
|
||||
end
|
||||
end
|
||||
|
||||
require "rss/1.0"
|
||||
|
@ -18,66 +18,66 @@ channels = {}
|
|||
verbose = false
|
||||
|
||||
def error(exception)
|
||||
mark = "=" * 20
|
||||
mark = "#{mark} error #{mark}"
|
||||
puts mark
|
||||
puts exception.class
|
||||
puts exception.message
|
||||
puts exception.backtrace
|
||||
puts mark
|
||||
mark = "=" * 20
|
||||
mark = "#{mark} error #{mark}"
|
||||
puts mark
|
||||
puts exception.class
|
||||
puts exception.message
|
||||
puts exception.backtrace
|
||||
puts mark
|
||||
end
|
||||
|
||||
before_time = Time.now
|
||||
ARGV.each do |fname|
|
||||
if fname == '-v'
|
||||
verbose = true
|
||||
next
|
||||
end
|
||||
rss = nil
|
||||
f = File.new(fname).read
|
||||
begin
|
||||
## do validate parse
|
||||
rss = RSS::Parser.parse(f)
|
||||
rescue RSS::InvalidRSSError
|
||||
error($!) if verbose
|
||||
## do non validate parse for invalid RSS 1.0
|
||||
begin
|
||||
rss = RSS::Parser.parse(f, false)
|
||||
rescue RSS::Error
|
||||
## invalid RSS.
|
||||
error($!) if verbose
|
||||
end
|
||||
rescue RSS::Error
|
||||
error($!) if verbose
|
||||
end
|
||||
if rss.nil?
|
||||
puts "#{fname} does not include RSS 1.0 or 0.9x/2.0"
|
||||
else
|
||||
begin
|
||||
rss.output_encoding = "euc-jp"
|
||||
rescue RSS::UnknownConversionMethodError
|
||||
error($!) if verbose
|
||||
end
|
||||
rss.channel.title ||= "Unknown"
|
||||
rss.items.each do |item|
|
||||
item.title ||= "Unknown"
|
||||
channels[rss.channel.title] ||= []
|
||||
channels[rss.channel.title] << item if item.description
|
||||
end
|
||||
end
|
||||
if fname == '-v'
|
||||
verbose = true
|
||||
next
|
||||
end
|
||||
rss = nil
|
||||
f = File.new(fname).read
|
||||
begin
|
||||
## do validate parse
|
||||
rss = RSS::Parser.parse(f)
|
||||
rescue RSS::InvalidRSSError
|
||||
error($!) if verbose
|
||||
## do non validate parse for invalid RSS 1.0
|
||||
begin
|
||||
rss = RSS::Parser.parse(f, false)
|
||||
rescue RSS::Error
|
||||
## invalid RSS.
|
||||
error($!) if verbose
|
||||
end
|
||||
rescue RSS::Error
|
||||
error($!) if verbose
|
||||
end
|
||||
if rss.nil?
|
||||
puts "#{fname} does not include RSS 1.0 or 0.9x/2.0"
|
||||
else
|
||||
begin
|
||||
rss.output_encoding = "euc-jp"
|
||||
rescue RSS::UnknownConversionMethodError
|
||||
error($!) if verbose
|
||||
end
|
||||
rss.channel.title ||= "Unknown"
|
||||
rss.items.each do |item|
|
||||
item.title ||= "Unknown"
|
||||
channels[rss.channel.title] ||= []
|
||||
channels[rss.channel.title] << item if item.description
|
||||
end
|
||||
end
|
||||
end
|
||||
processing_time = Time.now - before_time
|
||||
|
||||
channels.sort do |x, y|
|
||||
x[0] <=> y[0]
|
||||
x[0] <=> y[0]
|
||||
end[0..20].each do |title, items|
|
||||
puts "Channel: #{title}" unless items.empty?
|
||||
items.sort do |x, y|
|
||||
x.title <=> y.title
|
||||
end[0..10].each do |item|
|
||||
puts " Item: #{item.title.shorten(50)}"
|
||||
puts " Description: #{item.description.shorten(50)}"
|
||||
end
|
||||
puts "Channel: #{title}" unless items.empty?
|
||||
items.sort do |x, y|
|
||||
x.title <=> y.title
|
||||
end[0..10].each do |item|
|
||||
puts " Item: #{item.title.shorten(50)}"
|
||||
puts " Description: #{item.description.shorten(50)}"
|
||||
end
|
||||
end
|
||||
|
||||
puts "Used XML parser: #{RSS::Parser.default_parser}"
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
require "nkf"
|
||||
class String
|
||||
# From tdiary.rb
|
||||
def shorten( len = 120 )
|
||||
lines = NKF::nkf( "-e -m0 -f#{len}", self.gsub( /\n/, ' ' ) ).split( /\n/ )
|
||||
lines[0].concat( '...' ) if lines[0] and lines[1]
|
||||
lines[0]
|
||||
end
|
||||
# From tdiary.rb
|
||||
def shorten( len = 120 )
|
||||
lines = NKF::nkf( "-e -m0 -f#{len}", self.gsub( /\n/, ' ' ) ).split( /\n/ )
|
||||
lines[0].concat( '...' ) if lines[0] and lines[1]
|
||||
lines[0]
|
||||
end
|
||||
end
|
||||
|
||||
require "rss/1.0"
|
||||
|
@ -18,65 +18,65 @@ items = []
|
|||
verbose = false
|
||||
|
||||
def error(exception)
|
||||
mark = "=" * 20
|
||||
mark = "#{mark} error #{mark}"
|
||||
puts mark
|
||||
puts exception.class
|
||||
puts exception.message
|
||||
puts exception.backtrace
|
||||
puts mark
|
||||
mark = "=" * 20
|
||||
mark = "#{mark} error #{mark}"
|
||||
puts mark
|
||||
puts exception.class
|
||||
puts exception.message
|
||||
puts exception.backtrace
|
||||
puts mark
|
||||
end
|
||||
before_time = Time.now
|
||||
ARGV.each do |fname|
|
||||
if fname == '-v'
|
||||
verbose = true
|
||||
next
|
||||
end
|
||||
rss = nil
|
||||
f = File.new(fname).read
|
||||
begin
|
||||
## do validate parse
|
||||
rss = RSS::Parser.parse(f)
|
||||
rescue RSS::InvalidRSSError
|
||||
error($!) if verbose
|
||||
## do non validate parse for invalid RSS 1.0
|
||||
begin
|
||||
rss = RSS::Parser.parse(f, false)
|
||||
rescue RSS::Error
|
||||
## invalid RSS.
|
||||
error($!) if verbose
|
||||
end
|
||||
rescue RSS::Error
|
||||
error($!) if verbose
|
||||
end
|
||||
if rss.nil?
|
||||
puts "#{fname} does not include RSS 1.0 or 0.9x/2.0"
|
||||
else
|
||||
begin
|
||||
rss.output_encoding = "euc-jp"
|
||||
rescue RSS::UnknownConversionMethodError
|
||||
error($!) if verbose
|
||||
end
|
||||
rss.items.each do |item|
|
||||
if item.respond_to?(:pubDate) and item.pubDate
|
||||
class << item
|
||||
alias_method(:dc_date, :pubDate)
|
||||
end
|
||||
end
|
||||
if item.respond_to?(:dc_date) and item.dc_date
|
||||
items << [rss.channel, item]
|
||||
end
|
||||
end
|
||||
end
|
||||
if fname == '-v'
|
||||
verbose = true
|
||||
next
|
||||
end
|
||||
rss = nil
|
||||
f = File.new(fname).read
|
||||
begin
|
||||
## do validate parse
|
||||
rss = RSS::Parser.parse(f)
|
||||
rescue RSS::InvalidRSSError
|
||||
error($!) if verbose
|
||||
## do non validate parse for invalid RSS 1.0
|
||||
begin
|
||||
rss = RSS::Parser.parse(f, false)
|
||||
rescue RSS::Error
|
||||
## invalid RSS.
|
||||
error($!) if verbose
|
||||
end
|
||||
rescue RSS::Error
|
||||
error($!) if verbose
|
||||
end
|
||||
if rss.nil?
|
||||
puts "#{fname} does not include RSS 1.0 or 0.9x/2.0"
|
||||
else
|
||||
begin
|
||||
rss.output_encoding = "euc-jp"
|
||||
rescue RSS::UnknownConversionMethodError
|
||||
error($!) if verbose
|
||||
end
|
||||
rss.items.each do |item|
|
||||
if item.respond_to?(:pubDate) and item.pubDate
|
||||
class << item
|
||||
alias_method(:dc_date, :pubDate)
|
||||
end
|
||||
end
|
||||
if item.respond_to?(:dc_date) and item.dc_date
|
||||
items << [rss.channel, item]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
processing_time = Time.now - before_time
|
||||
|
||||
items.sort do |x, y|
|
||||
y[1].dc_date <=> x[1].dc_date
|
||||
y[1].dc_date <=> x[1].dc_date
|
||||
end[0..20].each do |channel, item|
|
||||
puts "#{item.dc_date.localtime.iso8601}: " <<
|
||||
"#{channel.title}: #{item.title}"
|
||||
puts " Description: #{item.description.shorten(50)}" if item.description
|
||||
puts "#{item.dc_date.localtime.iso8601}: " <<
|
||||
"#{channel.title}: #{item.title}"
|
||||
puts " Description: #{item.description.shorten(50)}" if item.description
|
||||
end
|
||||
|
||||
puts "Used XML parser: #{RSS::Parser.default_parser}"
|
||||
|
|
|
@ -94,27 +94,44 @@ module RSS
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_xml_stylesheet_attrs(xsl, attrs)
|
||||
|
||||
def assert_not_set_error(name, variables)
|
||||
_wrap_assertion do
|
||||
normalized_attrs = {}
|
||||
attrs.each do |name, value|
|
||||
normalized_attrs[name.to_s] = value
|
||||
end
|
||||
::RSS::XMLStyleSheet::ATTRIBUTES.each do |name|
|
||||
assert_equal(normalized_attrs[name], xsl.send(name))
|
||||
begin
|
||||
yield
|
||||
flunk("Not raise NotSetError")
|
||||
rescue ::RSS::NotSetError => e
|
||||
assert_equal(name, e.name)
|
||||
assert_equal(variables.sort, e.variables.sort)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_xml_stylesheet(target, xsl, attrs)
|
||||
def assert_xml_declaration(version, encoding, standalone, rss)
|
||||
_wrap_assertion do
|
||||
assert_equal(version, rss.version)
|
||||
assert_equal(encoding, rss.encoding)
|
||||
assert_equal(standalone, rss.standalone)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_xml_stylesheet_attrs(attrs, xsl)
|
||||
_wrap_assertion do
|
||||
n_attrs = normalized_attrs(attrs)
|
||||
::RSS::XMLStyleSheet::ATTRIBUTES.each do |name|
|
||||
assert_equal(n_attrs[name], xsl.send(name))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_xml_stylesheet(target, attrs, xsl)
|
||||
_wrap_assertion do
|
||||
if attrs.has_key?(:href)
|
||||
if !attrs.has_key?(:type) and attrs.has_key?(:guess_type)
|
||||
attrs[:type] = attrs[:guess_type]
|
||||
end
|
||||
assert_equal("xml-stylesheet", target)
|
||||
assert_xml_stylesheet_attrs(xsl, attrs)
|
||||
assert_xml_stylesheet_attrs(attrs, xsl)
|
||||
else
|
||||
assert_nil(target)
|
||||
assert_equal("", xsl.to_s)
|
||||
|
@ -123,40 +140,314 @@ module RSS
|
|||
end
|
||||
|
||||
def assert_xml_stylesheet_pis(attrs_ary)
|
||||
rdf = ::RSS::RDF.new()
|
||||
xss_strs = []
|
||||
attrs_ary.each do |attrs|
|
||||
xss = ::RSS::XMLStyleSheet.new(*attrs)
|
||||
xss_strs.push(xss.to_s)
|
||||
rdf.xml_stylesheets.push(xss)
|
||||
_wrap_assertion do
|
||||
rdf = ::RSS::RDF.new()
|
||||
xss_strs = []
|
||||
attrs_ary.each do |attrs|
|
||||
xss = ::RSS::XMLStyleSheet.new(*attrs)
|
||||
xss_strs.push(xss.to_s)
|
||||
rdf.xml_stylesheets.push(xss)
|
||||
end
|
||||
pi_str = rdf.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s*<rdf:RDF.*\z/m, "")
|
||||
assert_equal(xss_strs.join("\n"), pi_str)
|
||||
end
|
||||
pi_str = rdf.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s*<rdf:RDF.*\z/m, "")
|
||||
assert_equal(xss_strs.join("\n"), pi_str)
|
||||
end
|
||||
|
||||
def assert_xml_stylesheets(attrs, xss)
|
||||
_wrap_assertion do
|
||||
xss.each_with_index do |xs, i|
|
||||
assert_xml_stylesheet_attrs(attrs[i], xs)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def assert_channel10(attrs, channel)
|
||||
_wrap_assertion do
|
||||
n_attrs = normalized_attrs(attrs)
|
||||
|
||||
names = %w(about title link description)
|
||||
assert_attributes(attrs, names, channel)
|
||||
|
||||
%w(image items textinput).each do |name|
|
||||
value = n_attrs[name]
|
||||
if value
|
||||
target = channel.__send__(name)
|
||||
__send__("assert_channel10_#{name}", value, target)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_channel10_image(attrs, image)
|
||||
_wrap_assertion do
|
||||
assert_attributes(attrs, %w(resource), image)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_channel10_textinput(attrs, textinput)
|
||||
_wrap_assertion do
|
||||
assert_attributes(attrs, %w(resource), textinput)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_channel10_items(attrs, items)
|
||||
_wrap_assertion do
|
||||
items.Seq.lis.each_with_index do |li, i|
|
||||
assert_attributes(attrs[i], %w(resource), li)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_image10(attrs, image)
|
||||
_wrap_assertion do
|
||||
names = %w(about title url link)
|
||||
assert_attributes(attrs, names, image)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_items10(attrs, items)
|
||||
_wrap_assertion do
|
||||
names = %w(about title link description)
|
||||
items.each_with_index do |item, i|
|
||||
assert_attributes(attrs[i], names, item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_textinput10(attrs, textinput)
|
||||
_wrap_assertion do
|
||||
names = %w(about title description name link)
|
||||
assert_attributes(attrs, names, textinput)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def assert_channel09(attrs, channel)
|
||||
_wrap_assertion do
|
||||
n_attrs = normalized_attrs(attrs)
|
||||
|
||||
names = %w(title description link language rating
|
||||
copyright pubDate lastBuildDate docs
|
||||
managingEditor webMaster)
|
||||
assert_attributes(attrs, names, channel)
|
||||
|
||||
%w(skipHours skipDays).each do |name|
|
||||
value = n_attrs[name]
|
||||
if value
|
||||
target = channel.__send__(name)
|
||||
__send__("assert_channel09_#{name}", value, target)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_channel09_skipDays(contents, skipDays)
|
||||
_wrap_assertion do
|
||||
days = skipDays.days
|
||||
contents.each_with_index do |content, i|
|
||||
assert_equal(content, days[i].content)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_channel09_skipHours(contents, skipHours)
|
||||
_wrap_assertion do
|
||||
hours = skipHours.hours
|
||||
contents.each_with_index do |content, i|
|
||||
assert_equal(content, hours[i].content)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_image09(attrs, image)
|
||||
_wrap_assertion do
|
||||
names = %w(url link title description width height)
|
||||
assert_attributes(attrs, names, image)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_items09(attrs, items)
|
||||
_wrap_assertion do
|
||||
names = %w(title link description)
|
||||
items.each_with_index do |item, i|
|
||||
assert_attributes(attrs[i], names, item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_textinput09(attrs, textinput)
|
||||
_wrap_assertion do
|
||||
names = %w(title description name link)
|
||||
assert_attributes(attrs, names, textinput)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def assert_channel20(attrs, channel)
|
||||
_wrap_assertion do
|
||||
n_attrs = normalized_attrs(attrs)
|
||||
|
||||
names = %w(title link description language copyright
|
||||
managingEditor webMaster pubDate
|
||||
lastBuildDate generator docs ttl rating)
|
||||
assert_attributes(attrs, names, channel)
|
||||
|
||||
%w(cloud categories skipHours skipDays).each do |name|
|
||||
value = n_attrs[name]
|
||||
if value
|
||||
target = channel.__send__(name)
|
||||
__send__("assert_channel20_#{name}", value, target)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_channel20_skipDays(contents, skipDays)
|
||||
assert_channel09_skipDays(contents, skipDays)
|
||||
end
|
||||
|
||||
def assert_channel20_skipHours(contents, skipHours)
|
||||
assert_channel09_skipHours(contents, skipHours)
|
||||
end
|
||||
|
||||
def assert_channel20_cloud(attrs, cloud)
|
||||
_wrap_assertion do
|
||||
names = %w(domain port path registerProcedure protocol)
|
||||
assert_attributes(attrs, names, cloud)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_channel20_categories(attrs, categories)
|
||||
_wrap_assertion do
|
||||
names = %w(domain content)
|
||||
categories.each_with_index do |category, i|
|
||||
assert_attributes(attrs[i], names, category)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_image20(attrs, image)
|
||||
_wrap_assertion do
|
||||
names = %w(url link title description width height)
|
||||
assert_attributes(attrs, names, image)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_items20(attrs, items)
|
||||
_wrap_assertion do
|
||||
names = %w(about title link description)
|
||||
items.each_with_index do |item, i|
|
||||
assert_attributes(attrs[i], names, item)
|
||||
|
||||
n_attrs = normalized_attrs(attrs[i])
|
||||
|
||||
%w(source enclosure categories guid).each do |name|
|
||||
value = n_attrs[name]
|
||||
if value
|
||||
target = item.__send__(name)
|
||||
__send__("assert_items20_#{name}", value, target)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_items20_source(attrs, source)
|
||||
_wrap_assertion do
|
||||
assert_attributes(attrs, %w(url content), source)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_items20_enclosure(attrs, enclosure)
|
||||
_wrap_assertion do
|
||||
names = %w(url length type)
|
||||
assert_attributes(attrs, names, enclosure)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_items20_categories(attrs, categories)
|
||||
_wrap_assertion do
|
||||
assert_channel20_categories(attrs, categories)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_items20_guid(attrs, guid)
|
||||
_wrap_assertion do
|
||||
assert_attributes(attrs, %w(isPermaLink content), guid)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_textinput20(attrs, textinput)
|
||||
_wrap_assertion do
|
||||
names = %w(title description name link)
|
||||
assert_attributes(attrs, names, textinput)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def assert_dublin_core(elems, target)
|
||||
elems.each do |name, value|
|
||||
assert_equal(value, target.__send__("dc_#{name}"))
|
||||
_wrap_assertion do
|
||||
elems.each do |name, value|
|
||||
assert_equal(value, target.__send__("dc_#{name}"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_syndication(elems, target)
|
||||
elems.each do |name, value|
|
||||
assert_equal(value, target.__send__("sy_#{name}"))
|
||||
_wrap_assertion do
|
||||
elems.each do |name, value|
|
||||
assert_equal(value, target.__send__("sy_#{name}"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_content(elems, target)
|
||||
elems.each do |name, value|
|
||||
assert_equal(value, target.__send__("content_#{name}"))
|
||||
_wrap_assertion do
|
||||
elems.each do |name, value|
|
||||
assert_equal(value, target.__send__("content_#{name}"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_trackback(elems, target)
|
||||
elems.each do |name, value|
|
||||
assert_equal(value, target.__send__("trackback_#{name}"))
|
||||
def assert_trackback(attrs, target)
|
||||
_wrap_assertion do
|
||||
n_attrs = normalized_attrs(attrs)
|
||||
if n_attrs["ping"]
|
||||
assert_equal(n_attrs["ping"], target.trackback_ping)
|
||||
end
|
||||
if n_attrs["abouts"]
|
||||
n_attrs["abouts"].each_with_index do |about, i|
|
||||
assert_equal(about, target.trackback_abouts[i].value)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def assert_attributes(attrs, names, target)
|
||||
_wrap_assertion do
|
||||
n_attrs = normalized_attrs(attrs)
|
||||
names.each do |name|
|
||||
value = n_attrs[name]
|
||||
if value.is_a?(Time)
|
||||
actual = target.__send__(name)
|
||||
assert_instance_of(Time, actual)
|
||||
assert_equal(value.to_i, actual.to_i)
|
||||
elsif value
|
||||
assert_equal(value, target.__send__(name))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def normalized_attrs(attrs)
|
||||
n_attrs = {}
|
||||
attrs.each do |name, value|
|
||||
n_attrs[name.to_s] = value
|
||||
end
|
||||
n_attrs
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ module RSS
|
|||
|
||||
version = "1.0"
|
||||
encoding = "UTF-8"
|
||||
standalone = "no"
|
||||
standalone = false
|
||||
|
||||
rdf = RDF.new(version, encoding, standalone)
|
||||
|
||||
|
@ -27,9 +27,10 @@ module RSS
|
|||
|
||||
xmldecl = doc.xml_decl
|
||||
|
||||
%w(version encoding standalone).each do |x|
|
||||
%w(version encoding).each do |x|
|
||||
assert_equal(instance_eval(x), xmldecl.send(x))
|
||||
end
|
||||
assert_equal(standalone, !xmldecl.standalone.nil?)
|
||||
|
||||
assert_equal(@rdf_uri, doc.root.namespace)
|
||||
|
||||
|
|
|
@ -6,36 +6,38 @@ module RSS
|
|||
class TestMaker09 < TestCase
|
||||
|
||||
def test_rss
|
||||
rss = RSS::Maker.make("0.9")
|
||||
rss = RSS::Maker.make("0.91")
|
||||
assert_nil(rss)
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
setup_dummy_image(maker)
|
||||
end
|
||||
assert_equal("0.91", rss.rss_version)
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
end
|
||||
assert_equal("0.91", rss.rss_version)
|
||||
|
||||
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
setup_dummy_image(maker)
|
||||
|
||||
maker.encoding = "EUC-JP"
|
||||
end
|
||||
assert_equal("0.91", rss.rss_version)
|
||||
assert_equal("EUC-JP", rss.encoding)
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
setup_dummy_image(maker)
|
||||
|
||||
maker.standalone = "yes"
|
||||
end
|
||||
assert_equal("0.91", rss.rss_version)
|
||||
assert_equal("yes", rss.standalone)
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
setup_dummy_image(maker)
|
||||
|
||||
maker.encoding = "EUC-JP"
|
||||
maker.standalone = "yes"
|
||||
|
@ -55,12 +57,18 @@ module RSS
|
|||
webMaster = "web master"
|
||||
rating = "6"
|
||||
docs = "http://foo.com/doc"
|
||||
skipDays = "Sunday"
|
||||
skipHours = "13"
|
||||
skipDays = [
|
||||
"Sunday",
|
||||
"Monday",
|
||||
]
|
||||
skipHours = [
|
||||
0,
|
||||
13,
|
||||
]
|
||||
pubDate = Time.now
|
||||
lastBuildDate = Time.now
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
maker.channel.description = description
|
||||
|
@ -70,12 +78,17 @@ module RSS
|
|||
maker.channel.webMaster = webMaster
|
||||
maker.channel.rating = rating
|
||||
maker.channel.docs = docs
|
||||
maker.channel.skipDays = skipDays
|
||||
maker.channel.skipHours = skipHours
|
||||
maker.channel.pubDate = pubDate
|
||||
maker.channel.lastBuildDate = lastBuildDate
|
||||
|
||||
setup_dummy_image(maker)
|
||||
skipDays.each do |day|
|
||||
new_day = maker.channel.skipDays.new_day
|
||||
new_day.content = day
|
||||
end
|
||||
skipHours.each do |hour|
|
||||
new_hour = maker.channel.skipHours.new_hour
|
||||
new_hour.content = hour
|
||||
end
|
||||
end
|
||||
channel = rss.channel
|
||||
|
||||
|
@ -88,13 +101,18 @@ module RSS
|
|||
assert_equal(webMaster, channel.webMaster)
|
||||
assert_equal(rating, channel.rating)
|
||||
assert_equal(docs, channel.docs)
|
||||
assert_equal(skipDays, channel.skipDays)
|
||||
assert_equal(skipHours, channel.skipHours)
|
||||
assert_equal(pubDate, channel.pubDate)
|
||||
assert_equal(lastBuildDate, channel.lastBuildDate)
|
||||
|
||||
skipDays.each_with_index do |day, i|
|
||||
assert_equal(day, channel.skipDays.days[i].content)
|
||||
end
|
||||
skipHours.each_with_index do |hour, i|
|
||||
assert_equal(hour, channel.skipHours.hours[i].content)
|
||||
end
|
||||
|
||||
assert(channel.items.empty?)
|
||||
assert_not_nil(channel.image)
|
||||
assert_nil(channel.image)
|
||||
assert_nil(channel.textInput)
|
||||
end
|
||||
|
||||
|
@ -103,57 +121,43 @@ module RSS
|
|||
link = "http://hoge.com"
|
||||
description = "fugafugafugafuga"
|
||||
language = "ja"
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
# setup_dummy_image(maker)
|
||||
|
||||
maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
maker.channel.description = description
|
||||
maker.channel.language = language
|
||||
end
|
||||
assert_nil(rss)
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
setup_dummy_image(maker)
|
||||
|
||||
# maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
maker.channel.description = description
|
||||
maker.channel.language = language
|
||||
assert_not_set_error("maker.channel", %w(title)) do
|
||||
RSS::Maker.make("0.91") do |maker|
|
||||
# maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
maker.channel.description = description
|
||||
maker.channel.language = language
|
||||
end
|
||||
end
|
||||
assert_nil(rss)
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
setup_dummy_image(maker)
|
||||
|
||||
maker.channel.title = title
|
||||
# maker.channel.link = link
|
||||
maker.channel.link = nil
|
||||
maker.channel.description = description
|
||||
maker.channel.language = language
|
||||
assert_not_set_error("maker.channel", %w(link)) do
|
||||
RSS::Maker.make("0.91") do |maker|
|
||||
maker.channel.title = title
|
||||
# maker.channel.link = link
|
||||
maker.channel.link = nil
|
||||
maker.channel.description = description
|
||||
maker.channel.language = language
|
||||
end
|
||||
end
|
||||
assert_nil(rss)
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
setup_dummy_image(maker)
|
||||
|
||||
maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
# maker.channel.description = description
|
||||
maker.channel.language = language
|
||||
assert_not_set_error("maker.channel", %w(description)) do
|
||||
RSS::Maker.make("0.91") do |maker|
|
||||
maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
# maker.channel.description = description
|
||||
maker.channel.language = language
|
||||
end
|
||||
end
|
||||
assert_nil(rss)
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
setup_dummy_image(maker)
|
||||
|
||||
maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
maker.channel.description = description
|
||||
# maker.channel.language = language
|
||||
assert_not_set_error("maker.channel", %w(language)) do
|
||||
RSS::Maker.make("0.91") do |maker|
|
||||
maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
maker.channel.description = description
|
||||
# maker.channel.language = language
|
||||
end
|
||||
end
|
||||
assert_nil(rss)
|
||||
end
|
||||
|
||||
def test_image
|
||||
|
@ -164,7 +168,7 @@ module RSS
|
|||
height = 400
|
||||
description = "an image"
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
maker.channel.link = link
|
||||
|
||||
|
@ -182,17 +186,18 @@ module RSS
|
|||
assert_equal(height, image.height)
|
||||
assert_equal(description, image.description)
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
# setup_dummy_channel(maker)
|
||||
maker.channel.link = link
|
||||
assert_not_set_error("maker.channel", %w(description title language)) do
|
||||
RSS::Maker.make("0.91") do |maker|
|
||||
# setup_dummy_channel(maker)
|
||||
maker.channel.link = link
|
||||
|
||||
maker.image.title = title
|
||||
maker.image.url = url
|
||||
maker.image.width = width
|
||||
maker.image.height = height
|
||||
maker.image.description = description
|
||||
maker.image.title = title
|
||||
maker.image.url = url
|
||||
maker.image.width = width
|
||||
maker.image.height = height
|
||||
maker.image.description = description
|
||||
end
|
||||
end
|
||||
assert_nil(rss)
|
||||
end
|
||||
|
||||
def test_not_valid_image
|
||||
|
@ -203,7 +208,7 @@ module RSS
|
|||
height = 400
|
||||
description = "an image"
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
maker.channel.link = link
|
||||
|
||||
|
@ -213,22 +218,23 @@ module RSS
|
|||
maker.image.height = height
|
||||
maker.image.description = description
|
||||
end
|
||||
assert_nil(rss)
|
||||
assert_nil(rss.channel.image)
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
# maker.channel.link = link
|
||||
maker.channel.link = nil
|
||||
assert_not_set_error("maker.channel", %w(link)) do
|
||||
RSS::Maker.make("0.91") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
# maker.channel.link = link
|
||||
maker.channel.link = nil
|
||||
|
||||
maker.image.title = title
|
||||
maker.image.url = url
|
||||
maker.image.width = width
|
||||
maker.image.height = height
|
||||
maker.image.description = description
|
||||
maker.image.title = title
|
||||
maker.image.url = url
|
||||
maker.image.width = width
|
||||
maker.image.height = height
|
||||
maker.image.description = description
|
||||
end
|
||||
end
|
||||
assert_nil(rss)
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
maker.channel.link = link
|
||||
|
||||
|
@ -238,7 +244,7 @@ module RSS
|
|||
maker.image.height = height
|
||||
maker.image.description = description
|
||||
end
|
||||
assert_nil(rss)
|
||||
assert_nil(rss.channel.image)
|
||||
end
|
||||
|
||||
def test_items
|
||||
|
@ -246,15 +252,13 @@ module RSS
|
|||
link = "http://hoge.com/"
|
||||
description = "text hoge fuga"
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
setup_dummy_image(maker)
|
||||
end
|
||||
assert(rss.channel.items.empty?)
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
setup_dummy_image(maker)
|
||||
|
||||
item = maker.items.new_item
|
||||
item.title = title
|
||||
|
@ -269,9 +273,8 @@ module RSS
|
|||
|
||||
|
||||
item_size = 5
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
setup_dummy_image(maker)
|
||||
|
||||
item_size.times do |i|
|
||||
item = maker.items.new_item
|
||||
|
@ -288,9 +291,8 @@ module RSS
|
|||
assert_equal("#{description}#{i}", item.description)
|
||||
end
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
setup_dummy_image(maker)
|
||||
|
||||
item_size.times do |i|
|
||||
item = maker.items.new_item
|
||||
|
@ -316,9 +318,8 @@ module RSS
|
|||
name = "hoge"
|
||||
link = "http://hoge.com"
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
setup_dummy_image(maker)
|
||||
|
||||
maker.textinput.title = title
|
||||
maker.textinput.description = description
|
||||
|
@ -331,9 +332,8 @@ module RSS
|
|||
assert_equal(name, textInput.name)
|
||||
assert_equal(link, textInput.link)
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
# setup_dummy_channel(maker)
|
||||
setup_dummy_image(maker)
|
||||
|
||||
maker.textinput.title = title
|
||||
maker.textinput.description = description
|
||||
|
@ -349,9 +349,8 @@ module RSS
|
|||
name = "hoge"
|
||||
link = "http://hoge.com"
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
setup_dummy_image(maker)
|
||||
|
||||
# maker.textinput.title = title
|
||||
maker.textinput.description = description
|
||||
|
@ -360,9 +359,8 @@ module RSS
|
|||
end
|
||||
assert_nil(rss.channel.textInput)
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
setup_dummy_image(maker)
|
||||
|
||||
maker.textinput.title = title
|
||||
# maker.textinput.description = description
|
||||
|
@ -371,9 +369,8 @@ module RSS
|
|||
end
|
||||
assert_nil(rss.channel.textInput)
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
setup_dummy_image(maker)
|
||||
|
||||
maker.textinput.title = title
|
||||
maker.textinput.description = description
|
||||
|
@ -382,9 +379,8 @@ module RSS
|
|||
end
|
||||
assert_nil(rss.channel.textInput)
|
||||
|
||||
rss = RSS::Maker.make("0.9") do |maker|
|
||||
rss = RSS::Maker.make("0.91") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
setup_dummy_image(maker)
|
||||
|
||||
maker.textinput.title = title
|
||||
maker.textinput.description = description
|
||||
|
|
|
@ -85,37 +85,41 @@ module RSS
|
|||
link = "http://hoge.com"
|
||||
description = "fugafugafugafuga"
|
||||
|
||||
rss = RSS::Maker.make("1.0") do |maker|
|
||||
# maker.channel.about = about
|
||||
maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
maker.channel.description = description
|
||||
assert_not_set_error("maker.channel", %w(about)) do
|
||||
RSS::Maker.make("1.0") do |maker|
|
||||
# maker.channel.about = about
|
||||
maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
maker.channel.description = description
|
||||
end
|
||||
end
|
||||
assert_nil(rss)
|
||||
|
||||
rss = RSS::Maker.make("1.0") do |maker|
|
||||
maker.channel.about = about
|
||||
# maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
maker.channel.description = description
|
||||
assert_not_set_error("maker.channel", %w(title)) do
|
||||
RSS::Maker.make("1.0") do |maker|
|
||||
maker.channel.about = about
|
||||
# maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
maker.channel.description = description
|
||||
end
|
||||
end
|
||||
assert_nil(rss)
|
||||
|
||||
rss = RSS::Maker.make("1.0") do |maker|
|
||||
maker.channel.about = about
|
||||
maker.channel.title = title
|
||||
# maker.channel.link = link
|
||||
maker.channel.description = description
|
||||
assert_not_set_error("maker.channel", %w(link)) do
|
||||
RSS::Maker.make("1.0") do |maker|
|
||||
maker.channel.about = about
|
||||
maker.channel.title = title
|
||||
# maker.channel.link = link
|
||||
maker.channel.description = description
|
||||
end
|
||||
end
|
||||
assert_nil(rss)
|
||||
|
||||
rss = RSS::Maker.make("1.0") do |maker|
|
||||
maker.channel.about = about
|
||||
maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
# maker.channel.description = description
|
||||
assert_not_set_error("maker.channel", %w(description)) do
|
||||
RSS::Maker.make("1.0") do |maker|
|
||||
maker.channel.about = about
|
||||
maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
# maker.channel.description = description
|
||||
end
|
||||
end
|
||||
assert_nil(rss)
|
||||
end
|
||||
|
||||
|
||||
|
@ -138,14 +142,15 @@ module RSS
|
|||
assert_equal(link, image.link)
|
||||
assert_equal(url, image.url)
|
||||
|
||||
rss = RSS::Maker.make("1.0") do |maker|
|
||||
# setup_dummy_channel(maker)
|
||||
maker.channel.link = link
|
||||
|
||||
maker.image.title = title
|
||||
maker.image.url = url
|
||||
assert_not_set_error("maker.channel", %w(about title description)) do
|
||||
RSS::Maker.make("1.0") do |maker|
|
||||
# setup_dummy_channel(maker)
|
||||
maker.channel.link = link
|
||||
|
||||
maker.image.title = title
|
||||
maker.image.url = url
|
||||
end
|
||||
end
|
||||
assert_nil(rss)
|
||||
end
|
||||
|
||||
def test_not_valid_image
|
||||
|
@ -173,15 +178,16 @@ module RSS
|
|||
assert_nil(rss.channel.image)
|
||||
assert_nil(rss.image)
|
||||
|
||||
rss = RSS::Maker.make("1.0") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
# maker.channel.link = link
|
||||
maker.channel.link = nil
|
||||
|
||||
maker.image.url = url
|
||||
maker.image.title = title
|
||||
assert_not_set_error("maker.channel", %w(link)) do
|
||||
RSS::Maker.make("1.0") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
# maker.channel.link = link
|
||||
maker.channel.link = nil
|
||||
|
||||
maker.image.url = url
|
||||
maker.image.title = title
|
||||
end
|
||||
end
|
||||
assert_nil(rss)
|
||||
end
|
||||
|
||||
def test_items
|
||||
|
|
|
@ -51,11 +51,20 @@ module RSS
|
|||
webMaster = "web master"
|
||||
rating = "6"
|
||||
docs = "http://foo.com/doc"
|
||||
skipDays = "Sunday"
|
||||
skipHours = "13"
|
||||
skipDays = [
|
||||
"Sunday",
|
||||
"Monday",
|
||||
]
|
||||
skipHours = [
|
||||
0,
|
||||
13,
|
||||
]
|
||||
pubDate = Time.now
|
||||
lastBuildDate = Time.now
|
||||
category = "Nespapers"
|
||||
categories = [
|
||||
"Nespapers",
|
||||
"misc",
|
||||
]
|
||||
generator = "RSS Maker"
|
||||
ttl = 60
|
||||
|
||||
|
@ -69,11 +78,23 @@ module RSS
|
|||
maker.channel.webMaster = webMaster
|
||||
maker.channel.rating = rating
|
||||
maker.channel.docs = docs
|
||||
maker.channel.skipDays = skipDays
|
||||
maker.channel.skipHours = skipHours
|
||||
maker.channel.pubDate = pubDate
|
||||
maker.channel.lastBuildDate = lastBuildDate
|
||||
maker.channel.category = category
|
||||
|
||||
skipDays.each do |day|
|
||||
new_day = maker.channel.skipDays.new_day
|
||||
new_day.content = day
|
||||
end
|
||||
skipHours.each do |hour|
|
||||
new_hour = maker.channel.skipHours.new_hour
|
||||
new_hour.content = hour
|
||||
end
|
||||
|
||||
categories.each do |category|
|
||||
new_category = maker.channel.categories.new_category
|
||||
new_category.content = category
|
||||
end
|
||||
|
||||
maker.channel.generator = generator
|
||||
maker.channel.ttl = ttl
|
||||
end
|
||||
|
@ -88,11 +109,20 @@ module RSS
|
|||
assert_equal(webMaster, channel.webMaster)
|
||||
assert_equal(rating, channel.rating)
|
||||
assert_equal(docs, channel.docs)
|
||||
assert_equal(skipDays, channel.skipDays)
|
||||
assert_equal(skipHours, channel.skipHours)
|
||||
assert_equal(pubDate, channel.pubDate)
|
||||
assert_equal(lastBuildDate, channel.lastBuildDate)
|
||||
assert_equal(category, channel.category)
|
||||
|
||||
skipDays.each_with_index do |day, i|
|
||||
assert_equal(day, channel.skipDays.days[i].content)
|
||||
end
|
||||
skipHours.each_with_index do |hour, i|
|
||||
assert_equal(hour, channel.skipHours.hours[i].content)
|
||||
end
|
||||
|
||||
channel.categories.each_with_index do |category, i|
|
||||
assert_equal(categories[i], category.content)
|
||||
end
|
||||
|
||||
assert_equal(generator, channel.generator)
|
||||
assert_equal(ttl, channel.ttl)
|
||||
|
||||
|
@ -107,29 +137,32 @@ module RSS
|
|||
description = "fugafugafugafuga"
|
||||
language = "ja"
|
||||
|
||||
rss = RSS::Maker.make("2.0") do |maker|
|
||||
# maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
maker.channel.description = description
|
||||
maker.channel.language = language
|
||||
assert_not_set_error("maker.channel", %w(title)) do
|
||||
RSS::Maker.make("2.0") do |maker|
|
||||
# maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
maker.channel.description = description
|
||||
maker.channel.language = language
|
||||
end
|
||||
end
|
||||
assert_nil(rss)
|
||||
|
||||
rss = RSS::Maker.make("2.0") do |maker|
|
||||
maker.channel.title = title
|
||||
# maker.channel.link = link
|
||||
maker.channel.description = description
|
||||
maker.channel.language = language
|
||||
assert_not_set_error("maker.channel", %w(link)) do
|
||||
RSS::Maker.make("2.0") do |maker|
|
||||
maker.channel.title = title
|
||||
# maker.channel.link = link
|
||||
maker.channel.description = description
|
||||
maker.channel.language = language
|
||||
end
|
||||
end
|
||||
assert_nil(rss)
|
||||
|
||||
rss = RSS::Maker.make("2.0") do |maker|
|
||||
maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
# maker.channel.description = description
|
||||
maker.channel.language = language
|
||||
assert_not_set_error("maker.channel", %w(description)) do
|
||||
RSS::Maker.make("2.0") do |maker|
|
||||
maker.channel.title = title
|
||||
maker.channel.link = link
|
||||
# maker.channel.description = description
|
||||
maker.channel.language = language
|
||||
end
|
||||
end
|
||||
assert_nil(rss)
|
||||
|
||||
rss = RSS::Maker.make("2.0") do |maker|
|
||||
maker.channel.title = title
|
||||
|
@ -255,17 +288,18 @@ module RSS
|
|||
assert_equal(height, image.height)
|
||||
assert_equal(description, image.description)
|
||||
|
||||
rss = RSS::Maker.make("2.0") do |maker|
|
||||
# setup_dummy_channel(maker)
|
||||
maker.channel.link = link
|
||||
assert_not_set_error("maker.channel", %w(title description)) do
|
||||
RSS::Maker.make("2.0") do |maker|
|
||||
# setup_dummy_channel(maker)
|
||||
maker.channel.link = link
|
||||
|
||||
maker.image.title = title
|
||||
maker.image.url = url
|
||||
maker.image.width = width
|
||||
maker.image.height = height
|
||||
maker.image.description = description
|
||||
maker.image.title = title
|
||||
maker.image.url = url
|
||||
maker.image.width = width
|
||||
maker.image.height = height
|
||||
maker.image.description = description
|
||||
end
|
||||
end
|
||||
assert_nil(rss)
|
||||
end
|
||||
|
||||
def test_not_valid_image
|
||||
|
@ -288,18 +322,19 @@ module RSS
|
|||
end
|
||||
assert_nil(rss.image)
|
||||
|
||||
rss = RSS::Maker.make("2.0") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
# maker.channel.link = link
|
||||
maker.channel.link = nil
|
||||
assert_not_set_error("maker.channel", %w(link)) do
|
||||
RSS::Maker.make("2.0") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
# maker.channel.link = link
|
||||
maker.channel.link = nil
|
||||
|
||||
maker.image.title = title
|
||||
maker.image.url = url
|
||||
maker.image.width = width
|
||||
maker.image.height = height
|
||||
maker.image.description = description
|
||||
maker.image.title = title
|
||||
maker.image.url = url
|
||||
maker.image.width = width
|
||||
maker.image.height = height
|
||||
maker.image.description = description
|
||||
end
|
||||
end
|
||||
assert_nil(rss)
|
||||
|
||||
rss = RSS::Maker.make("2.0") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
|
@ -519,11 +554,11 @@ module RSS
|
|||
setup_dummy_channel(maker)
|
||||
setup_dummy_item(maker)
|
||||
|
||||
category = maker.items.last.category
|
||||
category = maker.items.last.categories.new_category
|
||||
category.domain = domain
|
||||
category.content = content
|
||||
end
|
||||
category = rss.channel.items.last.category
|
||||
category = rss.channel.items.last.categories.last
|
||||
assert_equal(domain, category.domain)
|
||||
assert_equal(content, category.content)
|
||||
end
|
||||
|
@ -535,10 +570,10 @@ module RSS
|
|||
setup_dummy_channel(maker)
|
||||
setup_dummy_item(maker)
|
||||
|
||||
category = maker.items.last.category
|
||||
category = maker.items.last.categories.new_category
|
||||
# category.content = content
|
||||
end
|
||||
assert_nil(rss.channel.items.last.category)
|
||||
assert(rss.channel.items.last.categories.empty?)
|
||||
end
|
||||
|
||||
def test_textInput
|
||||
|
|
|
@ -14,7 +14,7 @@ module RSS
|
|||
end
|
||||
|
||||
def test_rss10
|
||||
rss = RSS::Maker.make("1.0", ["content"]) do |maker|
|
||||
rss = RSS::Maker.make("1.0") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
|
||||
setup_dummy_item(maker)
|
||||
|
|
|
@ -34,7 +34,7 @@ module RSS
|
|||
end
|
||||
|
||||
def test_rss10
|
||||
rss = RSS::Maker.make("1.0", ["dublincore"]) do |maker|
|
||||
rss = RSS::Maker.make("1.0") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
set_elements(maker.channel)
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ module RSS
|
|||
end
|
||||
|
||||
def test_rss10
|
||||
rss = RSS::Maker.make("1.0", ["syndication"]) do |maker|
|
||||
rss = RSS::Maker.make("1.0") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
set_elements(maker.channel)
|
||||
end
|
||||
|
|
|
@ -10,18 +10,23 @@ module RSS
|
|||
|
||||
@elements = {
|
||||
:ping => "http://bar.com/tb.cgi?tb_id=rssplustrackback",
|
||||
:about => "http://foo.com/trackback/tb.cgi?tb_id=20020923",
|
||||
:abouts => [
|
||||
"http://foo.com/trackback/tb.cgi?tb_id=20020923",
|
||||
"http://bar.com/trackback/tb.cgi?tb_id=20041114",
|
||||
],
|
||||
}
|
||||
end
|
||||
|
||||
def test_rss10
|
||||
rss = RSS::Maker.make("1.0", ["trackback"]) do |maker|
|
||||
rss = RSS::Maker.make("1.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)
|
||||
item.trackback_ping = @elements[:ping]
|
||||
@elements[:abouts].each do |about|
|
||||
new_about = item.trackback_abouts.new_about
|
||||
new_about.value = about
|
||||
end
|
||||
end
|
||||
assert_trackback(@elements, rss.items.last)
|
||||
|
|
|
@ -116,7 +116,7 @@ EOR
|
|||
|
||||
def test_channel
|
||||
|
||||
assert_parse(make_RDF(<<-EOR), :missing_attribute, "channel", "about")
|
||||
assert_parse(make_RDF(<<-EOR), :missing_attribute, "channel", "rdf:about")
|
||||
<channel />
|
||||
EOR
|
||||
|
||||
|
@ -145,7 +145,7 @@ EOR
|
|||
</channel>
|
||||
EOR
|
||||
|
||||
assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "resource")
|
||||
assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "rdf:resource")
|
||||
<channel rdf:about="http://example.com/">
|
||||
<title>hoge</title>
|
||||
<link>http://example.com/</link>
|
||||
|
@ -194,7 +194,7 @@ EOR
|
|||
</channel>
|
||||
EOR
|
||||
|
||||
assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "resource")
|
||||
assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "rdf:resource")
|
||||
<channel rdf:about="http://example.com/">
|
||||
<title>hoge</title>
|
||||
<link>http://example.com/</link>
|
||||
|
@ -257,7 +257,7 @@ EOR
|
|||
|
||||
def test_image
|
||||
|
||||
assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "about")
|
||||
assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "rdf:about")
|
||||
#{make_channel}
|
||||
<image>
|
||||
</image>
|
||||
|
@ -314,7 +314,7 @@ EOR
|
|||
|
||||
def test_item
|
||||
|
||||
assert_parse(make_RDF(<<-EOR), :missing_attribute, "item", "about")
|
||||
assert_parse(make_RDF(<<-EOR), :missing_attribute, "item", "rdf:about")
|
||||
#{make_channel}
|
||||
#{make_image}
|
||||
<item>
|
||||
|
@ -371,7 +371,7 @@ EOR
|
|||
|
||||
def test_textinput
|
||||
|
||||
assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "about")
|
||||
assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "rdf:about")
|
||||
#{make_channel}
|
||||
#{make_image}
|
||||
#{make_item}
|
||||
|
|
|
@ -88,19 +88,19 @@ EOR
|
|||
@elems.each do |name, value|
|
||||
@parents.each do |parent|
|
||||
accessor = "#{RSS::TRACKBACK_PREFIX}_#{name}"
|
||||
target_accessor = "resource"
|
||||
target = @rss.send(parent).send(accessor)
|
||||
target = @rss.send(parent)
|
||||
target20 = @rss20.channel.send(parent, -1)
|
||||
assert_equal(value, target.send(target_accessor))
|
||||
assert_equal(value, target.send(accessor))
|
||||
assert_equal(value, target20.send(accessor))
|
||||
target.send("#{target_accessor}=", new_value[name].to_s)
|
||||
if name == :about
|
||||
# abount is zero or more
|
||||
target.send("#{accessor}=", 0, new_value[name].to_s)
|
||||
target20.send("#{accessor}=", 0, new_value[name].to_s)
|
||||
else
|
||||
target.send("#{accessor}=", new_value[name].to_s)
|
||||
target20.send("#{accessor}=", new_value[name].to_s)
|
||||
end
|
||||
assert_equal(new_value[name], target.send(target_accessor))
|
||||
assert_equal(new_value[name], target.send(accessor))
|
||||
assert_equal(new_value[name], target20.send(accessor))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ module RSS
|
|||
{:media => "print", :title => "FOO"},
|
||||
{:charset => "UTF-8", :alternate => "yes"},
|
||||
].each do |attrs|
|
||||
assert_xml_stylesheet_attrs(XMLStyleSheet.new(*attrs), attrs)
|
||||
assert_xml_stylesheet_attrs(attrs, XMLStyleSheet.new(*attrs))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -36,7 +36,7 @@ module RSS
|
|||
:alternate => "yes"},
|
||||
].each do |attrs|
|
||||
target, contents = parse_pi(XMLStyleSheet.new(*attrs).to_s)
|
||||
assert_xml_stylesheet(target, XMLStyleSheet.new(*contents), attrs)
|
||||
assert_xml_stylesheet(target, attrs, XMLStyleSheet.new(*contents))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -88,7 +88,7 @@ module RSS
|
|||
assert_equal(have_href_xsss.size, rss.xml_stylesheets.size)
|
||||
rss.xml_stylesheets.each_with_index do |stylesheet, i|
|
||||
target, = parse_pi(stylesheet.to_s)
|
||||
assert_xml_stylesheet(target, stylesheet, have_href_xsss[i])
|
||||
assert_xml_stylesheet(target, have_href_xsss[i], stylesheet)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue