summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--lib/rss/0.9.rb906
-rw-r--r--lib/rss/1.0.rb1144
-rw-r--r--lib/rss/2.0.rb260
-rw-r--r--lib/rss/content.rb92
-rw-r--r--lib/rss/converter.rb286
-rw-r--r--lib/rss/dublincore.rb94
-rw-r--r--lib/rss/parser.rb774
-rw-r--r--lib/rss/rexmlparser.rb74
-rw-r--r--lib/rss/rss.rb1274
-rw-r--r--lib/rss/syndication.rb134
-rw-r--r--lib/rss/taxonomy.rb44
-rw-r--r--lib/rss/trackback.rb598
-rw-r--r--lib/rss/utils.rb22
-rw-r--r--lib/rss/xml-stylesheet.rb158
-rw-r--r--lib/rss/xmlparser.rb132
-rw-r--r--lib/rss/xmlscanner.rb100
-rw-r--r--test/rss/rss-assertions.rb266
-rw-r--r--test/rss/rss-testcase.rb232
-rw-r--r--test/rss/test_1.0.rb516
-rw-r--r--test/rss/test_accessor.rb34
-rw-r--r--test/rss/test_content.rb142
-rw-r--r--test/rss/test_dublincore.rb192
-rw-r--r--test/rss/test_parser.rb458
-rw-r--r--test/rss/test_syndication.rb204
-rw-r--r--test/rss/test_trackback.rb204
-rw-r--r--test/rss/test_xml-stylesheet.rb198
27 files changed, 4275 insertions, 4269 deletions
diff --git a/ChangeLog b/ChangeLog
index 1b55edaac5..2ab54aa288 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sat Oct 16 13:42:49 2004 Kouhei Sutou <kou@cozmixng.org>
+
+ * lib/rss/: untabified.
+ * test/rss/: untabified.
+ * lib/rss/0.9.rb (RSS::Rss#to_s): inent -> indent.
+
Sat Oct 16 13:34:56 2004 Kouhei Sutou <kou@cozmixng.org>
* lib/rss: supported prety print.
diff --git a/lib/rss/0.9.rb b/lib/rss/0.9.rb
index 8486c4fc1f..77b65cddec 100644
--- a/lib/rss/0.9.rb
+++ b/lib/rss/0.9.rb
@@ -2,144 +2,144 @@ require "rss/parser"
module RSS
- module RSS09
- NSPOOL = {}
- ELEMENTS = []
-
- def self.append_features(klass)
- super
-
- klass.install_must_call_validator('', nil)
- end
- end
-
- class Rss < Element
-
- include RSS09
- include RootElementMixin
- include XMLStyleSheetMixin
-
- [
- ["channel", nil],
- ].each do |tag, occurs|
- install_model(tag, occurs)
- end
-
- %w(channel).each do |x|
- install_have_child_element(x)
- end
-
- attr_accessor :rss_version, :version, :encoding, :standalone
-
- def initialize(rss_version, version=nil, encoding=nil, standalone=nil)
- super
- end
-
- def items
- if @channel
- @channel.items
- else
- []
- end
- end
-
- def image
- if @channel
- @channel.image
- else
- nil
- end
- end
-
- def to_s(convert=true, indent=calc_indent)
- next_indent = indent + INDENT
- rv = <<-EOR
+ module RSS09
+ NSPOOL = {}
+ ELEMENTS = []
+
+ def self.append_features(klass)
+ super
+
+ klass.install_must_call_validator('', nil)
+ end
+ end
+
+ class Rss < Element
+
+ include RSS09
+ include RootElementMixin
+ include XMLStyleSheetMixin
+
+ [
+ ["channel", nil],
+ ].each do |tag, occurs|
+ install_model(tag, occurs)
+ end
+
+ %w(channel).each do |x|
+ install_have_child_element(x)
+ end
+
+ attr_accessor :rss_version, :version, :encoding, :standalone
+
+ def initialize(rss_version, version=nil, encoding=nil, standalone=nil)
+ super
+ end
+
+ def items
+ if @channel
+ @channel.items
+ else
+ []
+ end
+ end
+
+ def image
+ if @channel
+ @channel.image
+ else
+ nil
+ end
+ 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)}
-#{inent}}</rss>
+#{indent}}</rss>
EOR
- rv = @converter.convert(rv) if convert and @converter
- remove_empty_newline(rv)
- end
-
- private
- def children
- [@channel]
- end
-
- def _tags
- [
- [nil, 'channel'],
- ].delete_if {|x| send(x[1]).nil?}
- end
-
- def _attrs
- [
- ["version", true],
- ]
- end
-
- class Channel < Element
-
- include RSS09
-
- [
- ["title", nil],
- ["link", nil],
- ["description", nil],
- ["language", nil],
- ["copyright", "?"],
- ["managingEditor", "?"],
- ["webMaster", "?"],
- ["rating", "?"],
- ["docs", "?"],
- ["skipDays", "?"],
- ["skipHours", "?"],
- ].each do |x, occurs|
- install_text_element(x)
- install_model(x, occurs)
- end
-
- [
- ["pubDate", "?"],
- ["lastBuildDate", "?"],
- ].each do |x, occurs|
- install_date_element(x, 'rfc822')
- install_model(x, occurs)
- end
-
- [
- ["image", nil],
- ["textInput", "?"],
- ].each do |x, occurs|
- install_have_child_element(x)
- install_model(x, occurs)
- end
-
- [
- ["cloud", "?"]
- ].each do |x, occurs|
- install_have_attribute_element(x)
- install_model(x, occurs)
- end
-
- [
- ["item", "*"]
- ].each do |x, occurs|
- install_have_children_element(x)
- install_model(x, occurs)
- end
-
- def initialize()
- super()
- end
-
- def to_s(convert=true, indent=calc_indent)
- next_indent = indent + INDENT
- rv = <<-EOT
+ rv = @converter.convert(rv) if convert and @converter
+ remove_empty_newline(rv)
+ end
+
+ private
+ def children
+ [@channel]
+ end
+
+ def _tags
+ [
+ [nil, 'channel'],
+ ].delete_if {|x| send(x[1]).nil?}
+ end
+
+ def _attrs
+ [
+ ["version", true],
+ ]
+ end
+
+ class Channel < Element
+
+ include RSS09
+
+ [
+ ["title", nil],
+ ["link", nil],
+ ["description", nil],
+ ["language", nil],
+ ["copyright", "?"],
+ ["managingEditor", "?"],
+ ["webMaster", "?"],
+ ["rating", "?"],
+ ["docs", "?"],
+ ["skipDays", "?"],
+ ["skipHours", "?"],
+ ].each do |x, occurs|
+ install_text_element(x)
+ install_model(x, occurs)
+ end
+
+ [
+ ["pubDate", "?"],
+ ["lastBuildDate", "?"],
+ ].each do |x, occurs|
+ install_date_element(x, 'rfc822')
+ install_model(x, occurs)
+ end
+
+ [
+ ["image", nil],
+ ["textInput", "?"],
+ ].each do |x, occurs|
+ install_have_child_element(x)
+ install_model(x, occurs)
+ end
+
+ [
+ ["cloud", "?"]
+ ].each do |x, occurs|
+ install_have_attribute_element(x)
+ install_model(x, occurs)
+ end
+
+ [
+ ["item", "*"]
+ ].each do |x, occurs|
+ install_have_children_element(x)
+ install_model(x, occurs)
+ end
+
+ def initialize()
+ super()
+ 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)}
@@ -160,60 +160,60 @@ EOR
#{other_element(false, next_indent)}
#{indent}</channel>
EOT
- rv = @converter.convert(rv) if convert and @converter
- rv
- end
-
- private
- def children
- [@image, @textInput, @cloud, *@item]
- end
-
- def _tags
- rv = [
- "title",
- "link",
- "description",
- "language",
- "copyright",
- "managingEditor",
- "webMaster",
- "rating",
- "docs",
- "skipDays",
- "skipHours",
- "image",
- "textInput",
- "cloud",
- ].delete_if do |x|
- send(x).nil?
- end.collect do |elem|
- [nil, elem]
- end
-
- @item.each do
- rv << [nil, "item"]
- end
-
- rv
- end
-
- class Image < Element
-
- include RSS09
-
- %w(url title link).each do |x|
- install_text_element(x)
- install_model(x, nil)
- end
- %w(width height description).each do |x|
- install_text_element(x)
- install_model(x, "?")
- end
-
- def to_s(convert=true, indent=calc_indent)
- next_indent = indent + INDENT
- rv = <<-EOT
+ rv = @converter.convert(rv) if convert and @converter
+ rv
+ end
+
+ private
+ def children
+ [@image, @textInput, @cloud, *@item]
+ end
+
+ def _tags
+ rv = [
+ "title",
+ "link",
+ "description",
+ "language",
+ "copyright",
+ "managingEditor",
+ "webMaster",
+ "rating",
+ "docs",
+ "skipDays",
+ "skipHours",
+ "image",
+ "textInput",
+ "cloud",
+ ].delete_if do |x|
+ send(x).nil?
+ end.collect do |elem|
+ [nil, elem]
+ end
+
+ @item.each do
+ rv << [nil, "item"]
+ end
+
+ rv
+ end
+
+ class Image < Element
+
+ include RSS09
+
+ %w(url title link).each do |x|
+ install_text_element(x)
+ install_model(x, nil)
+ end
+ %w(width height description).each do |x|
+ install_text_element(x)
+ install_model(x, "?")
+ 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)}
@@ -224,46 +224,46 @@ EOT
#{other_element(false, next_indent)}
#{indent}</image>
EOT
- rv = @converter.convert(rv) if convert and @converter
- rv
- end
-
- private
- def _tags
- %w(url title link width height description).delete_if do |x|
- send(x).nil?
- end.collect do |elem|
- [nil, elem]
- end
- end
- end
-
- class Cloud < Element
-
- include RSS09
-
- [
- ["domain", nil, true],
- ["port", nil, true],
- ["path", nil, true],
- ["registerProcedure", nil, true],
- ["protocol", nil ,true],
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- def initialize(domain, port, path, rp, protocol)
- super()
- @domain = domain
- @port = port
- @path = path
- @registerProcedure = rp
- @protocol = protocol
- end
-
- def to_s(convert=true, indent=calc_indent)
- next_indent = indent + INDENT
- rv = <<-EOT
+ rv = @converter.convert(rv) if convert and @converter
+ rv
+ end
+
+ private
+ def _tags
+ %w(url title link width height description).delete_if do |x|
+ send(x).nil?
+ end.collect do |elem|
+ [nil, elem]
+ end
+ end
+ end
+
+ class Cloud < Element
+
+ include RSS09
+
+ [
+ ["domain", nil, true],
+ ["port", nil, true],
+ ["path", nil, true],
+ ["registerProcedure", nil, true],
+ ["protocol", nil ,true],
+ ].each do |name, uri, required|
+ install_get_attribute(name, uri, required)
+ end
+
+ def initialize(domain, port, path, rp, protocol)
+ super()
+ @domain = domain
+ @port = port
+ @path = path
+ @registerProcedure = rp
+ @protocol = protocol
+ 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}"
@@ -271,45 +271,45 @@ EOT
#{next_indent}registerProcedure="#{h @registerProcedure}"
#{next_indent}protocol="#{h @protocol}"/>
EOT
- rv = @converter.convert(rv) if convert and @converter
- rv
- end
-
- private
- def _attrs
- %w(domain port path registerProcedure protocol).collect do |attr|
- [attr, true]
- end
- end
-
- end
-
- class Item < Element
-
- include RSS09
-
- %w(title link description).each do |x|
- install_text_element(x)
- end
-
- %w(category source enclosure).each do |x|
- install_have_child_element(x)
- end
-
- [
- ["title", '?'],
- ["link", '?'],
- ["description", '?'],
- ["category", '?'],
- ["source", '?'],
- ["enclosure", '?'],
- ].each do |tag, occurs|
- install_model(tag, occurs)
- end
-
- def to_s(convert=true, indent=calc_indent)
+ rv = @converter.convert(rv) if convert and @converter
+ rv
+ end
+
+ private
+ def _attrs
+ %w(domain port path registerProcedure protocol).collect do |attr|
+ [attr, true]
+ end
+ end
+
+ end
+
+ class Item < Element
+
+ include RSS09
+
+ %w(title link description).each do |x|
+ install_text_element(x)
+ end
+
+ %w(category source enclosure).each do |x|
+ install_have_child_element(x)
+ end
+
+ [
+ ["title", '?'],
+ ["link", '?'],
+ ["description", '?'],
+ ["category", '?'],
+ ["source", '?'],
+ ["enclosure", '?'],
+ ].each do |tag, occurs|
+ install_model(tag, occurs)
+ end
+
+ def to_s(convert=true, indent=calc_indent)
next_indent = indent + INDENT
- rv = <<-EOT
+ rv = <<-EOT
#{indent}<item>
#{title_element(false, next_indent)}
#{link_element(false, next_indent)}
@@ -320,159 +320,159 @@ EOT
#{other_element(false, next_indent)}
#{indent}</item>
EOT
- rv = @converter.convert(rv) if convert and @converter
- rv
- end
-
- private
- def children
- [@category, @source, @enclosure,].compact
- end
-
- def _tags
- %w(title link description author comments category
- source enclosure).delete_if do |x|
- send(x).nil?
- end.collect do |x|
- [nil, x]
- end
- end
-
- class Source < Element
-
- include RSS09
-
- [
- ["url", nil, true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- content_setup
-
- def initialize(url=nil, content=nil)
- super()
- @url = url
- @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
- []
- end
-
- def _attrs
- [
- ["url", true]
- ]
- end
-
- end
-
- class Enclosure < Element
-
- include RSS09
-
- [
- ["url", nil, true],
- ["length", nil, true],
- ["type", nil, true],
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- def initialize(url=nil, length=nil, type=nil)
- super()
- @url = url
- @length = length
- @type = type
- 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
- end
-
- private
- def _attrs
- [
- ["url", true],
- ["length", true],
- ["type", true],
- ]
- end
-
- end
-
- class Category < Element
-
- include RSS09
-
- [
- ["domain", nil, true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- content_setup
-
- def initialize(domain=nil, content=nil)
- super()
- @domain = domain
- @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
- [
- ["domain", true]
- ]
- end
-
- end
-
- end
-
- class TextInput < Element
-
- include RSS09
-
- %w(title description name link).each do |x|
- install_text_element(x)
- install_model(x, nil)
- end
-
- def to_s(convert=true, indent=calc_indent)
+ rv = @converter.convert(rv) if convert and @converter
+ rv
+ end
+
+ private
+ def children
+ [@category, @source, @enclosure,].compact
+ end
+
+ def _tags
+ %w(title link description author comments category
+ source enclosure).delete_if do |x|
+ send(x).nil?
+ end.collect do |x|
+ [nil, x]
+ end
+ end
+
+ class Source < Element
+
+ include RSS09
+
+ [
+ ["url", nil, true]
+ ].each do |name, uri, required|
+ install_get_attribute(name, uri, required)
+ end
+
+ content_setup
+
+ def initialize(url=nil, content=nil)
+ super()
+ @url = url
+ @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
+ []
+ end
+
+ def _attrs
+ [
+ ["url", true]
+ ]
+ end
+
+ end
+
+ class Enclosure < Element
+
+ include RSS09
+
+ [
+ ["url", nil, true],
+ ["length", nil, true],
+ ["type", nil, true],
+ ].each do |name, uri, required|
+ install_get_attribute(name, uri, required)
+ end
+
+ def initialize(url=nil, length=nil, type=nil)
+ super()
+ @url = url
+ @length = length
+ @type = type
+ 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
+ end
+
+ private
+ def _attrs
+ [
+ ["url", true],
+ ["length", true],
+ ["type", true],
+ ]
+ end
+
+ end
+
+ class Category < Element
+
+ include RSS09
+
+ [
+ ["domain", nil, true]
+ ].each do |name, uri, required|
+ install_get_attribute(name, uri, required)
+ end
+
+ content_setup
+
+ def initialize(domain=nil, content=nil)
+ super()
+ @domain = domain
+ @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
+ [
+ ["domain", true]
+ ]
+ end
+
+ end
+
+ end
+
+ class TextInput < Element
+
+ include RSS09
+
+ %w(title description name link).each do |x|
+ install_text_element(x)
+ install_model(x, nil)
+ end
+
+ def to_s(convert=true, indent=calc_indent)
next_indent = indent + INDENT
- rv = <<-EOT
+ rv = <<-EOT
#{indent}<textInput>
#{title_element(false, next_indent)}
#{description_element(false, next_indent)}
@@ -481,42 +481,42 @@ EOT
#{other_element(false, next_indent)}
#{indent}</textInput>
EOT
- rv = @converter.convert(rv) if convert and @converter
- rv
- end
-
- private
- def _tags
- %w(title description name link).each do |x|
- send(x).nil?
- end.collect do |elem|
- [nil, elem]
- end
- end
- end
-
- end
-
- end
-
- RSS09::ELEMENTS.each do |x|
- BaseListener.install_get_text_element(x, nil, "#{x}=")
- end
-
- module ListenerMixin
- private
- def start_rss(tag_name, prefix, attrs, ns)
- check_ns(tag_name, prefix, ns, nil)
-
- @rss = Rss.new(attrs['version'], @version, @encoding, @standalone)
- @rss.do_validate = @do_validate
- @rss.xml_stylesheets = @xml_stylesheets
- @last_element = @rss
- @proc_stack.push Proc.new { |text, tags|
- @rss.validate_for_stream(tags) if @do_validate
- }
- end
-
- end
+ rv = @converter.convert(rv) if convert and @converter
+ rv
+ end
+
+ private
+ def _tags
+ %w(title description name link).each do |x|
+ send(x).nil?
+ end.collect do |elem|
+ [nil, elem]
+ end
+ end
+ end
+
+ end
+
+ end
+
+ RSS09::ELEMENTS.each do |x|
+ BaseListener.install_get_text_element(x, nil, "#{x}=")
+ end
+
+ module ListenerMixin
+ private
+ def start_rss(tag_name, prefix, attrs, ns)
+ check_ns(tag_name, prefix, ns, nil)
+
+ @rss = Rss.new(attrs['version'], @version, @encoding, @standalone)
+ @rss.do_validate = @do_validate
+ @rss.xml_stylesheets = @xml_stylesheets
+ @last_element = @rss
+ @proc_stack.push Proc.new { |text, tags|
+ @rss.validate_for_stream(tags) if @do_validate
+ }
+ end
+
+ end
end
diff --git a/lib/rss/1.0.rb b/lib/rss/1.0.rb
index 999301c595..563ed66426 100644
--- a/lib/rss/1.0.rb
+++ b/lib/rss/1.0.rb
@@ -2,64 +2,64 @@ require "rss/parser"
module RSS
- module RSS10
- NSPOOL = {}
- ELEMENTS = []
+ module RSS10
+ NSPOOL = {}
+ ELEMENTS = []
- def self.append_features(klass)
- super
-
- klass.install_must_call_validator('', ::RSS::URI)
- end
+ def self.append_features(klass)
+ super
+
+ klass.install_must_call_validator('', ::RSS::URI)
+ end
- end
+ end
- class RDF < Element
+ class RDF < Element
- include RSS10
- include RootElementMixin
- include XMLStyleSheetMixin
+ include RSS10
+ include RootElementMixin
+ include XMLStyleSheetMixin
- class << self
+ class << self
- def required_uri
- URI
- end
+ def required_uri
+ URI
+ end
- end
+ end
- @tag_name = 'RDF'
+ @tag_name = 'RDF'
- PREFIX = 'rdf'
- URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ PREFIX = 'rdf'
+ URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- install_ns('', ::RSS::URI)
- install_ns(PREFIX, URI)
+ install_ns('', ::RSS::URI)
+ install_ns(PREFIX, URI)
- [
- ["channel", nil],
- ["image", "?"],
- ["item", "+"],
- ["textinput", "?"],
- ].each do |tag, occurs|
- install_model(tag, occurs)
- end
+ [
+ ["channel", nil],
+ ["image", "?"],
+ ["item", "+"],
+ ["textinput", "?"],
+ ].each do |tag, occurs|
+ install_model(tag, occurs)
+ end
- %w(channel image textinput).each do |x|
- install_have_child_element(x)
- end
+ %w(channel image textinput).each do |x|
+ install_have_child_element(x)
+ end
- install_have_children_element("item")
+ install_have_children_element("item")
- attr_accessor :rss_version, :version, :encoding, :standalone
-
- def initialize(version=nil, encoding=nil, standalone=nil)
- super('1.0', version, encoding, standalone)
- end
+ attr_accessor :rss_version, :version, :encoding, :standalone
+
+ def initialize(version=nil, encoding=nil, standalone=nil)
+ super('1.0', version, encoding, standalone)
+ end
- def to_s(convert=true, indent=calc_indent)
- next_indent = indent + INDENT
- rv = <<-EORDF
+ 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)}>
@@ -72,170 +72,170 @@ module RSS
EORDF
rv = @converter.convert(rv) if convert and @converter
remove_empty_newline(rv)
- end
-
- private
- def rdf_validate(tags)
- _validate(tags, [])
- end
-
- def children
- [@channel, @image, @textinput, *@item]
- end
-
- def _tags
- rv = [
- [::RSS::URI, "channel"],
- [::RSS::URI, "image"],
- ].delete_if {|x| send(x[1]).nil?}
- @item.each do |x|
- rv << [::RSS::URI, "item"]
- end
- rv << [::RSS::URI, "textinput"] if @textinput
- rv
- end
-
- class Seq < Element
-
- include RSS10
-
- class << self
-
- def required_uri
- URI
- end
-
- end
-
- @tag_name = 'Seq'
-
- install_have_children_element("li")
-
- install_must_call_validator('rdf', ::RSS::RDF::URI)
-
- def initialize(li=[])
- super()
- @li = li
- end
-
- def to_s(convert=true, indent=calc_indent)
- next_indent = indent + INDENT
- <<-EOT
+ end
+
+ private
+ def rdf_validate(tags)
+ _validate(tags, [])
+ end
+
+ def children
+ [@channel, @image, @textinput, *@item]
+ end
+
+ def _tags
+ rv = [
+ [::RSS::URI, "channel"],
+ [::RSS::URI, "image"],
+ ].delete_if {|x| send(x[1]).nil?}
+ @item.each do |x|
+ rv << [::RSS::URI, "item"]
+ end
+ rv << [::RSS::URI, "textinput"] if @textinput
+ rv
+ end
+
+ class Seq < Element
+
+ include RSS10
+
+ class << self
+
+ def required_uri
+ URI
+ end
+
+ end
+
+ @tag_name = 'Seq'
+
+ install_have_children_element("li")
+
+ install_must_call_validator('rdf', ::RSS::RDF::URI)
+
+ def initialize(li=[])
+ super()
+ @li = li
+ 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
- end
+ end
private
- def children
- @li
- end
-
- def rdf_validate(tags)
- _validate(tags, [["li", '*']])
- end
-
- def _tags
- rv = []
- @li.each do |x|
- rv << [URI, "li"]
- end
- rv
- end
-
- end
-
- class Li < Element
-
- include RSS10
-
- class << self
-
- def required_uri
- URI
- end
-
- end
-
- [
- ["resource", [URI, nil], 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}<#{PREFIX}:li resource="#{h @resource}" />\n!
- rv = @converter.convert(rv) if convert and @converter
- rv
- else
- ''
- end
- end
-
- private
- def _attrs
- [
- ["resource", true]
- ]
- end
-
- end
-
- class Channel < Element
-
- include RSS10
-
- class << self
-
- def required_uri
- ::RSS::URI
- end
-
- end
+ def children
+ @li
+ end
+
+ def rdf_validate(tags)
+ _validate(tags, [["li", '*']])
+ end
+
+ def _tags
+ rv = []
+ @li.each do |x|
+ rv << [URI, "li"]
+ end
+ rv
+ end
+
+ end
+
+ class Li < Element
+
+ include RSS10
+
+ class << self
+
+ def required_uri
+ URI
+ end
+
+ end
+
+ [
+ ["resource", [URI, nil], 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}<#{PREFIX}:li resource="#{h @resource}" />\n!
+ rv = @converter.convert(rv) if convert and @converter
+ rv
+ else
+ ''
+ end
+ end
+
+ private
+ def _attrs
+ [
+ ["resource", true]
+ ]
+ end
+
+ end
+
+ class Channel < Element
+
+ include RSS10
+
+ class << self
+
+ def required_uri
+ ::RSS::URI
+ end
+
+ end
[
- ["about", URI, true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- %w(title link description).each do |x|
- install_text_element(x)
- end
-
- %w(image items textinput).each do |x|
- install_have_child_element(x)
- end
-
- [
- ['title', nil],
- ['link', nil],
- ['description', nil],
- ['image', '?'],
- ['items', nil],
- ['textinput', '?'],
- ].each do |tag, occurs|
- install_model(tag, occurs)
- end
-
- def initialize(about=nil)
- super()
- @about = about
- end
-
- def to_s(convert=true, indent=calc_indent)
- next_indent = indent + INDENT
- about = ''
- about << %Q!#{PREFIX}:about="#{h @about}"! if @about
- rv = <<-EOT
+ ["about", URI, true]
+ ].each do |name, uri, required|
+ install_get_attribute(name, uri, required)
+ end
+
+ %w(title link description).each do |x|
+ install_text_element(x)
+ end
+
+ %w(image items textinput).each do |x|
+ install_have_child_element(x)
+ end
+
+ [
+ ['title', nil],
+ ['link', nil],
+ ['description', nil],
+ ['image', '?'],
+ ['items', nil],
+ ['textinput', '?'],
+ ].each do |tag, occurs|
+ install_model(tag, occurs)
+ end
+
+ def initialize(about=nil)
+ super()
+ @about = about
+ 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)}
@@ -246,216 +246,216 @@ EOT
#{other_element(false, next_indent)}
#{indent}</channel>
EOT
- rv = @converter.convert(rv) if convert and @converter
+ rv = @converter.convert(rv) if convert and @converter
rv
- end
-
- private
- def children
- [@image, @items, @textinput]
- end
-
- def _tags
- [
- [::RSS::URI, 'title'],
- [::RSS::URI, 'link'],
- [::RSS::URI, 'description'],
- [::RSS::URI, 'image'],
- [::RSS::URI, 'items'],
- [::RSS::URI, 'textinput'],
- ].delete_if do |x|
- send(x[1]).nil?
- end
- end
-
- def _attrs
- [
- ["about", true]
- ]
- end
-
- class Image < Element
-
- include RSS10
-
- class << self
-
- def required_uri
- ::RSS::URI
- end
-
- end
-
- [
- ["resource", 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}<image #{PREFIX}:resource="#{h @resource}" />!
- rv = @converter.convert(rv) if convert and @converter
- rv
- else
- ''
- end
- end
-
- private
- def _attrs
- [
- ["resource", true]
- ]
- end
-
- end
-
- class Textinput < Element
-
- include RSS10
-
- class << self
-
- def required_uri
- ::RSS::URI
- end
-
- end
-
- [
- ["resource", 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}<textinput #{PREFIX}:resource="#{h @resource}" />|
- rv = @converter.convert(rv) if convert and @converter
- rv
- else
- ''
- end
- end
-
- private
- def _attrs
- [
- ["resource", true],
- ]
- end
-
- end
-
- class Items < Element
-
- include RSS10
-
- Seq = ::RSS::RDF::Seq
- class Seq
- unless const_defined?(:Li)
- Li = ::RSS::RDF::Li
- end
- end
-
- class << self
-
- def required_uri
- ::RSS::URI
- end
-
- end
-
- install_have_child_element("Seq")
-
- install_must_call_validator('rdf', ::RSS::RDF::URI)
-
- def initialize(seq=Seq.new)
- super()
- @Seq = seq
- end
-
- def to_s(convert=true, indent=calc_indent)
- next_indent = indent + INDENT
- <<-EOT
+ end
+
+ private
+ def children
+ [@image, @items, @textinput]
+ end
+
+ def _tags
+ [
+ [::RSS::URI, 'title'],
+ [::RSS::URI, 'link'],
+ [::RSS::URI, 'description'],
+ [::RSS::URI, 'image'],
+ [::RSS::URI, 'items'],
+ [::RSS::URI, 'textinput'],
+ ].delete_if do |x|
+ send(x[1]).nil?
+ end
+ end
+
+ def _attrs
+ [
+ ["about", true]
+ ]
+ end
+
+ class Image < Element
+
+ include RSS10
+
+ class << self
+
+ def required_uri
+ ::RSS::URI
+ end
+
+ end
+
+ [
+ ["resource", 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}<image #{PREFIX}:resource="#{h @resource}" />!
+ rv = @converter.convert(rv) if convert and @converter
+ rv
+ else
+ ''
+ end
+ end
+
+ private
+ def _attrs
+ [
+ ["resource", true]
+ ]
+ end
+
+ end
+
+ class Textinput < Element
+
+ include RSS10
+
+ class << self
+
+ def required_uri
+ ::RSS::URI
+ end
+
+ end
+
+ [
+ ["resource", 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}<textinput #{PREFIX}:resource="#{h @resource}" />|
+ rv = @converter.convert(rv) if convert and @converter
+ rv
+ else
+ ''
+ end
+ end
+
+ private
+ def _attrs
+ [
+ ["resource", true],
+ ]
+ end
+
+ end
+
+ class Items < Element
+
+ include RSS10
+
+ Seq = ::RSS::RDF::Seq
+ class Seq
+ unless const_defined?(:Li)
+ Li = ::RSS::RDF::Li
+ end
+ end
+
+ class << self
+
+ def required_uri
+ ::RSS::URI
+ end
+
+ end
+
+ install_have_child_element("Seq")
+
+ install_must_call_validator('rdf', ::RSS::RDF::URI)
+
+ def initialize(seq=Seq.new)
+ super()
+ @Seq = seq
+ 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
- end
-
- private
- def children
- [@Seq]
- end
-
- private
- def _tags
- rv = []
- rv << [URI, 'Seq'] unless @Seq.nil?
- rv
- end
-
- def rdf_validate(tags)
- _validate(tags, [["Seq", nil]])
- end
-
- end
-
- end
-
- class Image < Element
-
- include RSS10
-
- class << self
-
- def required_uri
- ::RSS::URI
- end
-
- end
-
- [
- ["about", URI, true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- %w(title url link).each do |x|
- install_text_element(x)
- end
-
- [
- ['title', nil],
- ['url', nil],
- ['link', nil],
- ].each do |tag, occurs|
- install_model(tag, occurs)
- end
-
- def initialize(about=nil)
- super()
- @about = about
- end
-
- def to_s(convert=true, indent=calc_indent)
- next_indent = indent + INDENT
- about = ''
- about << %Q!#{PREFIX}:about="#{h @about}"! if @about
- rv = <<-EOT
+ end
+
+ private
+ def children
+ [@Seq]
+ end
+
+ private
+ def _tags
+ rv = []
+ rv << [URI, 'Seq'] unless @Seq.nil?
+ rv
+ end
+
+ def rdf_validate(tags)
+ _validate(tags, [["Seq", nil]])
+ end
+
+ end
+
+ end
+
+ class Image < Element
+
+ include RSS10
+
+ class << self
+
+ def required_uri
+ ::RSS::URI
+ end
+
+ end
+
+ [
+ ["about", URI, true]
+ ].each do |name, uri, required|
+ install_get_attribute(name, uri, required)
+ end
+
+ %w(title url link).each do |x|
+ install_text_element(x)
+ end
+
+ [
+ ['title', nil],
+ ['url', nil],
+ ['link', nil],
+ ].each do |tag, occurs|
+ install_model(tag, occurs)
+ end
+
+ def initialize(about=nil)
+ super()
+ @about = about
+ 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)}
@@ -463,69 +463,69 @@ EOT
#{other_element(false, next_indent)}
#{indent}</image>
EOT
- rv = @converter.convert(rv) if convert and @converter
- rv
- end
-
- private
- def _tags
- [
- [::RSS::URI, 'title'],
- [::RSS::URI, 'url'],
- [::RSS::URI, 'link'],
- ].delete_if do |x|
- send(x[1]).nil?
- end
- end
-
- def _attrs
- [
- ["about", true],
- ]
- end
-
- end
-
- class Item < Element
-
- include RSS10
-
- class << self
-
- def required_uri
- ::RSS::URI
- end
-
- end
-
- [
- ["about", URI, true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- %w(title link description).each do |x|
- install_text_element(x)
- end
-
- [
- ["title", nil],
- ["link", nil],
- ["description", "?"],
- ].each do |tag, occurs|
- install_model(tag, occurs)
- end
-
- def initialize(about=nil)
- super()
- @about = about
- end
-
- def to_s(convert=true, indent=calc_indent)
- next_indent = indent + INDENT
- about = ''
- about << %Q!#{PREFIX}:about="#{h @about}"! if @about
- rv = <<-EOT
+ rv = @converter.convert(rv) if convert and @converter
+ rv
+ end
+
+ private
+ def _tags
+ [
+ [::RSS::URI, 'title'],
+ [::RSS::URI, 'url'],
+ [::RSS::URI, 'link'],
+ ].delete_if do |x|
+ send(x[1]).nil?
+ end
+ end
+
+ def _attrs
+ [
+ ["about", true],
+ ]
+ end
+
+ end
+
+ class Item < Element
+
+ include RSS10
+
+ class << self
+
+ def required_uri
+ ::RSS::URI
+ end
+
+ end
+
+ [
+ ["about", URI, true]
+ ].each do |name, uri, required|
+ install_get_attribute(name, uri, required)
+ end
+
+ %w(title link description).each do |x|
+ install_text_element(x)
+ end
+
+ [
+ ["title", nil],
+ ["link", nil],
+ ["description", "?"],
+ ].each do |tag, occurs|
+ install_model(tag, occurs)
+ end
+
+ def initialize(about=nil)
+ super()
+ @about = about
+ 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)}
@@ -533,70 +533,70 @@ EOT
#{other_element(false, next_indent)}
#{indent}</item>
EOT
- rv = @converter.convert(rv) if convert and @converter
- rv
- end
+ rv = @converter.convert(rv) if convert and @converter
+ rv
+ end
- private
- def _tags
- [
- [::RSS::URI, 'title'],
- [::RSS::URI, 'link'],
- [::RSS::URI, 'description'],
- ].delete_if do |x|
- send(x[1]).nil?
- end
- end
-
- def _attrs
- [
- ["about", true],
- ]
- end
-
- end
-
- class Textinput < Element
-
- include RSS10
-
- class << self
-
- def required_uri
- ::RSS::URI
- end
-
- end
-
- [
- ["about", URI, true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- %w(title description name link).each do |x|
- install_text_element(x)
- end
-
- [
- ["title", nil],
- ["description", nil],
- ["name", nil],
- ["link", nil],
- ].each do |tag, occurs|
- install_model(tag, occurs)
- end
-
- def initialize(about=nil)
- super()
- @about = about
- end
-
- def to_s(convert=true, indent=calc_indent)
- next_indent = indent + INDENT
- about = ''
- about << %Q!#{PREFIX}:about="#{h @about}"! if @about
- rv = <<-EOT
+ private
+ def _tags
+ [
+ [::RSS::URI, 'title'],
+ [::RSS::URI, 'link'],
+ [::RSS::URI, 'description'],
+ ].delete_if do |x|
+ send(x[1]).nil?
+ end
+ end
+
+ def _attrs
+ [
+ ["about", true],
+ ]
+ end
+
+ end
+
+ class Textinput < Element
+
+ include RSS10
+
+ class << self
+
+ def required_uri
+ ::RSS::URI
+ end
+
+ end
+
+ [
+ ["about", URI, true]
+ ].each do |name, uri, required|
+ install_get_attribute(name, uri, required)
+ end
+
+ %w(title description name link).each do |x|
+ install_text_element(x)
+ end
+
+ [
+ ["title", nil],
+ ["description", nil],
+ ["name", nil],
+ ["link", nil],
+ ].each do |tag, occurs|
+ install_model(tag, occurs)
+ end
+
+ def initialize(about=nil)
+ super()
+ @about = about
+ 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)}
@@ -605,49 +605,49 @@ EOT
#{other_element(false, next_indent)}
#{indent}</textinput>
EOT
- rv = @converter.convert(rv) if convert and @converter
- rv
- end
-
- private
- def _tags
- [
- [::RSS::URI, 'title'],
- [::RSS::URI, 'description'],
- [::RSS::URI, 'name'],
- [::RSS::URI, 'link'],
- ].delete_if do |x|
- send(x[1]).nil?
- end
- end
-
- def _attrs
- [
- ["about", true],
- ]
- end
-
- end
-
- end
-
- RSS10::ELEMENTS.each do |x|
- BaseListener.install_get_text_element(x, URI, "#{x}=")
- end
-
- module ListenerMixin
- private
- def start_RDF(tag_name, prefix, attrs, ns)
- check_ns(tag_name, prefix, ns, RDF::URI)
-
- @rss = RDF.new(@version, @encoding, @standalone)
- @rss.do_validate = @do_validate
- @rss.xml_stylesheets = @xml_stylesheets
- @last_element = @rss
- @proc_stack.push Proc.new { |text, tags|
- @rss.validate_for_stream(tags) if @do_validate
- }
- end
- end
+ rv = @converter.convert(rv) if convert and @converter
+ rv
+ end
+
+ private
+ def _tags
+ [
+ [::RSS::URI, 'title'],
+ [::RSS::URI, 'description'],
+ [::RSS::URI, 'name'],
+ [::RSS::URI, 'link'],
+ ].delete_if do |x|
+ send(x[1]).nil?
+ end
+ end
+
+ def _attrs
+ [
+ ["about", true],
+ ]
+ end
+
+ end
+
+ end
+
+ RSS10::ELEMENTS.each do |x|
+ BaseListener.install_get_text_element(x, URI, "#{x}=")
+ end
+
+ module ListenerMixin
+ private
+ def start_RDF(tag_name, prefix, attrs, ns)
+ check_ns(tag_name, prefix, ns, RDF::URI)
+
+ @rss = RDF.new(@version, @encoding, @standalone)
+ @rss.do_validate = @do_validate
+ @rss.xml_stylesheets = @xml_stylesheets
+ @last_element = @rss
+ @proc_stack.push Proc.new { |text, tags|
+ @rss.validate_for_stream(tags) if @do_validate
+ }
+ end
+ end
end
diff --git a/lib/rss/2.0.rb b/lib/rss/2.0.rb
index c4d055e984..7fafb23ba9 100644
--- a/lib/rss/2.0.rb
+++ b/lib/rss/2.0.rb
@@ -2,149 +2,149 @@ require "rss/0.9"
module RSS
- class Rss
+ class Rss
- class Channel
+ class Channel
- %w(generator ttl).each do |x|
- install_text_element(x)
- install_model(x, '?')
- end
+ %w(generator ttl).each do |x|
+ install_text_element(x)
+ install_model(x, '?')
+ end
- %w(category).each do |x|
- install_have_child_element(x)
- install_model(x, '?')
- end
+ %w(category).each do |x|
+ install_have_child_element(x)
+ install_model(x, '?')
+ end
- [
- ["image", "?"],
- ["language", "?"],
- ].each do |x, occurs|
- install_model(x, occurs)
- end
+ [
+ ["image", "?"],
+ ["language", "?"],
+ ].each do |x, occurs|
+ install_model(x, occurs)
+ end
- def other_element(convert, indent)
- rv = <<-EOT
+ def other_element(convert, indent)
+ rv = <<-EOT
#{category_element(convert, indent)}
#{generator_element(convert, indent)}
#{ttl_element(convert, indent)}
EOT
- rv << super
- end
-
- private
- alias children09 children
- def children
- children09 + [@category].compact
- end
-
- alias _tags09 _tags
- def _tags
- %w(generator ttl category).delete_if do |x|
- send(x).nil?
- end.collect do |elem|
- [nil, elem]
- end + _tags09
- end
-
- Category = Item::Category
-
- class Item
-
- [
- ["comments", "?"],
- ["author", "?"],
- ].each do |x, occurs|
- install_text_element(x)
- install_model(x, occurs)
- end
-
- [
- ["pubDate", '?'],
- ].each do |x, occurs|
- install_date_element(x, 'rfc822')
- install_model(x, occurs)
- end
-
- [
- ["guid", '?'],
- ].each do |x, occurs|
- install_have_child_element(x)
- install_model(x, occurs)
- end
-
- def other_element(convert, indent)
- rv = <<-EOT
+ rv << super
+ end
+
+ private
+ alias children09 children
+ def children
+ children09 + [@category].compact
+ end
+
+ alias _tags09 _tags
+ def _tags
+ %w(generator ttl category).delete_if do |x|
+ send(x).nil?
+ end.collect do |elem|
+ [nil, elem]
+ end + _tags09
+ end
+
+ Category = Item::Category
+
+ class Item
+
+ [
+ ["comments", "?"],
+ ["author", "?"],
+ ].each do |x, occurs|
+ install_text_element(x)
+ install_model(x, occurs)
+ end
+
+ [
+ ["pubDate", '?'],
+ ].each do |x, occurs|
+ install_date_element(x, 'rfc822')
+ install_model(x, occurs)
+ end
+
+ [
+ ["guid", '?'],
+ ].each do |x, occurs|
+ install_have_child_element(x)
+ install_model(x, occurs)
+ 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
- end
-
- private
- alias children09 children
- def children
- children09 + [@guid].compact
- end
-
- alias _tags09 _tags
- def _tags
- %w(comments author pubDate guid).delete_if do |x|
- send(x).nil?
- end.collect do |elem|
- [nil, elem]
- end + _tags09
- end
-
- class Guid < Element
-
- include RSS09
-
- [
- ["isPermaLink", nil, false]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- content_setup
-
- def initialize(isPermaLink=nil, content=nil)
- super()
- @isPermaLink = isPermaLink
- @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
- [
- ["isPermaLink", false]
- ]
- end
-
- end
-
- end
-
- end
-
- end
-
- RSS09::ELEMENTS.each do |x|
- BaseListener.install_get_text_element(x, nil, "#{x}=")
- end
+ rv << super
+ end
+
+ private
+ alias children09 children
+ def children
+ children09 + [@guid].compact
+ end
+
+ alias _tags09 _tags
+ def _tags
+ %w(comments author pubDate guid).delete_if do |x|
+ send(x).nil?
+ end.collect do |elem|
+ [nil, elem]
+ end + _tags09
+ end
+
+ class Guid < Element
+
+ include RSS09
+
+ [
+ ["isPermaLink", nil, false]
+ ].each do |name, uri, required|
+ install_get_attribute(name, uri, required)
+ end
+
+ content_setup
+
+ def initialize(isPermaLink=nil, content=nil)
+ super()
+ @isPermaLink = isPermaLink
+ @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
+ [
+ ["isPermaLink", false]
+ ]
+ end
+
+ end
+
+ end
+
+ end
+
+ end
+
+ RSS09::ELEMENTS.each do |x|
+ BaseListener.install_get_text_element(x, nil, "#{x}=")
+ end
end
diff --git a/lib/rss/content.rb b/lib/rss/content.rb
index a8ed962644..4367d16d92 100644
--- a/lib/rss/content.rb
+++ b/lib/rss/content.rb
@@ -2,51 +2,51 @@ require "rss/1.0"
module RSS
- CONTENT_PREFIX = 'content'
- CONTENT_URI = "http://purl.org/rss/1.0/modules/content/"
-
- RDF.install_ns(CONTENT_PREFIX, CONTENT_URI)
-
- module ContentModel
-
- extend BaseModel
-
- ELEMENTS = []
-
- def self.append_features(klass)
- super
-
- klass.module_eval(<<-EOC)
- %w(encoded).each do |x|
- install_text_element("\#{CONTENT_PREFIX}_\#{x}")
- end
- EOC
- end
-
- def content_validate(tags)
- counter = {}
- ELEMENTS.each do |x|
- counter[x] = 0
- end
-
- tags.each do |tag|
- key = "#{CONTENT_PREFIX}_#{tag}"
- raise UnknownTagError.new(tag, CONTENT_URI) unless counter.has_key?(key)
- counter[key] += 1
- raise TooMuchTagError.new(tag, tag_name) if counter[key] > 1
- end
- end
-
- end
-
- class RDF
- class Item; include ContentModel; end
- end
-
- prefix_size = CONTENT_PREFIX.size + 1
- ContentModel::ELEMENTS.uniq!
- ContentModel::ELEMENTS.each do |x|
- BaseListener.install_get_text_element(x[prefix_size..-1], CONTENT_URI, "#{x}=")
- end
+ CONTENT_PREFIX = 'content'
+ CONTENT_URI = "http://purl.org/rss/1.0/modules/content/"
+
+ RDF.install_ns(CONTENT_PREFIX, CONTENT_URI)
+
+ module ContentModel
+
+ extend BaseModel
+
+ ELEMENTS = []
+
+ def self.append_features(klass)
+ super
+
+ klass.module_eval(<<-EOC)
+ %w(encoded).each do |x|
+ install_text_element("\#{CONTENT_PREFIX}_\#{x}")
+ end
+ EOC
+ end
+
+ def content_validate(tags)
+ counter = {}
+ ELEMENTS.each do |x|
+ counter[x] = 0
+ end
+
+ tags.each do |tag|
+ key = "#{CONTENT_PREFIX}_#{tag}"
+ raise UnknownTagError.new(tag, CONTENT_URI) unless counter.has_key?(key)
+ counter[key] += 1
+ raise TooMuchTagError.new(tag, tag_name) if counter[key] > 1
+ end
+ end
+
+ end
+
+ class RDF
+ class Item; include ContentModel; end
+ end
+
+ prefix_size = CONTENT_PREFIX.size + 1
+ ContentModel::ELEMENTS.uniq!
+ ContentModel::ELEMENTS.each do |x|
+ BaseListener.install_get_text_element(x[prefix_size..-1], CONTENT_URI, "#{x}=")
+ end
end
diff --git a/lib/rss/converter.rb b/lib/rss/converter.rb
index 472da2e0a9..7ad79db318 100644
--- a/lib/rss/converter.rb
+++ b/lib/rss/converter.rb
@@ -2,154 +2,154 @@ require "rss/utils"
module RSS
- class Converter
-
- include Utils
+ class Converter
+
+ include Utils
- def initialize(to_enc, from_enc=nil)
- normalized_to_enc = to_enc.downcase.gsub(/-/, '_')
- from_enc ||= 'utf-8'
- normalized_from_enc = from_enc.downcase.gsub(/-/, '_')
- if normalized_to_enc == normalized_from_enc
- def_same_enc()
- else
- def_diff_enc = "def_to_#{normalized_to_enc}_from_#{normalized_from_enc}"
- if respond_to?(def_diff_enc)
- __send__(def_diff_enc)
- else
- def_else_enc(to_enc, from_enc)
- end
- end
- end
+ def initialize(to_enc, from_enc=nil)
+ normalized_to_enc = to_enc.downcase.gsub(/-/, '_')
+ from_enc ||= 'utf-8'
+ normalized_from_enc = from_enc.downcase.gsub(/-/, '_')
+ if normalized_to_enc == normalized_from_enc
+ def_same_enc()
+ else
+ def_diff_enc = "def_to_#{normalized_to_enc}_from_#{normalized_from_enc}"
+ if respond_to?(def_diff_enc)
+ __send__(def_diff_enc)
+ else
+ def_else_enc(to_enc, from_enc)
+ end
+ end
+ end
- def convert(value)
- value
- end
+ def convert(value)
+ value
+ end
- def def_convert(depth=0)
- instance_eval(<<-EOC, *get_file_and_line_from_caller(depth))
- def convert(value)
- if value.kind_of?(String)
- #{yield('value')}
- else
- value
- end
- end
- EOC
- end
+ def def_convert(depth=0)
+ instance_eval(<<-EOC, *get_file_and_line_from_caller(depth))
+ def convert(value)
+ if value.kind_of?(String)
+ #{yield('value')}
+ else
+ value
+ end
+ end
+ EOC
+ end
- def def_iconv_convert(to_enc, from_enc, depth=0)
- begin
- require "iconv"
- @iconv = Iconv.new(to_enc, from_enc)
- def_convert(depth+1) do |value|
- <<-EOC
- begin
- @iconv.iconv(#{value})
- rescue Iconv::Failure
- raise ConversionError.new(#{value}, "#{to_enc}", "#{from_enc}")
- end
- EOC
- end
- rescue LoadError, ArgumentError, SystemCallError
- raise UnknownConversionMethodError.new(to_enc, from_enc)
- end
- end
-
- def def_else_enc(to_enc, from_enc)
- def_iconv_convert(to_enc, from_enc, 0)
- end
-
- def def_same_enc()
- def_convert do |value|
- value
- end
- end
+ def def_iconv_convert(to_enc, from_enc, depth=0)
+ begin
+ require "iconv"
+ @iconv = Iconv.new(to_enc, from_enc)
+ def_convert(depth+1) do |value|
+ <<-EOC
+ begin
+ @iconv.iconv(#{value})
+ rescue Iconv::Failure
+ raise ConversionError.new(#{value}, "#{to_enc}", "#{from_enc}")
+ end
+ EOC
+ end
+ rescue LoadError, ArgumentError, SystemCallError
+ raise UnknownConversionMethodError.new(to_enc, from_enc)
+ end
+ end
+
+ def def_else_enc(to_enc, from_enc)
+ def_iconv_convert(to_enc, from_enc, 0)
+ end
+
+ def def_same_enc()
+ def_convert do |value|
+ value
+ end
+ end
- def def_uconv_convert_if_can(meth, to_enc, from_enc)
- begin
- require "uconv"
- def_convert(1) do |value|
- <<-EOC
- begin
- Uconv.#{meth}(#{value})
- rescue Uconv::Error
- raise ConversionError.new(#{value}, "#{to_enc}", "#{from_enc}")
- end
- EOC
- end
- rescue LoadError
- def_iconv_convert(to_enc, from_enc, 1)
- end
- end
+ def def_uconv_convert_if_can(meth, to_enc, from_enc)
+ begin
+ require "uconv"
+ def_convert(1) do |value|
+ <<-EOC
+ begin
+ Uconv.#{meth}(#{value})
+ rescue Uconv::Error
+ raise ConversionError.new(#{value}, "#{to_enc}", "#{from_enc}")
+ end
+ EOC
+ end
+ rescue LoadError
+ def_iconv_convert(to_enc, from_enc, 1)
+ end
+ end
- def def_to_euc_jp_from_utf_8
- def_uconv_convert_if_can('u8toeuc', 'EUC-JP', 'UTF-8')
- end
-
- def def_to_utf_8_from_euc_jp
- def_uconv_convert_if_can('euctou8', 'UTF-8', 'EUC-JP')
- end
-
- def def_to_shift_jis_from_utf_8
- def_uconv_convert_if_can('u8tosjis', 'Shift_JIS', 'UTF-8')
- end
-
- def def_to_utf_8_from_shift_jis
- def_uconv_convert_if_can('sjistou8', 'UTF-8', 'Shift_JIS')
- end
-
- def def_to_euc_jp_from_shift_jis
- require "nkf"
- def_convert do |value|
- "NKF.nkf('-Se', #{value})"
- end
- end
-
- def def_to_shift_jis_from_euc_jp
- require "nkf"
- def_convert do |value|
- "NKF.nkf('-Es', #{value})"
- end
- end
-
- def def_to_euc_jp_from_iso_2022_jp
- require "nkf"
- def_convert do |value|
- "NKF.nkf('-Je', #{value})"
- end
- end
-
- def def_to_iso_2022_jp_from_euc_jp
- require "nkf"
- def_convert do |value|
- "NKF.nkf('-Ej', #{value})"
- end
- end
+ def def_to_euc_jp_from_utf_8
+ def_uconv_convert_if_can('u8toeuc', 'EUC-JP', 'UTF-8')
+ end
+
+ def def_to_utf_8_from_euc_jp
+ def_uconv_convert_if_can('euctou8', 'UTF-8', 'EUC-JP')
+ end
+
+ def def_to_shift_jis_from_utf_8
+ def_uconv_convert_if_can('u8tosjis', 'Shift_JIS', 'UTF-8')
+ end
+
+ def def_to_utf_8_from_shift_jis
+ def_uconv_convert_if_can('sjistou8', 'UTF-8', 'Shift_JIS')
+ end
+
+ def def_to_euc_jp_from_shift_jis
+ require "nkf"
+ def_convert do |value|
+ "NKF.nkf('-Se', #{value})"
+ end
+ end
+
+ def def_to_shift_jis_from_euc_jp
+ require "nkf"
+ def_convert do |value|
+ "NKF.nkf('-Es', #{value})"
+ end
+ end
+
+ def def_to_euc_jp_from_iso_2022_jp
+ require "nkf"
+ def_convert do |value|
+ "NKF.nkf('-Je', #{value})"
+ end
+ end
+
+ def def_to_iso_2022_jp_from_euc_jp
+ require "nkf"
+ def_convert do |value|
+ "NKF.nkf('-Ej', #{value})"
+ end
+ end
- def def_to_utf_8_from_iso_8859_1
- def_convert do |value|
- "#{value}.unpack('C*').pack('U*')"
- end
- end
-
- def def_to_iso_8859_1_from_utf_8
- def_convert do |value|
- <<-EOC
- array_utf8 = #{value}.unpack('U*')
- array_enc = []
- array_utf8.each do |num|
- if num <= 0xFF
- array_enc << num
- else
- array_enc.concat "&\#\#{num};".unpack('C*')
- end
- end
- array_enc.pack('C*')
- EOC
- end
- end
-
- end
-
+ def def_to_utf_8_from_iso_8859_1
+ def_convert do |value|
+ "#{value}.unpack('C*').pack('U*')"
+ end
+ end
+
+ def def_to_iso_8859_1_from_utf_8
+ def_convert do |value|
+ <<-EOC
+ array_utf8 = #{value}.unpack('U*')
+ array_enc = []
+ array_utf8.each do |num|
+ if num <= 0xFF
+ array_enc << num
+ else
+ array_enc.concat "&\#\#{num};".unpack('C*')
+ end
+ end
+ array_enc.pack('C*')
+ EOC
+ end
+ end
+
+ end
+
end
diff --git a/lib/rss/dublincore.rb b/lib/rss/dublincore.rb
index c757b6279b..417ab5b179 100644
--- a/lib/rss/dublincore.rb
+++ b/lib/rss/dublincore.rb
@@ -2,63 +2,63 @@ require "rss/1.0"
module RSS
- DC_PREFIX = 'dc'
- DC_URI = "http://purl.org/dc/elements/1.1/"
-
- RDF.install_ns(DC_PREFIX, DC_URI)
+ DC_PREFIX = 'dc'
+ DC_URI = "http://purl.org/dc/elements/1.1/"
+
+ RDF.install_ns(DC_PREFIX, DC_URI)
- module DublinCoreModel
+ module DublinCoreModel
- extend BaseModel
+ extend BaseModel
- ELEMENTS = []
+ ELEMENTS = []
- def self.append_features(klass)
- super
-
- klass.module_eval(<<-EOC)
- %w(title description creator subject publisher
- contributor type format identifier source
- language relation coverage rights).each do |x|
- install_text_element("\#{DC_PREFIX}_\#{x}")
- end
+ def self.append_features(klass)
+ super
+
+ klass.module_eval(<<-EOC)
+ %w(title description creator subject publisher
+ contributor type format identifier source
+ language relation coverage rights).each do |x|
+ install_text_element("\#{DC_PREFIX}_\#{x}")
+ end
- %w(date).each do |x|
- install_date_element("\#{DC_PREFIX}_\#{x}", 'w3cdtf', x)
- end
- EOC
- end
+ %w(date).each do |x|
+ install_date_element("\#{DC_PREFIX}_\#{x}", 'w3cdtf', x)
+ end
+ EOC
+ end
- def dc_validate(tags)
- counter = {}
- ELEMENTS.each do |x|
- counter[x] = 0
- end
+ def dc_validate(tags)
+ counter = {}
+ ELEMENTS.each do |x|
+ counter[x] = 0
+ end
- tags.each do |tag|
- key = "#{DC_PREFIX}_#{tag}"
- raise UnknownTagError.new(tag, DC_URI) unless counter.has_key?(key)
- counter[key] += 1
- raise TooMuchTagError.new(tag, tag_name) if counter[key] > 1
- end
- end
+ tags.each do |tag|
+ key = "#{DC_PREFIX}_#{tag}"
+ raise UnknownTagError.new(tag, DC_URI) unless counter.has_key?(key)
+ counter[key] += 1
+ raise TooMuchTagError.new(tag, tag_name) if counter[key] > 1
+ end
+ end
- end
+ end
- # For backward compatibility
- DublincoreModel = DublinCoreModel
+ # For backward compatibility
+ DublincoreModel = DublinCoreModel
- class RDF
- class Channel; include DublinCoreModel; end
- class Image; include DublinCoreModel; end
- class Item; include DublinCoreModel; end
- class Textinput; include DublinCoreModel; end
- end
+ class RDF
+ class Channel; include DublinCoreModel; end
+ class Image; include DublinCoreModel; end
+ class Item; include DublinCoreModel; end
+ class Textinput; include DublinCoreModel; end
+ end
- prefix_size = DC_PREFIX.size + 1
- DublinCoreModel::ELEMENTS.uniq!
- DublinCoreModel::ELEMENTS.each do |x|
- BaseListener.install_get_text_element(x[prefix_size..-1], DC_URI, "#{x}=")
- end
+ prefix_size = DC_PREFIX.size + 1
+ DublinCoreModel::ELEMENTS.uniq!
+ DublinCoreModel::ELEMENTS.each do |x|
+ BaseListener.install_get_text_element(x[prefix_size..-1], DC_URI, "#{x}=")
+ end
end
diff --git a/lib/rss/parser.rb b/lib/rss/parser.rb
index 9b9ff59173..09b3213372 100644
--- a/lib/rss/parser.rb
+++ b/lib/rss/parser.rb
@@ -4,393 +4,393 @@ require "rss/rss"
module RSS
- class NotWellFormedError < Error
- attr_reader :line, :element
- def initialize(line=nil, element=nil)
- message = "This is not well formed XML"
- if element or line
- message << "\nerror occurred"
- message << " in #{element}" if element
- message << " at about #{line} line" if line
- end
- message << "\n#{yield}" if block_given?
- super(message)
- end
- end
-
- class XMLParserNotFound < Error
- def initialize
- super("available XML parser does not found in " <<
- "#{AVAILABLE_PARSER_LIBRARIES.inspect}.")
- end
- end
-
- class NotValidXMLParser < Error
- def initialize(parser)
- super("#{parser} is not available XML parser. " <<
- "available XML parser is " <<
- "#{AVAILABLE_PARSERS.inspect}.")
- end
- end
-
- class NSError < InvalidRSSError
- attr_reader :tag, :prefix, :uri
- def initialize(tag, prefix, require_uri)
- @tag, @prefix, @uri = tag, prefix, require_uri
- super("prefix <#{prefix}> doesn't associate uri " <<
- "<#{require_uri}> in tag <#{tag}>")
- end
- end
-
- class Parser
-
- extend Forwardable
-
- class << self
-
- @@default_parser = nil
-
- def default_parser
- @@default_parser || AVAILABLE_PARSERS.first
- end
-
- def default_parser=(new_value)
- if AVAILABLE_PARSERS.include?(new_value)
- @@default_parser = new_value
- else
- raise NotValidXMLParser.new(new_value)
- end
- end
-
- def parse(rss, do_validate=true, ignore_unknown_element=true, parser_class=default_parser)
- parser = new(rss, parser_class)
- parser.do_validate = do_validate
- parser.ignore_unknown_element = ignore_unknown_element
- parser.parse
- end
-
- end
-
- def_delegators(:@parser, :parse, :rss,
- :ignore_unknown_element,
- :ignore_unknown_element=, :do_validate,
- :do_validate=)
-
- def initialize(rss, parser_class=self.class.default_parser)
- @parser = parser_class.new(rss)
- end
- end
-
- class BaseParser
-
- def initialize(rss)
- @listener = listener.new
- @rss = rss
- end
-
- def rss
- @listener.rss
- end
-
- def ignore_unknown_element
- @listener.ignore_unknown_element
- end
-
- def ignore_unknown_element=(new_value)
- @listener.ignore_unknown_element = new_value
- end
-
- def do_validate
- @listener.do_validate
- end
-
- def do_validate=(new_value)
- @listener.do_validate = new_value
- end
-
- def parse
- if @listener.rss.nil?
- _parse
- end
- @listener.rss
- end
-
- end
-
- class BaseListener
-
- extend Utils
-
- class << self
-
- @@setter = {}
- @@registered_uris = {}
-
- def install_setter(uri, tag_name, setter)
- @@setter[uri] = {} unless @@setter.has_key?(uri)
- @@setter[uri][tag_name] = setter
- end
-
- def register_uri(name, uri)
- @@registered_uris[name] = {} unless @@registered_uris.has_key?(name)
- @@registered_uris[name][uri] = nil
- end
-
- def uri_registered?(name, uri)
- @@registered_uris[name].has_key?(uri)
- end
-
- def setter(uri, tag_name)
- begin
- @@setter[uri][tag_name]
- rescue NameError
- nil
- end
- end
-
- def available_tags(uri)
- begin
- @@setter[uri].keys
- rescue NameError
- []
- end
- end
-
- def install_get_text_element(name, uri, setter)
- install_setter(uri, name, setter)
- def_get_text_element(uri, name, *get_file_and_line_from_caller(1))
- end
-
- private
-
- def def_get_text_element(uri, name, file, line)
- register_uri(name, uri)
- unless private_instance_methods(false).include?("start_#{name}")
- module_eval(<<-EOT, file, line)
- def start_#{name}(name, prefix, attrs, ns)
- uri = ns[prefix]
- if self.class.uri_registered?(#{name.inspect}, uri)
- if @do_validate
- tags = self.class.available_tags(uri)
- unless tags.include?(name)
- raise UnknownTagError.new(name, uri)
- end
- end
- start_get_text_element(name, prefix, ns, uri)
- else
- start_else_element(name, prefix, attrs, ns)
- end
- end
- EOT
- send("private", "start_#{name}")
- end
- end
-
- end
-
- end
-
- module ListenerMixin
-
- attr_reader :rss
-
- attr_accessor :ignore_unknown_element
- attr_accessor :do_validate
-
- def initialize
- @rss = nil
- @ignore_unknown_element = true
- @do_validate = true
- @ns_stack = [{}]
- @tag_stack = [[]]
- @text_stack = ['']
- @proc_stack = []
- @last_element = nil
- @version = @encoding = @standalone = nil
- @xml_stylesheets = []
- end
-
- def xmldecl(version, encoding, standalone)
- @version, @encoding, @standalone = version, encoding, standalone
- end
-
- def instruction(name, content)
- if name == "xml-stylesheet"
- params = parse_pi_content(content)
- if params.has_key?("href")
- @xml_stylesheets << XMLStyleSheet.new(*params)
- end
- end
- end
-
- def tag_start(name, attributes)
- @text_stack.push('')
-
- ns = @ns_stack.last.dup
- attrs = {}
- attributes.each do |n, v|
- if n =~ /\Axmlns:?/
- ns[$POSTMATCH] = v
- else
- attrs[n] = v
- end
- end
- @ns_stack.push(ns)
-
- prefix, local = split_name(name)
- @tag_stack.last.push([ns[prefix], local])
- @tag_stack.push([])
- if respond_to?("start_#{local}", true)
- send("start_#{local}", local, prefix, attrs, ns.dup)
- else
- start_else_element(local, prefix, attrs, ns.dup)
- end
- end
-
- def tag_end(name)
- if DEBUG
- p "end tag #{name}"
- p @tag_stack
- end
- text = @text_stack.pop
- tags = @tag_stack.pop
- pr = @proc_stack.pop
- pr.call(text, tags) unless pr.nil?
- end
-
- def text(data)
- @text_stack.last << data
- end
-
- private
-
- CONTENT_PATTERN = /\s*([^=]+)=(["'])([^\2]+?)\2/
- def parse_pi_content(content)
- params = {}
- content.scan(CONTENT_PATTERN) do |name, quote, value|
- params[name] = value
- end
- params
- end
-
- def start_else_element(local, prefix, attrs, ns)
- class_name = local[0,1].upcase << local[1..-1]
- current_class = @last_element.class
+ class NotWellFormedError < Error
+ attr_reader :line, :element
+ def initialize(line=nil, element=nil)
+ message = "This is not well formed XML"
+ if element or line
+ message << "\nerror occurred"
+ message << " in #{element}" if element
+ message << " at about #{line} line" if line
+ end
+ message << "\n#{yield}" if block_given?
+ super(message)
+ end
+ end
+
+ class XMLParserNotFound < Error
+ def initialize
+ super("available XML parser does not found in " <<
+ "#{AVAILABLE_PARSER_LIBRARIES.inspect}.")
+ end
+ end
+
+ class NotValidXMLParser < Error
+ def initialize(parser)
+ super("#{parser} is not available XML parser. " <<
+ "available XML parser is " <<
+ "#{AVAILABLE_PARSERS.inspect}.")
+ end
+ end
+
+ class NSError < InvalidRSSError
+ attr_reader :tag, :prefix, :uri
+ def initialize(tag, prefix, require_uri)
+ @tag, @prefix, @uri = tag, prefix, require_uri
+ super("prefix <#{prefix}> doesn't associate uri " <<
+ "<#{require_uri}> in tag <#{tag}>")
+ end
+ end
+
+ class Parser
+
+ extend Forwardable
+
+ class << self
+
+ @@default_parser = nil
+
+ def default_parser
+ @@default_parser || AVAILABLE_PARSERS.first
+ end
+
+ def default_parser=(new_value)
+ if AVAILABLE_PARSERS.include?(new_value)
+ @@default_parser = new_value
+ else
+ raise NotValidXMLParser.new(new_value)
+ end
+ end
+
+ def parse(rss, do_validate=true, ignore_unknown_element=true, parser_class=default_parser)
+ parser = new(rss, parser_class)
+ parser.do_validate = do_validate
+ parser.ignore_unknown_element = ignore_unknown_element
+ parser.parse
+ end
+
+ end
+
+ def_delegators(:@parser, :parse, :rss,
+ :ignore_unknown_element,
+ :ignore_unknown_element=, :do_validate,
+ :do_validate=)
+
+ def initialize(rss, parser_class=self.class.default_parser)
+ @parser = parser_class.new(rss)
+ end
+ end
+
+ class BaseParser
+
+ def initialize(rss)
+ @listener = listener.new
+ @rss = rss
+ end
+
+ def rss
+ @listener.rss
+ end
+
+ def ignore_unknown_element
+ @listener.ignore_unknown_element
+ end
+
+ def ignore_unknown_element=(new_value)
+ @listener.ignore_unknown_element = new_value
+ end
+
+ def do_validate
+ @listener.do_validate
+ end
+
+ def do_validate=(new_value)
+ @listener.do_validate = new_value
+ end
+
+ def parse
+ if @listener.rss.nil?
+ _parse
+ end
+ @listener.rss
+ end
+
+ end
+
+ class BaseListener
+
+ extend Utils
+
+ class << self
+
+ @@setter = {}
+ @@registered_uris = {}
+
+ def install_setter(uri, tag_name, setter)
+ @@setter[uri] = {} unless @@setter.has_key?(uri)
+ @@setter[uri][tag_name] = setter
+ end
+
+ def register_uri(name, uri)
+ @@registered_uris[name] = {} unless @@registered_uris.has_key?(name)
+ @@registered_uris[name][uri] = nil
+ end
+
+ def uri_registered?(name, uri)
+ @@registered_uris[name].has_key?(uri)
+ end
+
+ def setter(uri, tag_name)
+ begin
+ @@setter[uri][tag_name]
+ rescue NameError
+ nil
+ end
+ end
+
+ def available_tags(uri)
+ begin
+ @@setter[uri].keys
+ rescue NameError
+ []
+ end
+ end
+
+ def install_get_text_element(name, uri, setter)
+ install_setter(uri, name, setter)
+ def_get_text_element(uri, name, *get_file_and_line_from_caller(1))
+ end
+
+ private
+
+ def def_get_text_element(uri, name, file, line)
+ register_uri(name, uri)
+ unless private_instance_methods(false).include?("start_#{name}")
+ module_eval(<<-EOT, file, line)
+ def start_#{name}(name, prefix, attrs, ns)
+ uri = ns[prefix]
+ if self.class.uri_registered?(#{name.inspect}, uri)
+ if @do_validate
+ tags = self.class.available_tags(uri)
+ unless tags.include?(name)
+ raise UnknownTagError.new(name, uri)
+ end
+ end
+ start_get_text_element(name, prefix, ns, uri)
+ else
+ start_else_element(name, prefix, attrs, ns)
+ end
+ end
+ EOT
+ send("private", "start_#{name}")
+ end
+ end
+
+ end
+
+ end
+
+ module ListenerMixin
+
+ attr_reader :rss
+
+ attr_accessor :ignore_unknown_element
+ attr_accessor :do_validate
+
+ def initialize
+ @rss = nil
+ @ignore_unknown_element = true
+ @do_validate = true
+ @ns_stack = [{}]
+ @tag_stack = [[]]
+ @text_stack = ['']
+ @proc_stack = []
+ @last_element = nil
+ @version = @encoding = @standalone = nil
+ @xml_stylesheets = []
+ end
+
+ def xmldecl(version, encoding, standalone)
+ @version, @encoding, @standalone = version, encoding, standalone
+ end
+
+ def instruction(name, content)
+ if name == "xml-stylesheet"
+ params = parse_pi_content(content)
+ if params.has_key?("href")
+ @xml_stylesheets << XMLStyleSheet.new(*params)
+ end
+ end
+ end
+
+ def tag_start(name, attributes)
+ @text_stack.push('')
+
+ ns = @ns_stack.last.dup
+ attrs = {}
+ attributes.each do |n, v|
+ if n =~ /\Axmlns:?/
+ ns[$POSTMATCH] = v
+ else
+ attrs[n] = v
+ end
+ end
+ @ns_stack.push(ns)
+
+ prefix, local = split_name(name)
+ @tag_stack.last.push([ns[prefix], local])
+ @tag_stack.push([])
+ if respond_to?("start_#{local}", true)
+ send("start_#{local}", local, prefix, attrs, ns.dup)
+ else
+ start_else_element(local, prefix, attrs, ns.dup)
+ end
+ end
+
+ def tag_end(name)
+ if DEBUG
+ p "end tag #{name}"
+ p @tag_stack
+ end
+ text = @text_stack.pop
+ tags = @tag_stack.pop
+ pr = @proc_stack.pop
+ pr.call(text, tags) unless pr.nil?
+ end
+
+ def text(data)
+ @text_stack.last << data
+ end
+
+ private
+
+ CONTENT_PATTERN = /\s*([^=]+)=(["'])([^\2]+?)\2/
+ def parse_pi_content(content)
+ params = {}
+ content.scan(CONTENT_PATTERN) do |name, quote, value|
+ params[name] = value
+ end
+ params
+ end
+
+ def start_else_element(local, prefix, attrs, ns)
+ class_name = local[0,1].upcase << local[1..-1]
+ current_class = @last_element.class
# begin
- if current_class.constants.include?(class_name)
- next_class = current_class.const_get(class_name)
- start_have_something_element(local, prefix, attrs, ns, next_class)
+ if current_class.constants.include?(class_name)
+ next_class = current_class.const_get(class_name)
+ start_have_something_element(local, prefix, attrs, ns, next_class)
# rescue NameError
- else
- if @ignore_unknown_element
- @proc_stack.push(nil)
- else
- parent = "ROOT ELEMENT???"
- if current_class.tag_name
- parent = current_class.tag_name
- end
- raise NotExceptedTagError.new(local, parent)
- end
- end
- end
-
- NAMESPLIT = /^(?:([\w:][-\w\d.]*):)?([\w:][-\w\d.]*)/
- def split_name(name)
- name =~ NAMESPLIT
- [$1 || '', $2]
- end
-
- def check_ns(tag_name, prefix, ns, require_uri)
- if @do_validate
- if ns[prefix] == require_uri
- #ns.delete(prefix)
- else
- raise NSError.new(tag_name, prefix, require_uri)
- end
- end
- end
-
- def start_get_text_element(tag_name, prefix, ns, required_uri)
- @proc_stack.push Proc.new {|text, tags|
- setter = self.class.setter(required_uri, tag_name)
- setter ||= "#{tag_name}="
- if @last_element.respond_to?(setter)
- @last_element.send(setter, text.to_s)
- else
- if @do_validate and not @ignore_unknown_element
- raise NotExceptedTagError.new(tag_name, @last_element.tag_name)
- end
- end
- }
- end
-
- def start_have_something_element(tag_name, prefix, attrs, ns, klass)
-
- check_ns(tag_name, prefix, ns, klass.required_uri)
-
- args = []
-
- klass.get_attributes.each do |a_name, a_uri, required|
-
- if a_uri.is_a?(String) or !a_uri.respond_to?(:include?)
- a_uri = [a_uri]
- end
- unless a_uri == [nil]
- for prefix, uri in ns
- if a_uri.include?(uri)
- val = attrs["#{prefix}:#{a_name}"]
- break if val
- end
- end
- end
- if val.nil? and a_uri.include?(nil)
- val = attrs[a_name]
- end
-
- if @do_validate and required and val.nil?
- raise MissingAttributeError.new(tag_name, a_name)
- end
-
- args << val
- end
-
- 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)
- @last_element = next_element
- @proc_stack.push Proc.new { |text, tags|
- p(@last_element.class) if DEBUG
- @last_element.content = text if klass.have_content?
- @last_element.validate_for_stream(tags) if @do_validate
- @last_element = previous
- }
- end
-
- end
-
- unless const_defined? :AVAILABLE_PARSER_LIBRARIES
- AVAILABLE_PARSER_LIBRARIES = [
- ["rss/xmlparser", :XMLParserParser],
- ["rss/xmlscanner", :XMLScanParser],
- ["rss/rexmlparser", :REXMLParser],
- ]
- end
-
- AVAILABLE_PARSERS = []
-
- AVAILABLE_PARSER_LIBRARIES.each do |lib, parser|
- begin
- require lib
- AVAILABLE_PARSERS.push(const_get(parser))
- rescue LoadError
- end
- end
-
- if AVAILABLE_PARSERS.empty?
- raise XMLParserNotFound
- end
+ else
+ if @ignore_unknown_element
+ @proc_stack.push(nil)
+ else
+ parent = "ROOT ELEMENT???"
+ if current_class.tag_name
+ parent = current_class.tag_name
+ end
+ raise NotExceptedTagError.new(local, parent)
+ end
+ end
+ end
+
+ NAMESPLIT = /^(?:([\w:][-\w\d.]*):)?([\w:][-\w\d.]*)/
+ def split_name(name)
+ name =~ NAMESPLIT
+ [$1 || '', $2]
+ end
+
+ def check_ns(tag_name, prefix, ns, require_uri)
+ if @do_validate
+ if ns[prefix] == require_uri
+ #ns.delete(prefix)
+ else
+ raise NSError.new(tag_name, prefix, require_uri)
+ end
+ end
+ end
+
+ def start_get_text_element(tag_name, prefix, ns, required_uri)
+ @proc_stack.push Proc.new {|text, tags|
+ setter = self.class.setter(required_uri, tag_name)
+ setter ||= "#{tag_name}="
+ if @last_element.respond_to?(setter)
+ @last_element.send(setter, text.to_s)
+ else
+ if @do_validate and not @ignore_unknown_element
+ raise NotExceptedTagError.new(tag_name, @last_element.tag_name)
+ end
+ end
+ }
+ end
+
+ def start_have_something_element(tag_name, prefix, attrs, ns, klass)
+
+ check_ns(tag_name, prefix, ns, klass.required_uri)
+
+ args = []
+
+ klass.get_attributes.each do |a_name, a_uri, required|
+
+ if a_uri.is_a?(String) or !a_uri.respond_to?(:include?)
+ a_uri = [a_uri]
+ end
+ unless a_uri == [nil]
+ for prefix, uri in ns
+ if a_uri.include?(uri)
+ val = attrs["#{prefix}:#{a_name}"]
+ break if val
+ end
+ end
+ end
+ if val.nil? and a_uri.include?(nil)
+ val = attrs[a_name]
+ end
+
+ if @do_validate and required and val.nil?
+ raise MissingAttributeError.new(tag_name, a_name)
+ end
+
+ args << val
+ end
+
+ 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)
+ @last_element = next_element
+ @proc_stack.push Proc.new { |text, tags|
+ p(@last_element.class) if DEBUG
+ @last_element.content = text if klass.have_content?
+ @last_element.validate_for_stream(tags) if @do_validate
+ @last_element = previous
+ }
+ end
+
+ end
+
+ unless const_defined? :AVAILABLE_PARSER_LIBRARIES
+ AVAILABLE_PARSER_LIBRARIES = [
+ ["rss/xmlparser", :XMLParserParser],
+ ["rss/xmlscanner", :XMLScanParser],
+ ["rss/rexmlparser", :REXMLParser],
+ ]
+ end
+
+ AVAILABLE_PARSERS = []
+
+ AVAILABLE_PARSER_LIBRARIES.each do |lib, parser|
+ begin
+ require lib
+ AVAILABLE_PARSERS.push(const_get(parser))
+ rescue LoadError
+ end
+ end
+
+ if AVAILABLE_PARSERS.empty?
+ raise XMLParserNotFound
+ end
end
diff --git a/lib/rss/rexmlparser.rb b/lib/rss/rexmlparser.rb
index 13ab0e277b..375b7794fb 100644
--- a/lib/rss/rexmlparser.rb
+++ b/lib/rss/rexmlparser.rb
@@ -3,45 +3,45 @@ require "rexml/streamlistener"
/\A(\d+)\.(\d+)(?:\.\d+)+\z/ =~ REXML::Version
if ([$1.to_i, $2.to_i] <=> [2, 5]) < 0
- raise LoadError, "needs REXML 2.5 or later (#{REXML::Version})"
+ raise LoadError, "needs REXML 2.5 or later (#{REXML::Version})"
end
module RSS
-
- class REXMLParser < BaseParser
-
- private
-
- def listener
- REXMLListener
- end
-
- def _parse
- begin
- REXML::Document.parse_stream(@rss, @listener)
- rescue RuntimeError => e
- raise NotWellFormedError.new{e.message}
- rescue REXML::ParseException => e
- context = e.context
- line = context[0] if context
- raise NotWellFormedError.new(line){e.message}
- end
- end
-
- end
-
- class REXMLListener < BaseListener
-
- include REXML::StreamListener
- include ListenerMixin
-
- def xmldecl(version, encoding, standalone)
- super
- # Encoding is converted to UTF-8 when REXML parse XML.
- @encoding = 'UTF-8'
- end
-
- alias_method(:cdata, :text)
- end
+
+ class REXMLParser < BaseParser
+
+ private
+
+ def listener
+ REXMLListener
+ end
+
+ def _parse
+ begin
+ REXML::Document.parse_stream(@rss, @listener)
+ rescue RuntimeError => e
+ raise NotWellFormedError.new{e.message}
+ rescue REXML::ParseException => e
+ context = e.context
+ line = context[0] if context
+ raise NotWellFormedError.new(line){e.message}
+ end
+ end
+
+ end
+
+ class REXMLListener < BaseListener
+
+ include REXML::StreamListener
+ include ListenerMixin
+
+ def xmldecl(version, encoding, standalone)
+ super
+ # Encoding is converted to UTF-8 when REXML parse XML.
+ @encoding = 'UTF-8'
+ end
+
+ alias_method(:cdata, :text)
+ end
end
diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb
index 24ba0eb170..231fb1fb62 100644
--- a/lib/rss/rss.rb
+++ b/lib/rss/rss.rb
@@ -7,47 +7,47 @@
require "time"
class Time
- class << self
- unless respond_to?(:w3cdtf)
- def w3cdtf(date)
- if /\A\s*
- (-?\d+)-(\d\d)-(\d\d)
- (?:T
- (\d\d):(\d\d)(?::(\d\d))?
- (\.\d+)?
- (Z|[+-]\d\d:\d\d)?)?
- \s*\z/ix =~ date and (($5 and $8) or (!$5 and !$8))
- datetime = [$1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i]
- datetime << $7.to_f * 1000000 if $7
- if $8
- Time.utc(*datetime) - zone_offset($8)
- else
- Time.local(*datetime)
- end
- else
- raise ArgumentError.new("invalid date: #{date.inspect}")
- end
- end
- end
- end
-
- unless instance_methods.include?("w3cdtf")
- alias w3cdtf iso8601
- end
+ class << self
+ unless respond_to?(:w3cdtf)
+ def w3cdtf(date)
+ if /\A\s*
+ (-?\d+)-(\d\d)-(\d\d)
+ (?:T
+ (\d\d):(\d\d)(?::(\d\d))?
+ (\.\d+)?
+ (Z|[+-]\d\d:\d\d)?)?
+ \s*\z/ix =~ date and (($5 and $8) or (!$5 and !$8))
+ datetime = [$1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i]
+ datetime << $7.to_f * 1000000 if $7
+ if $8
+ Time.utc(*datetime) - zone_offset($8)
+ else
+ Time.local(*datetime)
+ end
+ else
+ raise ArgumentError.new("invalid date: #{date.inspect}")
+ end
+ end
+ end
+ end
+
+ unless instance_methods.include?("w3cdtf")
+ alias w3cdtf iso8601
+ end
end
module Enumerable
- unless instance_methods.include?("sort_by")
- def sort_by
- collect do |x|
- [yield(x), x]
- end.sort do |x, y|
- x[0] <=> y[0]
- end.collect! do |x|
- x[1]
- end
- end
- end
+ unless instance_methods.include?("sort_by")
+ def sort_by
+ collect do |x|
+ [yield(x), x]
+ end.sort do |x, y|
+ x[0] <=> y[0]
+ end.collect! do |x|
+ x[1]
+ end
+ end
+ end
end
require "English"
@@ -57,623 +57,623 @@ require "rss/xml-stylesheet"
module RSS
- VERSION = "0.1.0"
-
- URI = "http://purl.org/rss/1.0/"
-
- DEBUG = false
-
- class Error < StandardError; end
-
- class OverlappedPrefixError < Error
- attr_reader :prefix
- def initialize(prefix)
- @prefix = prefix
- end
- end
-
- class InvalidRSSError < Error; end
-
- class MissingTagError < InvalidRSSError
- attr_reader :tag, :parent
- def initialize(tag, parent)
- @tag, @parent = tag, parent
- super("tag <#{tag}> is missing in tag <#{parent}>")
- end
- end
-
- class TooMuchTagError < InvalidRSSError
- attr_reader :tag, :parent
- def initialize(tag, parent)
- @tag, @parent = tag, parent
- super("tag <#{tag}> is too much in tag <#{parent}>")
- end
- end
-
- class MissingAttributeError < InvalidRSSError
- attr_reader :tag, :attribute
- def initialize(tag, attribute)
- @tag, @attribute = tag, attribute
- super("attribute <#{attribute}> is missing in tag <#{tag}>")
- end
- end
-
- class UnknownTagError < InvalidRSSError
- attr_reader :tag, :uri
- def initialize(tag, uri)
- @tag, @uri = tag, uri
- super("tag <#{tag}> is unknown in namespace specified by uri <#{uri}>")
- end
- end
-
- class NotExceptedTagError < InvalidRSSError
- attr_reader :tag, :parent
- def initialize(tag, parent)
- @tag, @parent = tag, parent
- super("tag <#{tag}> is not expected in tag <#{parent}>")
- end
- end
-
- class NotAvailableValueError < InvalidRSSError
- attr_reader :tag, :value
- def initialize(tag, value)
- @tag, @value = tag, value
- super("value <#{value}> of tag <#{tag}> is not available.")
- end
- end
-
- class UnknownConversionMethodError < Error
- attr_reader :to, :from
- def initialize(to, from)
- @to = to
- @from = from
- super("can't convert to #{to} from #{from}.")
- end
- end
- # for backward compatibility
- UnknownConvertMethod = UnknownConversionMethodError
-
- class ConversionError < Error
- attr_reader :string, :to, :from
- def initialize(string, to, from)
- @string = string
- @to = to
- @from = from
- super("can't convert #{@string} to #{to} from #{from}.")
- end
- end
-
- module BaseModel
-
- include Utils
-
- def install_have_child_element(name)
- add_need_initialize_variable(name)
-
- attr_accessor name
- install_element(name) do |n, elem_name|
- <<-EOC
- if @#{n}
- "\#{@#{n}.to_s(convert, indent)}"
- else
- ''
- end
+ VERSION = "0.1.0"
+
+ URI = "http://purl.org/rss/1.0/"
+
+ DEBUG = false
+
+ class Error < StandardError; end
+
+ class OverlappedPrefixError < Error
+ attr_reader :prefix
+ def initialize(prefix)
+ @prefix = prefix
+ end
+ end
+
+ class InvalidRSSError < Error; end
+
+ class MissingTagError < InvalidRSSError
+ attr_reader :tag, :parent
+ def initialize(tag, parent)
+ @tag, @parent = tag, parent
+ super("tag <#{tag}> is missing in tag <#{parent}>")
+ end
+ end
+
+ class TooMuchTagError < InvalidRSSError
+ attr_reader :tag, :parent
+ def initialize(tag, parent)
+ @tag, @parent = tag, parent
+ super("tag <#{tag}> is too much in tag <#{parent}>")
+ end
+ end
+
+ class MissingAttributeError < InvalidRSSError
+ attr_reader :tag, :attribute
+ def initialize(tag, attribute)
+ @tag, @attribute = tag, attribute
+ super("attribute <#{attribute}> is missing in tag <#{tag}>")
+ end
+ end
+
+ class UnknownTagError < InvalidRSSError
+ attr_reader :tag, :uri
+ def initialize(tag, uri)
+ @tag, @uri = tag, uri
+ super("tag <#{tag}> is unknown in namespace specified by uri <#{uri}>")
+ end
+ end
+
+ class NotExceptedTagError < InvalidRSSError
+ attr_reader :tag, :parent
+ def initialize(tag, parent)
+ @tag, @parent = tag, parent
+ super("tag <#{tag}> is not expected in tag <#{parent}>")
+ end
+ end
+
+ class NotAvailableValueError < InvalidRSSError
+ attr_reader :tag, :value
+ def initialize(tag, value)
+ @tag, @value = tag, value
+ super("value <#{value}> of tag <#{tag}> is not available.")
+ end
+ end
+
+ class UnknownConversionMethodError < Error
+ attr_reader :to, :from
+ def initialize(to, from)
+ @to = to
+ @from = from
+ super("can't convert to #{to} from #{from}.")
+ end
+ end
+ # for backward compatibility
+ UnknownConvertMethod = UnknownConversionMethodError
+
+ class ConversionError < Error
+ attr_reader :string, :to, :from
+ def initialize(string, to, from)
+ @string = string
+ @to = to
+ @from = from
+ super("can't convert #{@string} to #{to} from #{from}.")
+ end
+ end
+
+ module BaseModel
+
+ include Utils
+
+ def install_have_child_element(name)
+ add_need_initialize_variable(name)
+
+ attr_accessor name
+ install_element(name) do |n, elem_name|
+ <<-EOC
+ if @#{n}
+ "\#{@#{n}.to_s(convert, indent)}"
+ else
+ ''
+ end
EOC
- end
- 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|
- <<-EOC
- rv = ''
- @#{n}.each do |x|
- rv << "\#{x.to_s(convert, indent)}"
- end
- rv
+ end
+ 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|
+ <<-EOC
+ rv = ''
+ @#{n}.each do |x|
+ rv << "\#{x.to_s(convert, indent)}"
+ end
+ rv
EOC
- end
- end
-
- def install_text_element(name)
- self::ELEMENTS << name
- add_need_initialize_variable(name)
-
- attr_writer name
- convert_attr_reader name
- install_element(name) do |n, elem_name|
- <<-EOC
- if @#{n}
- rv = "\#{indent}<#{elem_name}>"
- value = html_escape(@#{n})
- if convert and @converter
- rv << @converter.convert(value)
- else
- rv << value
- end
- rv << "</#{elem_name}>"
- rv
- else
- ''
- end
+ end
+ end
+
+ def install_text_element(name)
+ self::ELEMENTS << name
+ add_need_initialize_variable(name)
+
+ attr_writer name
+ convert_attr_reader name
+ install_element(name) do |n, elem_name|
+ <<-EOC
+ if @#{n}
+ rv = "\#{indent}<#{elem_name}>"
+ value = html_escape(@#{n})
+ if convert and @converter
+ rv << @converter.convert(value)
+ else
+ rv << value
+ end
+ rv << "</#{elem_name}>"
+ rv
+ else
+ ''
+ end
EOC
- end
- end
-
- def install_date_element(name, type, disp_name=name)
- self::ELEMENTS << name
- add_need_initialize_variable(name)
-
- # accessor
- convert_attr_reader name
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{name}=(new_value)
- if new_value.kind_of?(Time)
- @#{name} = new_value
- else
- if @do_validate
- begin
- @#{name} = Time.send('#{type}', new_value)
- rescue ArgumentError
- raise NotAvailableValueError.new('#{disp_name}', new_value)
- end
- else
- @#{name} = nil
- if /\\A\\s*\\z/ !~ new_value.to_s
- begin
- @#{name} = Time.parse(new_value)
- rescue ArgumentError
- end
- end
- end
- end
-
- # Is it need?
- if @#{name}
- class << @#{name}
- alias_method(:_to_s, :to_s) unless respond_to?(:_to_s)
- alias_method(:to_s, :#{type})
- end
- end
-
- end
+ end
+ end
+
+ def install_date_element(name, type, disp_name=name)
+ self::ELEMENTS << name
+ add_need_initialize_variable(name)
+
+ # accessor
+ convert_attr_reader name
+ module_eval(<<-EOC, *get_file_and_line_from_caller(2))
+ def #{name}=(new_value)
+ if new_value.kind_of?(Time)
+ @#{name} = new_value
+ else
+ if @do_validate
+ begin
+ @#{name} = Time.send('#{type}', new_value)
+ rescue ArgumentError
+ raise NotAvailableValueError.new('#{disp_name}', new_value)
+ end
+ else
+ @#{name} = nil
+ if /\\A\\s*\\z/ !~ new_value.to_s
+ begin
+ @#{name} = Time.parse(new_value)
+ rescue ArgumentError
+ end
+ end
+ end
+ end
+
+ # Is it need?
+ if @#{name}
+ class << @#{name}
+ alias_method(:_to_s, :to_s) unless respond_to?(:_to_s)
+ alias_method(:to_s, :#{type})
+ end
+ end
+
+ end
EOC
-
- install_element(name) do |n, elem_name|
- <<-EOC
- if @#{n}
- rv = "\#{indent}<#{elem_name}>"
- value = html_escape(@#{n}.#{type})
- if convert and @converter
- rv << @converter.convert(value)
- else
- rv << value
- end
- rv << "</#{elem_name}>"
- rv
- else
- ''
- end
+
+ install_element(name) do |n, elem_name|
+ <<-EOC
+ if @#{n}
+ rv = "\#{indent}<#{elem_name}>"
+ value = html_escape(@#{n}.#{type})
+ if convert and @converter
+ rv << @converter.convert(value)
+ else
+ rv << value
+ end
+ rv << "</#{elem_name}>"
+ rv
+ else
+ ''
+ end
EOC
- end
-
- end
-
- private
- def install_element(name, postfix="")
- elem_name = name.sub('_', ':')
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{name}_element#{postfix}(convert=true, indent='')
- #{yield(name, elem_name)}
- end
- private :#{name}_element#{postfix}
+ end
+
+ end
+
+ private
+ def install_element(name, postfix="")
+ elem_name = name.sub('_', ':')
+ module_eval(<<-EOC, *get_file_and_line_from_caller(2))
+ def #{name}_element#{postfix}(convert=true, indent='')
+ #{yield(name, elem_name)}
+ end
+ private :#{name}_element#{postfix}
EOC
- end
-
- def convert_attr_reader(*attrs)
- attrs.each do |attr|
- attr = attr.id2name if attr.kind_of?(Integer)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{attr}
- if @converter
- @converter.convert(@#{attr})
- else
- @#{attr}
- end
- end
+ end
+
+ def convert_attr_reader(*attrs)
+ attrs.each do |attr|
+ attr = attr.id2name if attr.kind_of?(Integer)
+ module_eval(<<-EOC, *get_file_and_line_from_caller(2))
+ def #{attr}
+ if @converter
+ @converter.convert(@#{attr})
+ else
+ @#{attr}
+ end
+ end
EOC
- end
- end
-
- def def_children_accessor(accessor_name, postfix="s")
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{accessor_name}#{postfix}
- @#{accessor_name}
- end
-
- def #{accessor_name}(*args)
- if args.empty?
- @#{accessor_name}.first
- else
- @#{accessor_name}.send("[]", *args)
- end
- end
-
- def #{accessor_name}=(*args)
- if args.size == 1
- @#{accessor_name}.push(args[0])
- else
- @#{accessor_name}.send("[]=", *args)
- end
- end
- alias_method(:set_#{accessor_name}, :#{accessor_name}=)
+ end
+ end
+
+ def def_children_accessor(accessor_name, postfix="s")
+ module_eval(<<-EOC, *get_file_and_line_from_caller(2))
+ def #{accessor_name}#{postfix}
+ @#{accessor_name}
+ end
+
+ def #{accessor_name}(*args)
+ if args.empty?
+ @#{accessor_name}.first
+ else
+ @#{accessor_name}.send("[]", *args)
+ end
+ end
+
+ def #{accessor_name}=(*args)
+ if args.size == 1
+ @#{accessor_name}.push(args[0])
+ else
+ @#{accessor_name}.send("[]=", *args)
+ end
+ end
+ alias_method(:set_#{accessor_name}, :#{accessor_name}=)
EOC
- end
+ end
- end
+ end
- class Element
+ class Element
- extend BaseModel
- include Utils
+ extend BaseModel
+ include Utils
- INDENT = " "
+ INDENT = " "
- class << self
-
- def inherited(klass)
- klass.module_eval(<<-EOC)
- public
-
- @tag_name = name.split(/::/).last.downcase
- @indent_size = name.split(/::/).size - 2
-
- @@must_call_validators = {}
-
- def self.must_call_validators
- @@must_call_validators
- end
-
- def self.install_must_call_validator(prefix, uri)
- @@must_call_validators[uri] = prefix
- end
-
- @@model = []
-
- def self.model
- @@model
- end
-
- def self.install_model(tag, occurs=nil)
- if m = @@model.find {|t, o| t == tag}
- m[1] = occurs
- else
- @@model << [tag, occurs]
- end
- end
-
- @@get_attributes = []
-
- def self.get_attributes()
- @@get_attributes
- end
-
- def self.install_get_attribute(name, uri, required=true)
- attr_writer name
- convert_attr_reader name
- @@get_attributes << [name, uri, required]
- end
-
- @@have_content = false
-
- def self.content_setup
- attr_writer :content
- convert_attr_reader :content
- @@have_content = true
- end
-
- def self.have_content?
- @@have_content
- end
-
- @@have_children_elements = []
-
- def self.have_children_elements
- @@have_children_elements
- end
-
- def self.add_have_children_element(variable_name)
- @@have_children_elements << variable_name
- end
-
- @@need_initialize_variables = []
-
- def self.add_need_initialize_variable(variable_name)
- @@need_initialize_variables << variable_name
- end
-
- def self.need_initialize_variables
- @@need_initialize_variables
- end
-
- EOC
- end
-
- def required_prefix
- nil
- end
-
- def required_uri
- nil
- end
-
- def install_ns(prefix, uri)
- if self::NSPOOL.has_key?(prefix)
- raise OverlappedPrefixError.new(prefix)
- end
- self::NSPOOL[prefix] = uri
- end
-
- def tag_name
- @tag_name
- end
+ class << self
+
+ def inherited(klass)
+ klass.module_eval(<<-EOC)
+ public
+
+ @tag_name = name.split(/::/).last.downcase
+ @indent_size = name.split(/::/).size - 2
+
+ @@must_call_validators = {}
+
+ def self.must_call_validators
+ @@must_call_validators
+ end
+
+ def self.install_must_call_validator(prefix, uri)
+ @@must_call_validators[uri] = prefix
+ end
+
+ @@model = []
+
+ def self.model
+ @@model
+ end
+
+ def self.install_model(tag, occurs=nil)
+ if m = @@model.find {|t, o| t == tag}
+ m[1] = occurs
+ else
+ @@model << [tag, occurs]
+ end
+ end
+
+ @@get_attributes = []
+
+ def self.get_attributes()
+ @@get_attributes
+ end
+
+ def self.install_get_attribute(name, uri, required=true)
+ attr_writer name
+ convert_attr_reader name
+ @@get_attributes << [name, uri, required]
+ end
+
+ @@have_content = false
+
+ def self.content_setup
+ attr_writer :content
+ convert_attr_reader :content
+ @@have_content = true
+ end
+
+ def self.have_content?
+ @@have_content
+ end
+
+ @@have_children_elements = []
+
+ def self.have_children_elements
+ @@have_children_elements
+ end
+
+ def self.add_have_children_element(variable_name)
+ @@have_children_elements << variable_name
+ end
+
+ @@need_initialize_variables = []
+
+ def self.add_need_initialize_variable(variable_name)
+ @@need_initialize_variables << variable_name
+ end
+
+ def self.need_initialize_variables
+ @@need_initialize_variables
+ end
+
+ EOC
+ end
+
+ def required_prefix
+ nil
+ end
+
+ def required_uri
+ nil
+ end
+
+ def install_ns(prefix, uri)
+ if self::NSPOOL.has_key?(prefix)
+ raise OverlappedPrefixError.new(prefix)
+ end
+ self::NSPOOL[prefix] = uri
+ end
+
+ def tag_name
+ @tag_name
+ end
- def indent_size
- @indent_size
- end
+ def indent_size
+ @indent_size
+ end
- end
-
- attr_accessor :do_validate
-
- def initialize(do_validate=true)
- @converter = nil
- @do_validate = do_validate
- initialize_variables
- end
-
- def tag_name
- self.class.tag_name
- end
-
- def converter=(converter)
- @converter = converter
- children.each do |child|
- child.converter = converter unless child.nil?
- end
- end
-
- def validate
- validate_attribute
- __validate
- end
-
- def validate_for_stream(tags)
- validate_attribute
- __validate(tags, false)
- end
+ end
+
+ attr_accessor :do_validate
+
+ def initialize(do_validate=true)
+ @converter = nil
+ @do_validate = do_validate
+ initialize_variables
+ end
+
+ def tag_name
+ self.class.tag_name
+ end
+
+ def converter=(converter)
+ @converter = converter
+ children.each do |child|
+ child.converter = converter unless child.nil?
+ end
+ end
+
+ def validate
+ validate_attribute
+ __validate
+ end
+
+ def validate_for_stream(tags)
+ validate_attribute
+ __validate(tags, false)
+ end
+
+ private
+ def initialize_variables
+ self.class.need_initialize_variables.each do |variable_name|
+ instance_eval("@#{variable_name} = nil")
+ end
+ initialize_have_children_elements
+ @content = "" if self.class.have_content?
+ end
+
+ def initialize_have_children_elements
+ self.class.have_children_elements.each do |variable_name|
+ instance_eval("@#{variable_name} = []")
+ end
+ end
+
+ # not String class children.
+ def children
+ []
+ end
+
+ # default #validate() argument.
+ def _tags
+ []
+ end
+
+ def _attrs
+ []
+ end
+
+ def __validate(tags=_tags, recursive=true)
+ if recursive
+ children.compact.each do |child|
+ child.validate
+ end
+ end
+ must_call_validators = self.class.must_call_validators
+ tags = tag_filter(tags.dup)
+ p tags if DEBUG
+ self.class::NSPOOL.each do |prefix, uri|
+ if tags.has_key?(uri) and !must_call_validators.has_key?(uri)
+ meth = "#{prefix}_validate"
+ send(meth, tags[uri]) if respond_to?(meth, true)
+ end
+ end
+ must_call_validators.each do |uri, prefix|
+ send("#{prefix}_validate", tags[uri])
+ end
+ 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)
+ end
+ end
+ end
+
+ def other_element(convert, indent='')
+ 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
+ end
+ end
+ rv
+ end
+
+ def _validate(tags, model=self.class.model)
+ count = 1
+ do_redo = false
+ not_shift = false
+ tag = nil
+ element_names = model.collect {|elem| elem[0]}
+ if tags
+ tags_size = tags.size
+ tags = tags.sort_by {|x| element_names.index(x) || tags_size}
+ end
+
+ model.each_with_index do |elem, i|
+
+ if DEBUG
+ p "before"
+ p tags
+ p elem
+ end
+
+ if not_shift
+ not_shift = false
+ elsif tags
+ tag = tags.shift
+ end
+
+ if DEBUG
+ p "mid"
+ p count
+ end
+
+ case elem[1]
+ when '?'
+ if count > 2
+ raise TooMuchTagError.new(elem[0], tag_name)
+ else
+ if elem[0] == tag
+ do_redo = true
+ else
+ not_shift = true
+ end
+ end
+ when '*'
+ if elem[0] == tag
+ do_redo = true
+ else
+ not_shift = true
+ end
+ when '+'
+ if elem[0] == tag
+ do_redo = true
+ else
+ if count > 1
+ not_shift = true
+ else
+ raise MissingTagError.new(elem[0], tag_name)
+ end
+ end
+ else
+ if elem[0] == tag
+ if model[i+1] and model[i+1][0] != elem[0] and
+ tags and tags.first == elem[0]
+ raise TooMuchTagError.new(elem[0], tag_name)
+ end
+ else
+ raise MissingTagError.new(elem[0], tag_name)
+ end
+ end
+
+ if DEBUG
+ p "after"
+ p not_shift
+ p do_redo
+ p tag
+ end
+
+ if do_redo
+ do_redo = false
+ count += 1
+ redo
+ else
+ count = 1
+ end
+
+ end
+
+ if !tags.nil? and !tags.empty?
+ raise NotExceptedTagError.new(tag, tag_name)
+ end
+
+ end
+
+ def tag_filter(tags)
+ rv = {}
+ tags.each do |tag|
+ rv[tag[0]] = [] unless rv.has_key?(tag[0])
+ rv[tag[0]].push(tag[1])
+ end
+ 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
+
+ attr_reader :output_encoding
+
+ def initialize(rss_version, version=nil, encoding=nil, standalone=nil)
+ super()
+ @rss_version = rss_version
+ @version = version || '1.0'
+ @encoding = encoding
+ @standalone = standalone
+ @output_encoding = nil
+ end
+
+ def output_encoding=(enc)
+ @output_encoding = enc
+ self.converter = Converter.new(@output_encoding, @encoding)
+ end
private
- def initialize_variables
- self.class.need_initialize_variables.each do |variable_name|
- instance_eval("@#{variable_name} = nil")
- end
- initialize_have_children_elements
- @content = "" if self.class.have_content?
- end
-
- def initialize_have_children_elements
- self.class.have_children_elements.each do |variable_name|
- instance_eval("@#{variable_name} = []")
- end
- end
-
- # not String class children.
- def children
- []
- end
-
- # default #validate() argument.
- def _tags
- []
- end
-
- def _attrs
- []
- end
-
- def __validate(tags=_tags, recursive=true)
- if recursive
- children.compact.each do |child|
- child.validate
- end
- end
- must_call_validators = self.class.must_call_validators
- tags = tag_filter(tags.dup)
- p tags if DEBUG
- self.class::NSPOOL.each do |prefix, uri|
- if tags.has_key?(uri) and !must_call_validators.has_key?(uri)
- meth = "#{prefix}_validate"
- send(meth, tags[uri]) if respond_to?(meth, true)
- end
- end
- must_call_validators.each do |uri, prefix|
- send("#{prefix}_validate", tags[uri])
- end
- 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)
- end
- end
- end
-
- def other_element(convert, indent='')
- 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
- end
- end
- rv
- end
-
- def _validate(tags, model=self.class.model)
- count = 1
- do_redo = false
- not_shift = false
- tag = nil
- element_names = model.collect {|elem| elem[0]}
- if tags
- tags_size = tags.size
- tags = tags.sort_by {|x| element_names.index(x) || tags_size}
- end
-
- model.each_with_index do |elem, i|
-
- if DEBUG
- p "before"
- p tags
- p elem
- end
-
- if not_shift
- not_shift = false
- elsif tags
- tag = tags.shift
- end
-
- if DEBUG
- p "mid"
- p count
- end
-
- case elem[1]
- when '?'
- if count > 2
- raise TooMuchTagError.new(elem[0], tag_name)
- else
- if elem[0] == tag
- do_redo = true
- else
- not_shift = true
- end
- end
- when '*'
- if elem[0] == tag
- do_redo = true
- else
- not_shift = true
- end
- when '+'
- if elem[0] == tag
- do_redo = true
- else
- if count > 1
- not_shift = true
- else
- raise MissingTagError.new(elem[0], tag_name)
- end
- end
- else
- if elem[0] == tag
- if model[i+1] and model[i+1][0] != elem[0] and
- tags and tags.first == elem[0]
- raise TooMuchTagError.new(elem[0], tag_name)
- end
- else
- raise MissingTagError.new(elem[0], tag_name)
- end
- end
-
- if DEBUG
- p "after"
- p not_shift
- p do_redo
- p tag
- end
-
- if do_redo
- do_redo = false
- count += 1
- redo
- else
- count = 1
- end
-
- end
-
- if !tags.nil? and !tags.empty?
- raise NotExceptedTagError.new(tag, tag_name)
- end
-
- end
-
- def tag_filter(tags)
- rv = {}
- tags.each do |tag|
- rv[tag[0]] = [] unless rv.has_key?(tag[0])
- rv[tag[0]].push(tag[1])
- end
- rv
- end
-
- private
- def calc_indent
- INDENT * (self.class.indent_size)
- 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
+ end
- def remove_empty_newline(string)
- string.gsub(/^\s*$(?:\r?\n?)/, '')
- end
+ def ns_declaration(indent)
+ rv = ''
+ self.class::NSPOOL.each do |prefix, uri|
+ prefix = ":#{prefix}" unless prefix.empty?
+ rv << %Q|\n#{indent}xmlns#{prefix}="#{html_escape(uri)}"|
+ end
+ rv
+ end
- end
-
- module RootElementMixin
-
- attr_reader :output_encoding
-
- def initialize(rss_version, version=nil, encoding=nil, standalone=nil)
- super()
- @rss_version = rss_version
- @version = version || '1.0'
- @encoding = encoding
- @standalone = standalone
- @output_encoding = nil
- end
-
- def output_encoding=(enc)
- @output_encoding = enc
- self.converter = Converter.new(@output_encoding, @encoding)
- end
-
- private
- 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
- end
-
- def ns_declaration(indent)
- rv = ''
- self.class::NSPOOL.each do |prefix, uri|
- prefix = ":#{prefix}" unless prefix.empty?
- rv << %Q|\n#{indent}xmlns#{prefix}="#{html_escape(uri)}"|
- end
- rv
- end
-
- end
+ end
end
diff --git a/lib/rss/syndication.rb b/lib/rss/syndication.rb
index aca39bb374..75f612864d 100644
--- a/lib/rss/syndication.rb
+++ b/lib/rss/syndication.rb
@@ -2,84 +2,84 @@ require "rss/1.0"
module RSS
- SY_PREFIX = 'sy'
- SY_URI = "http://purl.org/rss/1.0/modules/syndication/"
+ SY_PREFIX = 'sy'
+ SY_URI = "http://purl.org/rss/1.0/modules/syndication/"
- RDF.install_ns(SY_PREFIX, SY_URI)
+ RDF.install_ns(SY_PREFIX, SY_URI)
- module SyndicationModel
-
- extend BaseModel
-
- ELEMENTS = []
-
- def self.append_features(klass)
- super
-
- klass.module_eval(<<-EOC)
- %w(updatePeriod updateFrequency).each do |x|
- install_text_element("\#{SY_PREFIX}_\#{x}")
- end
+ module SyndicationModel
+
+ extend BaseModel
+
+ ELEMENTS = []
+
+ def self.append_features(klass)
+ super
+
+ klass.module_eval(<<-EOC)
+ %w(updatePeriod updateFrequency).each do |x|
+ install_text_element("\#{SY_PREFIX}_\#{x}")
+ end
- %w(updateBase).each do |x|
- install_date_element("\#{SY_PREFIX}_\#{x}", 'w3cdtf', x)
- end
+ %w(updateBase).each do |x|
+ install_date_element("\#{SY_PREFIX}_\#{x}", 'w3cdtf', x)
+ end
- alias_method(:_sy_updatePeriod=, :sy_updatePeriod=)
- def sy_updatePeriod=(new_value)
- new_value = new_value.strip
- validate_sy_updatePeriod(new_value) if @do_validate
- self._sy_updatePeriod = new_value
- end
+ alias_method(:_sy_updatePeriod=, :sy_updatePeriod=)
+ def sy_updatePeriod=(new_value)
+ new_value = new_value.strip
+ validate_sy_updatePeriod(new_value) if @do_validate
+ self._sy_updatePeriod = new_value
+ end
- alias_method(:_sy_updateFrequency=, :sy_updateFrequency=)
- def sy_updateFrequency=(new_value)
- new_value = new_value.strip
- validate_sy_updateFrequency(new_value) if @do_validate
- self._sy_updateFrequency = new_value.to_i
- end
- EOC
- end
+ alias_method(:_sy_updateFrequency=, :sy_updateFrequency=)
+ def sy_updateFrequency=(new_value)
+ new_value = new_value.strip
+ validate_sy_updateFrequency(new_value) if @do_validate
+ self._sy_updateFrequency = new_value.to_i
+ end
+ EOC
+ end
- def sy_validate(tags)
- counter = {}
- ELEMENTS.each do |x|
- counter[x] = 0
- end
+ def sy_validate(tags)
+ counter = {}
+ ELEMENTS.each do |x|
+ counter[x] = 0
+ end
- tags.each do |tag|
- key = "#{SY_PREFIX}_#{tag}"
- raise UnknownTagError.new(tag, SY_URI) unless counter.has_key?(key)
- counter[key] += 1
- raise TooMuchTagError.new(tag, tag_name) if counter[key] > 1
- end
- end
+ tags.each do |tag|
+ key = "#{SY_PREFIX}_#{tag}"
+ raise UnknownTagError.new(tag, SY_URI) unless counter.has_key?(key)
+ counter[key] += 1
+ raise TooMuchTagError.new(tag, tag_name) if counter[key] > 1
+ end
+ end
- private
- SY_UPDATEPERIOD_AVAILABLE_VALUES = %w(hourly daily weekly monthly yearly)
- def validate_sy_updatePeriod(value)
- unless SY_UPDATEPERIOD_AVAILABLE_VALUES.include?(value)
- raise NotAvailableValueError.new("updatePeriod", value)
- end
- end
+ private
+ SY_UPDATEPERIOD_AVAILABLE_VALUES = %w(hourly daily weekly monthly yearly)
+ def validate_sy_updatePeriod(value)
+ unless SY_UPDATEPERIOD_AVAILABLE_VALUES.include?(value)
+ raise NotAvailableValueError.new("updatePeriod", value)
+ end
+ end
- SY_UPDATEFREQUENCY_AVAILABLE_RE = /\A\s*\+?\d+\s*\z/
- def validate_sy_updateFrequency(value)
- if SY_UPDATEFREQUENCY_AVAILABLE_RE !~ value
- raise NotAvailableValueError.new("updateFrequency", value)
- end
- end
+ SY_UPDATEFREQUENCY_AVAILABLE_RE = /\A\s*\+?\d+\s*\z/
+ def validate_sy_updateFrequency(value)
+ if SY_UPDATEFREQUENCY_AVAILABLE_RE !~ value
+ raise NotAvailableValueError.new("updateFrequency", value)
+ end
+ end
- end
+ end
- class RDF
- class Channel; include SyndicationModel; end
- end
+ class RDF
+ class Channel; include SyndicationModel; end
+ end
- prefix_size = SY_PREFIX.size + 1
- SyndicationModel::ELEMENTS.uniq!
- SyndicationModel::ELEMENTS.each do |x|
- BaseListener.install_get_text_element(x[prefix_size..-1], SY_URI, "#{x}=")
- end
+ prefix_size = SY_PREFIX.size + 1
+ SyndicationModel::ELEMENTS.uniq!
+ SyndicationModel::ELEMENTS.each do |x|
+ BaseListener.install_get_text_element(x[prefix_size..-1], SY_URI, "#{x}=")
+ end
end
diff --git a/lib/rss/taxonomy.rb b/lib/rss/taxonomy.rb
index 5b11d338e0..bec6ea3c17 100644
--- a/lib/rss/taxonomy.rb
+++ b/lib/rss/taxonomy.rb
@@ -4,29 +4,29 @@ require "rss/1.0"
module RSS
- TAXO_PREFIX = "taxo"
- TAXO_NS = "http://purl.org/rss/1.0/modules/taxonomy/"
+ TAXO_PREFIX = "taxo"
+ TAXO_NS = "http://purl.org/rss/1.0/modules/taxonomy/"
- Element.install_ns(TAXO_PREFIX, TAXO_NS)
+ Element.install_ns(TAXO_PREFIX, TAXO_NS)
- TAXO_ELEMENTS = []
+ TAXO_ELEMENTS = []
- %w(link).each do |x|
- if const_defined? :Listener
- Listener.install_get_text_element(x, TAXO_NS, "#{TAXO_PREFIX}_#{x}=")
- end
- TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{x}"
- end
-
- module TaxonomyModel
- attr_writer(*%w(title description creator subject publisher
- contributor date format identifier source
- language relation coverage rights).collect{|x| "#{TAXO_PREFIX}_#{x}"})
- end
-
- class Channel; extend TaxonomyModel; end
- class Item; extend TaxonomyModel; end
- class Image; extend TaxonomyModel; end
- class TextInput; extend TaxonomyModel; end
-
+ %w(link).each do |x|
+ if const_defined? :Listener
+ Listener.install_get_text_element(x, TAXO_NS, "#{TAXO_PREFIX}_#{x}=")
+ end
+ TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{x}"
+ end
+
+ module TaxonomyModel
+ attr_writer(*%w(title description creator subject publisher
+ contributor date format identifier source
+ language relation coverage rights).collect{|x| "#{TAXO_PREFIX}_#{x}"})
+ end
+
+ class Channel; extend TaxonomyModel; end
+ class Item; extend TaxonomyModel; end
+ class Image; extend TaxonomyModel; end
+ class TextInput; extend TaxonomyModel; end
+
end
diff --git a/lib/rss/trackback.rb b/lib/rss/trackback.rb
index b427895aad..e276305ec1 100644
--- a/lib/rss/trackback.rb
+++ b/lib/rss/trackback.rb
@@ -3,304 +3,304 @@ require 'rss/2.0'
module RSS
- TRACKBACK_PREFIX = 'trackback'
- TRACKBACK_URI = 'http://madskills.com/public/xml/rss/module/trackback/'
-
- RDF.install_ns(TRACKBACK_PREFIX, TRACKBACK_URI)
- Rss.install_ns(TRACKBACK_PREFIX, TRACKBACK_URI)
-
- module BaseTrackBackModel
- def trackback_validate(tags)
- counter = {}
- %w(ping about).each do |x|
- counter["#{TRACKBACK_PREFIX}_#{x}"] = 0
- end
-
- tags.each do |tag|
- key = "#{TRACKBACK_PREFIX}_#{tag}"
- raise UnknownTagError.new(tag, TRACKBACK_URI) unless counter.has_key?(key)
- counter[key] += 1
- if tag != "about" and counter[key] > 1
- raise TooMuchTagError.new(tag, tag_name)
- end
- end
-
- if counter["#{TRACKBACK_PREFIX}_ping"].zero? and
- counter["#{TRACKBACK_PREFIX}_about"].nonzero?
- raise MissingTagError.new("#{TRACKBACK_PREFIX}:ping", tag_name)
- end
- end
- end
-
- module TrackBackModel10
- extend BaseModel
- include BaseTrackBackModel
-
- def self.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
-
- 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.install_have_child_element(var_name)
- klass.module_eval(<<-EOC)
- alias _#{var_name} #{var_name}
- def #{var_name}
- @#{var_name} and @#{var_name}.content
- end
-
- alias _#{var_name}= #{var_name}=
- def #{var_name}=(content)
- @#{var_name} = new_with_content_if_need(#{x.capitalize}, content)
- end
- EOC
- end
-
- [%w(about s)].each do |x, postfix|
- var_name = "#{TRACKBACK_PREFIX}_#{x}"
- klass.install_have_children_element(var_name)
- klass.module_eval(<<-EOC)
- alias _#{var_name}#{postfix} #{var_name}#{postfix}
- def #{var_name}#{postfix}
- @#{var_name}.collect {|x| x.content}
- end
-
- alias _#{var_name} #{var_name}
- def #{var_name}(*args)
- if args.empty?
- @#{var_name}.first and @#{var_name}.first.content
- else
- ret = @#{var_name}.send("[]", *args)
- if ret.is_a?(Array)
- ret.collect {|x| x.content}
- else
- ret.content
- end
- end
- end
-
- alias _#{var_name}= #{var_name}=
- alias _set_#{var_name} set_#{var_name}
- def #{var_name}=(*args)
- if args.size == 1
- item = new_with_content_if_need(#{x.capitalize}, args[0])
- @#{var_name}.push(item)
- else
- new_val = args.last
- if new_val.is_a?(Array)
- new_val = new_value.collect do |val|
- new_with_content_if_need(#{x.capitalize}, val)
- end
- else
- new_val = new_with_content_if_need(#{x.capitalize}, new_val)
- end
- @#{var_name}.send("[]=", *(args[0..-2] + [new_val]))
- end
- end
- alias set_#{var_name} #{var_name}=
- EOC
- end
- end
- end
-
- private
- def new_with_content(klass, content)
- obj = klass.new
- obj.content = content
- obj
- end
-
- def new_with_content_if_need(klass, content)
- if content.is_a?(klass)
- content
- else
- new_with_content(klass, content)
- end
- end
-
-
- class Ping < Element
- include RSS09
-
- content_setup
-
- class << self
-
- def required_prefix
- TRACKBACK_PREFIX
- end
-
- def required_uri
- TRACKBACK_URI
- end
-
- 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
-
- end
-
- class About < Element
- include RSS09
-
- content_setup
-
- class << self
-
- def required_prefix
- TRACKBACK_PREFIX
- end
-
- def required_uri
- TRACKBACK_URI
- 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
-
- end
- end
-
- class RDF
- class Item; include TrackBackModel10; end
- end
-
- class Rss
- class Channel
- class Item; include TrackBackModel20; end
- end
- end
+ TRACKBACK_PREFIX = 'trackback'
+ TRACKBACK_URI = 'http://madskills.com/public/xml/rss/module/trackback/'
+
+ RDF.install_ns(TRACKBACK_PREFIX, TRACKBACK_URI)
+ Rss.install_ns(TRACKBACK_PREFIX, TRACKBACK_URI)
+
+ module BaseTrackBackModel
+ def trackback_validate(tags)
+ counter = {}
+ %w(ping about).each do |x|
+ counter["#{TRACKBACK_PREFIX}_#{x}"] = 0
+ end
+
+ tags.each do |tag|
+ key = "#{TRACKBACK_PREFIX}_#{tag}"
+ raise UnknownTagError.new(tag, TRACKBACK_URI) unless counter.has_key?(key)
+ counter[key] += 1
+ if tag != "about" and counter[key] > 1
+ raise TooMuchTagError.new(tag, tag_name)
+ end
+ end
+
+ if counter["#{TRACKBACK_PREFIX}_ping"].zero? and
+ counter["#{TRACKBACK_PREFIX}_about"].nonzero?
+ raise MissingTagError.new("#{TRACKBACK_PREFIX}:ping", tag_name)
+ end
+ end
+ end
+
+ module TrackBackModel10
+ extend BaseModel
+ include BaseTrackBackModel
+
+ def self.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
+
+ 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.install_have_child_element(var_name)
+ klass.module_eval(<<-EOC)
+ alias _#{var_name} #{var_name}
+ def #{var_name}
+ @#{var_name} and @#{var_name}.content
+ end
+
+ alias _#{var_name}= #{var_name}=
+ def #{var_name}=(content)
+ @#{var_name} = new_with_content_if_need(#{x.capitalize}, content)
+ end
+ EOC
+ end
+
+ [%w(about s)].each do |x, postfix|
+ var_name = "#{TRACKBACK_PREFIX}_#{x}"
+ klass.install_have_children_element(var_name)
+ klass.module_eval(<<-EOC)
+ alias _#{var_name}#{postfix} #{var_name}#{postfix}
+ def #{var_name}#{postfix}
+ @#{var_name}.collect {|x| x.content}
+ end
+
+ alias _#{var_name} #{var_name}
+ def #{var_name}(*args)
+ if args.empty?
+ @#{var_name}.first and @#{var_name}.first.content
+ else
+ ret = @#{var_name}.send("[]", *args)
+ if ret.is_a?(Array)
+ ret.collect {|x| x.content}
+ else
+ ret.content
+ end
+ end
+ end
+
+ alias _#{var_name}= #{var_name}=
+ alias _set_#{var_name} set_#{var_name}
+ def #{var_name}=(*args)
+ if args.size == 1
+ item = new_with_content_if_need(#{x.capitalize}, args[0])
+ @#{var_name}.push(item)
+ else
+ new_val = args.last
+ if new_val.is_a?(Array)
+ new_val = new_value.collect do |val|
+ new_with_content_if_need(#{x.capitalize}, val)
+ end
+ else
+ new_val = new_with_content_if_need(#{x.capitalize}, new_val)
+ end
+ @#{var_name}.send("[]=", *(args[0..-2] + [new_val]))
+ end
+ end
+ alias set_#{var_name} #{var_name}=
+ EOC
+ end
+ end
+ end
+
+ private
+ def new_with_content(klass, content)
+ obj = klass.new
+ obj.content = content
+ obj
+ end
+
+ def new_with_content_if_need(klass, content)
+ if content.is_a?(klass)
+ content
+ else
+ new_with_content(klass, content)
+ end
+ end
+
+
+ class Ping < Element
+ include RSS09
+
+ content_setup
+
+ class << self
+
+ def required_prefix
+ TRACKBACK_PREFIX
+ end
+
+ def required_uri
+ TRACKBACK_URI
+ end
+
+ 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
+
+ end
+
+ class About < Element
+ include RSS09
+
+ content_setup
+
+ class << self
+
+ def required_prefix
+ TRACKBACK_PREFIX
+ end
+
+ def required_uri
+ TRACKBACK_URI
+ 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
+
+ end
+ end
+
+ class RDF
+ class Item; include TrackBackModel10; end
+ end
+
+ class Rss
+ class Channel
+ class Item; include TrackBackModel20; end
+ end
+ end
end
diff --git a/lib/rss/utils.rb b/lib/rss/utils.rb
index ae6f69bcf1..1c30ae74bc 100644
--- a/lib/rss/utils.rb
+++ b/lib/rss/utils.rb
@@ -1,17 +1,17 @@
module RSS
- module Utils
+ module Utils
- def get_file_and_line_from_caller(i=0)
- file, line, = caller[i].split(':')
- [file, line.to_i]
- end
+ def get_file_and_line_from_caller(i=0)
+ file, line, = caller[i].split(':')
+ [file, line.to_i]
+ end
- def html_escape(s)
- s.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
- end
- alias h html_escape
-
- end
+ def html_escape(s)
+ s.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
+ end
+ alias h html_escape
+
+ end
end
diff --git a/lib/rss/xml-stylesheet.rb b/lib/rss/xml-stylesheet.rb
index 7862c4f278..726899ed88 100644
--- a/lib/rss/xml-stylesheet.rb
+++ b/lib/rss/xml-stylesheet.rb
@@ -2,93 +2,93 @@ require "rss/utils"
module RSS
- module XMLStyleSheetMixin
- attr_accessor :xml_stylesheets
- def initialize(*args)
- super
- @xml_stylesheets = []
- end
-
- private
- def xml_stylesheet_pi
- xsss = @xml_stylesheets.collect do |xss|
- pi = xss.to_s
- pi = nil if /\A\s*\z/ =~ pi
- pi
- end.compact
- xsss.push("") unless xsss.empty?
- xsss.join("\n")
- end
- end
+ module XMLStyleSheetMixin
+ attr_accessor :xml_stylesheets
+ def initialize(*args)
+ super
+ @xml_stylesheets = []
+ end
+
+ private
+ def xml_stylesheet_pi
+ xsss = @xml_stylesheets.collect do |xss|
+ pi = xss.to_s
+ pi = nil if /\A\s*\z/ =~ pi
+ pi
+ end.compact
+ xsss.push("") unless xsss.empty?
+ xsss.join("\n")
+ end
+ end
- class XMLStyleSheet
+ class XMLStyleSheet
- include Utils
+ include Utils
- ATTRIBUTES = %w(href type title media charset alternate)
+ ATTRIBUTES = %w(href type title media charset alternate)
- GUESS_TABLE = {
- "xsl" => "text/xsl",
- "css" => "text/css",
- }
+ GUESS_TABLE = {
+ "xsl" => "text/xsl",
+ "css" => "text/css",
+ }
- attr_accessor(*ATTRIBUTES)
- attr_accessor(:do_validate)
- def initialize(*attrs)
- @do_validate = true
- ATTRIBUTES.each do |attr|
- self.send("#{attr}=", nil)
- end
- vars = ATTRIBUTES.dup
- vars.unshift(:do_validate)
- attrs.each do |name, value|
- if vars.include?(name.to_s)
- self.send("#{name}=", value)
- end
- end
- end
+ attr_accessor(*ATTRIBUTES)
+ attr_accessor(:do_validate)
+ def initialize(*attrs)
+ @do_validate = true
+ ATTRIBUTES.each do |attr|
+ self.send("#{attr}=", nil)
+ end
+ vars = ATTRIBUTES.dup
+ vars.unshift(:do_validate)
+ attrs.each do |name, value|
+ if vars.include?(name.to_s)
+ self.send("#{name}=", value)
+ end
+ end
+ end
- def to_s
- rv = ""
- if @href
- rv << %Q[<?xml-stylesheet]
- ATTRIBUTES.each do |name|
- if self.send(name)
- rv << %Q[ #{name}="#{h self.send(name)}"]
- end
- end
- rv << %Q[?>]
- end
- rv
- end
+ def to_s
+ rv = ""
+ if @href
+ rv << %Q[<?xml-stylesheet]
+ ATTRIBUTES.each do |name|
+ if self.send(name)
+ rv << %Q[ #{name}="#{h self.send(name)}"]
+ end
+ end
+ rv << %Q[?>]
+ end
+ rv
+ end
- remove_method(:href=)
- def href=(value)
- @href = value
- if @href and @type.nil?
- @type = guess_type(@href)
- end
- @href
- end
+ remove_method(:href=)
+ def href=(value)
+ @href = value
+ if @href and @type.nil?
+ @type = guess_type(@href)
+ end
+ @href
+ end
- remove_method(:alternate=)
- def alternate=(value)
- if value.nil? or /\A(?:yes|no)\z/ =~ value
- @alternate = value
- else
- if @do_validate
- args = ["?xml-stylesheet?", %Q[alternate="#{value}"]]
- raise NotAvailableValueError.new(*args)
- end
- end
- @alternate
- end
+ remove_method(:alternate=)
+ def alternate=(value)
+ if value.nil? or /\A(?:yes|no)\z/ =~ value
+ @alternate = value
+ else
+ if @do_validate
+ args = ["?xml-stylesheet?", %Q[alternate="#{value}"]]
+ raise NotAvailableValueError.new(*args)
+ end
+ end
+ @alternate
+ end
- private
- def guess_type(filename)
- /\.([^.]+)/ =~ filename
- GUESS_TABLE[$1]
- end
+ private
+ def guess_type(filename)
+ /\.([^.]+)/ =~ filename
+ GUESS_TABLE[$1]
+ end
- end
+ end
end
diff --git a/lib/rss/xmlparser.rb b/lib/rss/xmlparser.rb
index 7be0dc9a11..64737b821b 100644
--- a/lib/rss/xmlparser.rb
+++ b/lib/rss/xmlparser.rb
@@ -1,91 +1,91 @@
begin
- require "xml/parser"
+ require "xml/parser"
rescue LoadError
- require "xmlparser"
+ require "xmlparser"
end
begin
- require "xml/encoding-ja"
+ require "xml/encoding-ja"
rescue LoadError
- require "xmlencoding-ja"
- if defined?(Kconv)
- module XMLEncoding_ja
- class SJISHandler
- include Kconv
- end
- end
- end
+ require "xmlencoding-ja"
+ if defined?(Kconv)
+ module XMLEncoding_ja
+ class SJISHandler
+ include Kconv
+ end
+ end
+ end
end
module XML
- class Parser
- unless defined?(Error)
- Error = ::XMLParserError
- end
- end
+ class Parser
+ unless defined?(Error)
+ Error = ::XMLParserError
+ end
+ end
end
module RSS
-
- class REXMLLikeXMLParser < ::XML::Parser
-
- include ::XML::Encoding_ja
+
+ class REXMLLikeXMLParser < ::XML::Parser
+
+ include ::XML::Encoding_ja
- def listener=(listener)
- @listener = listener
- end
+ def listener=(listener)
+ @listener = listener
+ end
- def startElement(name, attrs)
- @listener.tag_start(name, attrs)
- end
-
- def endElement(name)
- @listener.tag_end(name)
- end
+ def startElement(name, attrs)
+ @listener.tag_start(name, attrs)
+ end
+
+ def endElement(name)
+ @listener.tag_end(name)
+ end
- def character(data)
- @listener.text(data)
- end
+ def character(data)
+ @listener.text(data)
+ end
- def xmlDecl(version, encoding, standalone)
- @listener.xmldecl(version, encoding, standalone == 1)
- end
+ def xmlDecl(version, encoding, standalone)
+ @listener.xmldecl(version, encoding, standalone == 1)
+ end
- def processingInstruction(target, content)
- @listener.instruction(target, content)
- end
+ def processingInstruction(target, content)
+ @listener.instruction(target, content)
+ end
- end
+ end
- class XMLParserParser < BaseParser
+ class XMLParserParser < BaseParser
- private
- def listener
- XMLParserListener
- end
+ private
+ def listener
+ XMLParserListener
+ end
- def _parse
- begin
- parser = REXMLLikeXMLParser.new
- parser.listener = @listener
- parser.parse(@rss)
- rescue ::XML::Parser::Error => e
- raise NotWellFormedError.new(parser.line){e.message}
- end
- end
-
- end
-
- class XMLParserListener < BaseListener
+ def _parse
+ begin
+ parser = REXMLLikeXMLParser.new
+ parser.listener = @listener
+ parser.parse(@rss)
+ rescue ::XML::Parser::Error => e
+ raise NotWellFormedError.new(parser.line){e.message}
+ end
+ end
+
+ end
+
+ class XMLParserListener < BaseListener
- include ListenerMixin
-
- def xmldecl(version, encoding, standalone)
- super
- # Encoding is converted to UTF-8 when XMLParser parses XML.
- @encoding = 'UTF-8'
- end
+ include ListenerMixin
+
+ def xmldecl(version, encoding, standalone)
+ super
+ # Encoding is converted to UTF-8 when XMLParser parses XML.
+ @encoding = 'UTF-8'
+ end
- end
+ end
end
diff --git a/lib/rss/xmlscanner.rb b/lib/rss/xmlscanner.rb
index 4ab997062d..472ca93523 100644
--- a/lib/rss/xmlscanner.rb
+++ b/lib/rss/xmlscanner.rb
@@ -1,102 +1,102 @@
require 'xmlscan/scanner'
module RSS
-
- class XMLScanParser < BaseParser
-
- private
- def listener
- XMLScanListener
- end
-
- def _parse
- begin
- XMLScan::XMLScanner.new(@listener).parse(@rss)
- rescue XMLScan::Error => e
- raise NotWellFormedError.new(e.lineno){e.message}
- end
- end
-
- end
-
- class XMLScanListener < BaseListener
-
- include XMLScan::Visitor
- include ListenerMixin
-
- ENTITIES = {
- 'lt' => '<',
- 'gt' => '>',
- 'amp' => '&',
- 'quot' => '"',
- 'apos' => '\''
- }
+
+ class XMLScanParser < BaseParser
+
+ private
+ def listener
+ XMLScanListener
+ end
+
+ def _parse
+ begin
+ XMLScan::XMLScanner.new(@listener).parse(@rss)
+ rescue XMLScan::Error => e
+ raise NotWellFormedError.new(e.lineno){e.message}
+ end
+ end
+
+ end
+
+ class XMLScanListener < BaseListener
+
+ include XMLScan::Visitor
+ include ListenerMixin
+
+ ENTITIES = {
+ 'lt' => '<',
+ 'gt' => '>',
+ 'amp' => '&',
+ 'quot' => '"',
+ 'apos' => '\''
+ }
def on_xmldecl_version(str)
- @version = str
+ @version = str
end
def on_xmldecl_encoding(str)
- @encoding = str
+ @encoding = str
end
def on_xmldecl_standalone(str)
- @standalone = str
+ @standalone = str
end
def on_xmldecl_end
- xmldecl(@version, @encoding, @standalone)
+ xmldecl(@version, @encoding, @standalone)
end
- alias_method(:on_pi, :instruction)
- alias_method(:on_chardata, :text)
- alias_method(:on_cdata, :text)
+ alias_method(:on_pi, :instruction)
+ alias_method(:on_chardata, :text)
+ alias_method(:on_cdata, :text)
def on_etag(name)
tag_end(name)
end
def on_entityref(ref)
- text(ENTITIES[ref])
+ text(ENTITIES[ref])
end
def on_charref(code)
- text([code].pack('U'))
+ text([code].pack('U'))
end
- alias_method(:on_charref_hex, :on_charref)
+ alias_method(:on_charref_hex, :on_charref)
def on_stag(name)
- @attrs = {}
+ @attrs = {}
end
def on_attribute(name)
- @attrs[name] = @current_attr = ''
+ @attrs[name] = @current_attr = ''
end
def on_attr_value(str)
- @current_attr << str
+ @current_attr << str
end
def on_attr_entityref(ref)
- @current_attr << ENTITIES[ref]
+ @current_attr << ENTITIES[ref]
end
def on_attr_charref(code)
- @current_attr << [code].pack('U')
+ @current_attr << [code].pack('U')
end
- alias_method(:on_attr_charref_hex, :on_attr_charref)
+ alias_method(:on_attr_charref_hex, :on_attr_charref)
def on_stag_end(name)
- tag_start(name, @attrs)
+ tag_start(name, @attrs)
end
def on_stag_end_empty(name)
- tag_start(name, @attrs)
- tag_end(name)
+ tag_start(name, @attrs)
+ tag_end(name)
end
- end
+ end
end
diff --git a/test/rss/rss-assertions.rb b/test/rss/rss-assertions.rb
index ad7da1f6b4..40a72e93cd 100644
--- a/test/rss/rss-assertions.rb
+++ b/test/rss/rss-assertions.rb
@@ -1,139 +1,139 @@
# -*- tab-width: 2 -*- vim: ts=2
module Test
- module Unit
- module Assertions
- # For backward compatibility
- unless instance_methods.include?("assert_raise")
- def assert_raise(*args, &block)
- assert_raises(*args, &block)
- end
- end
- end
- end
+ module Unit
+ module Assertions
+ # For backward compatibility
+ unless instance_methods.include?("assert_raise")
+ def assert_raise(*args, &block)
+ assert_raises(*args, &block)
+ end
+ end
+ end
+ end
end
module RSS
- module Assertions
-
- def assert_parse(rss, assert_method, *args)
- send("assert_#{assert_method}", *args) do
- ::RSS::Parser.parse(rss)
- end
- send("assert_#{assert_method}", *args) do
- ::RSS::Parser.parse(rss, false).validate
- end
- end
-
- def assert_ns(prefix, uri)
- _wrap_assertion do
- begin
- yield
- flunk("Not raise NSError")
- rescue ::RSS::NSError => e
- assert_equal(prefix, e.prefix)
- assert_equal(uri, e.uri)
- end
- end
- end
-
- def assert_missing_tag(tag, parent)
- _wrap_assertion do
- begin
- yield
- flunk("Not raise MissingTagError")
- rescue ::RSS::MissingTagError => e
- assert_equal(tag, e.tag)
- assert_equal(parent, e.parent)
- end
- end
- end
-
- def assert_too_much_tag(tag, parent)
- _wrap_assertion do
- begin
- yield
- flunk("Not raise TooMuchTagError")
- rescue ::RSS::TooMuchTagError => e
- assert_equal(tag, e.tag)
- assert_equal(parent, e.parent)
- end
- end
- end
-
- def assert_missing_attribute(tag, attrname)
- _wrap_assertion do
- begin
- yield
- flunk("Not raise MissingAttributeError")
- rescue ::RSS::MissingAttributeError => e
- assert_equal(tag, e.tag)
- assert_equal(attrname, e.attribute)
- end
- end
- end
-
- def assert_not_excepted_tag(tag, parent)
- _wrap_assertion do
- begin
- yield
- flunk("Not raise NotExceptedTagError")
- rescue ::RSS::NotExceptedTagError => e
- assert_equal(tag, e.tag)
- assert_equal(parent, e.parent)
- end
- end
- end
-
- def assert_not_available_value(tag, value)
- _wrap_assertion do
- begin
- yield
- flunk("Not raise NotAvailableValueError")
- rescue ::RSS::NotAvailableValueError => e
- assert_equal(tag, e.tag)
- assert_equal(value, e.value)
- end
- end
- end
-
- def assert_xml_stylesheet_attrs(xsl, attrs)
- _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))
- end
- end
- end
-
- def assert_xml_stylesheet(target, xsl, attrs)
- _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)
- else
- assert_nil(target)
- assert_equal("", xsl.to_s)
- end
- end
- 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)
- end
- pi_str = rdf.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s*<rdf:RDF.*\z/m, "")
- assert_equal(xss_strs.join("\n"), pi_str)
- end
-
- end
+ module Assertions
+
+ def assert_parse(rss, assert_method, *args)
+ send("assert_#{assert_method}", *args) do
+ ::RSS::Parser.parse(rss)
+ end
+ send("assert_#{assert_method}", *args) do
+ ::RSS::Parser.parse(rss, false).validate
+ end
+ end
+
+ def assert_ns(prefix, uri)
+ _wrap_assertion do
+ begin
+ yield
+ flunk("Not raise NSError")
+ rescue ::RSS::NSError => e
+ assert_equal(prefix, e.prefix)
+ assert_equal(uri, e.uri)
+ end
+ end
+ end
+
+ def assert_missing_tag(tag, parent)
+ _wrap_assertion do
+ begin
+ yield
+ flunk("Not raise MissingTagError")
+ rescue ::RSS::MissingTagError => e
+ assert_equal(tag, e.tag)
+ assert_equal(parent, e.parent)
+ end
+ end
+ end
+
+ def assert_too_much_tag(tag, parent)
+ _wrap_assertion do
+ begin
+ yield
+ flunk("Not raise TooMuchTagError")
+ rescue ::RSS::TooMuchTagError => e
+ assert_equal(tag, e.tag)
+ assert_equal(parent, e.parent)
+ end
+ end
+ end
+
+ def assert_missing_attribute(tag, attrname)
+ _wrap_assertion do
+ begin
+ yield
+ flunk("Not raise MissingAttributeError")
+ rescue ::RSS::MissingAttributeError => e
+ assert_equal(tag, e.tag)
+ assert_equal(attrname, e.attribute)
+ end
+ end
+ end
+
+ def assert_not_excepted_tag(tag, parent)
+ _wrap_assertion do
+ begin
+ yield
+ flunk("Not raise NotExceptedTagError")
+ rescue ::RSS::NotExceptedTagError => e
+ assert_equal(tag, e.tag)
+ assert_equal(parent, e.parent)
+ end
+ end
+ end
+
+ def assert_not_available_value(tag, value)
+ _wrap_assertion do
+ begin
+ yield
+ flunk("Not raise NotAvailableValueError")
+ rescue ::RSS::NotAvailableValueError => e
+ assert_equal(tag, e.tag)
+ assert_equal(value, e.value)
+ end
+ end
+ end
+
+ def assert_xml_stylesheet_attrs(xsl, attrs)
+ _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))
+ end
+ end
+ end
+
+ def assert_xml_stylesheet(target, xsl, attrs)
+ _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)
+ else
+ assert_nil(target)
+ assert_equal("", xsl.to_s)
+ end
+ end
+ 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)
+ end
+ pi_str = rdf.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s*<rdf:RDF.*\z/m, "")
+ assert_equal(xss_strs.join("\n"), pi_str)
+ end
+
+ end
end
diff --git a/test/rss/rss-testcase.rb b/test/rss/rss-testcase.rb
index e7195f41be..098263a392 100644
--- a/test/rss/rss-testcase.rb
+++ b/test/rss/rss-testcase.rb
@@ -4,182 +4,182 @@ require "test/unit"
require 'rss-assertions'
module RSS
- class TestCase < Test::Unit::TestCase
-
- include RSS
- include Assertions
-
- XMLDECL_VERSION = "1.0"
- XMLDECL_ENCODING = "UTF-8"
- XMLDECL_STANDALONE = "no"
-
- RDF_ABOUT = "http://www.xml.com/xml/news.rss"
- RDF_RESOURCE = "http://xml.com/universal/images/xml_tiny.gif"
- TITLE_VALUE = "XML.com"
- LINK_VALUE = "http://xml.com/pub"
- URL_VALUE = "http://xml.com/universal/images/xml_tiny.gif"
- NAME_VALUE = "hogehoge"
- LANGUAGE_VALUE = "ja"
- DESCRIPTION_VALUE = "
+ class TestCase < Test::Unit::TestCase
+
+ include RSS
+ include Assertions
+
+ XMLDECL_VERSION = "1.0"
+ XMLDECL_ENCODING = "UTF-8"
+ XMLDECL_STANDALONE = "no"
+
+ RDF_ABOUT = "http://www.xml.com/xml/news.rss"
+ RDF_RESOURCE = "http://xml.com/universal/images/xml_tiny.gif"
+ TITLE_VALUE = "XML.com"
+ LINK_VALUE = "http://xml.com/pub"
+ URL_VALUE = "http://xml.com/universal/images/xml_tiny.gif"
+ NAME_VALUE = "hogehoge"
+ LANGUAGE_VALUE = "ja"
+ DESCRIPTION_VALUE = "
XML.com features a rich mix of information and services
for the XML community.
- "
- RESOURCES = [
- "http://xml.com/pub/2000/08/09/xslt/xslt.html",
- "http://xml.com/pub/2000/08/09/rdfdb/index.html",
- ]
-
- CLOUD_DOMAIN = "data.ourfavoritesongs.com"
- CLOUD_PORT = "80"
- CLOUD_PATH = "/RPC2"
- CLOUD_REGISTER_PROCEDURE = "ourFavoriteSongs.rssPleaseNotify"
- CLOUD_PROTOCOL = "xml-rpc"
-
- ENCLOSURE_URL = "http://www.scripting.com/mp3s/weatherReportSuite.mp3"
- ENCLOSURE_LENGTH = "12216320"
- ENCLOSURE_TYPE = "audio/mpeg"
-
- CATEGORY_DOMAIN = "http://www.superopendirectory.com/"
-
- def default_test
- # This class isn't tested
- end
-
- private
- def make_xmldecl(v=XMLDECL_VERSION, e=XMLDECL_ENCODING, s=XMLDECL_STANDALONE)
- rv = "<?xml version='#{v}'"
- rv << " encoding='#{e}'" if e
- rv << " standalone='#{s}'" if s
- rv << "?>"
- rv
- end
-
- def make_RDF(content=nil, xmlns=[])
- <<-EORSS
+ "
+ RESOURCES = [
+ "http://xml.com/pub/2000/08/09/xslt/xslt.html",
+ "http://xml.com/pub/2000/08/09/rdfdb/index.html",
+ ]
+
+ CLOUD_DOMAIN = "data.ourfavoritesongs.com"
+ CLOUD_PORT = "80"
+ CLOUD_PATH = "/RPC2"
+ CLOUD_REGISTER_PROCEDURE = "ourFavoriteSongs.rssPleaseNotify"
+ CLOUD_PROTOCOL = "xml-rpc"
+
+ ENCLOSURE_URL = "http://www.scripting.com/mp3s/weatherReportSuite.mp3"
+ ENCLOSURE_LENGTH = "12216320"
+ ENCLOSURE_TYPE = "audio/mpeg"
+
+ CATEGORY_DOMAIN = "http://www.superopendirectory.com/"
+
+ def default_test
+ # This class isn't tested
+ end
+
+ private
+ def make_xmldecl(v=XMLDECL_VERSION, e=XMLDECL_ENCODING, s=XMLDECL_STANDALONE)
+ rv = "<?xml version='#{v}'"
+ rv << " encoding='#{e}'" if e
+ rv << " standalone='#{s}'" if s
+ rv << "?>"
+ rv
+ end
+
+ def make_RDF(content=nil, xmlns=[])
+ <<-EORSS
#{make_xmldecl}
<rdf:RDF xmlns="#{URI}" xmlns:rdf="#{RDF::URI}"
#{xmlns.collect {|pre, uri| "xmlns:#{pre}='#{uri}'"}.join(' ')}>
#{block_given? ? yield : content}
</rdf:RDF>
EORSS
- end
+ end
- def make_channel(content=nil)
- <<-EOC
+ def make_channel(content=nil)
+ <<-EOC
<channel rdf:about="#{RDF_ABOUT}">
- <title>#{TITLE_VALUE}</title>
- <link>#{LINK_VALUE}</link>
- <description>#{DESCRIPTION_VALUE}</description>
+ <title>#{TITLE_VALUE}</title>
+ <link>#{LINK_VALUE}</link>
+ <description>#{DESCRIPTION_VALUE}</description>
- <image rdf:resource="#{RDF_RESOURCE}" />
+ <image rdf:resource="#{RDF_RESOURCE}" />
- <items>
- <rdf:Seq>
+ <items>
+ <rdf:Seq>
#{RESOURCES.collect do |res| '<rdf:li resource="' + res + '" />' end.join("\n")}
- </rdf:Seq>
- </items>
+ </rdf:Seq>
+ </items>
- <textinput rdf:resource="#{RDF_RESOURCE}" />
+ <textinput rdf:resource="#{RDF_RESOURCE}" />
#{block_given? ? yield : content}
</channel>
EOC
- end
+ end
- def make_image(content=nil)
- <<-EOI
+ def make_image(content=nil)
+ <<-EOI
<image rdf:about="#{RDF_ABOUT}">
- <title>#{TITLE_VALUE}</title>
- <url>#{URL_VALUE}</url>
- <link>#{LINK_VALUE}</link>
+ <title>#{TITLE_VALUE}</title>
+ <url>#{URL_VALUE}</url>
+ <link>#{LINK_VALUE}</link>
#{block_given? ? yield : content}
</image>
EOI
- end
+ end
- def make_item(content=nil)
- <<-EOI
+ def make_item(content=nil)
+ <<-EOI
<item rdf:about="#{RDF_ABOUT}">
- <title>#{TITLE_VALUE}</title>
- <link>#{LINK_VALUE}</link>
- <description>#{DESCRIPTION_VALUE}</description>
+ <title>#{TITLE_VALUE}</title>
+ <link>#{LINK_VALUE}</link>
+ <description>#{DESCRIPTION_VALUE}</description>
#{block_given? ? yield : content}
</item>
EOI
- end
+ end
- def make_textinput(content=nil)
- <<-EOT
+ def make_textinput(content=nil)
+ <<-EOT
<textinput rdf:about="#{RDF_ABOUT}">
- <title>#{TITLE_VALUE}</title>
- <description>#{DESCRIPTION_VALUE}</description>
- <name>#{NAME_VALUE}</name>
- <link>#{LINK_VALUE}</link>
+ <title>#{TITLE_VALUE}</title>
+ <description>#{DESCRIPTION_VALUE}</description>
+ <name>#{NAME_VALUE}</name>
+ <link>#{LINK_VALUE}</link>
#{block_given? ? yield : content}
</textinput>
EOT
- end
+ end
- def make_sample_RDF
- make_RDF(<<-EOR)
+ def make_sample_RDF
+ make_RDF(<<-EOR)
#{make_channel}
#{make_image}
#{make_item}
#{make_textinput}
EOR
- end
+ end
- def make_rss20(content=nil, xmlns=[])
- <<-EORSS
+ def make_rss20(content=nil, xmlns=[])
+ <<-EORSS
#{make_xmldecl}
<rss version="2.0"
#{xmlns.collect {|pre, uri| "xmlns:#{pre}='#{uri}'"}.join(' ')}>
#{block_given? ? yield : content}
</rss>
EORSS
- end
+ end
- def make_channel20(content=nil)
- <<-EOC
+ def make_channel20(content=nil)
+ <<-EOC
<channel>
- <title>#{TITLE_VALUE}</title>
- <link>#{LINK_VALUE}</link>
- <description>#{DESCRIPTION_VALUE}</description>
- <language>#{LANGUAGE_VALUE}</language>
+ <title>#{TITLE_VALUE}</title>
+ <link>#{LINK_VALUE}</link>
+ <description>#{DESCRIPTION_VALUE}</description>
+ <language>#{LANGUAGE_VALUE}</language>
- <image>
- <url>#{RDF_RESOURCE}</url>
- <title>#{TITLE_VALUE}</title>
- <link>#{LINK_VALUE}</link>
- </image>
+ <image>
+ <url>#{RDF_RESOURCE}</url>
+ <title>#{TITLE_VALUE}</title>
+ <link>#{LINK_VALUE}</link>
+ </image>
#{RESOURCES.collect do |res| '<item><link>' + res + '</link></item>' end.join("\n")}
- <textInput>
- <title>#{TITLE_VALUE}</title>
- <description>#{DESCRIPTION_VALUE}</description>
- <name>#{NAME_VALUE}</name>
- <link>#{RDF_RESOURCE}</link>
- </textInput>
+ <textInput>
+ <title>#{TITLE_VALUE}</title>
+ <description>#{DESCRIPTION_VALUE}</description>
+ <name>#{NAME_VALUE}</name>
+ <link>#{RDF_RESOURCE}</link>
+ </textInput>
#{block_given? ? yield : content}
</channel>
EOC
- end
+ end
- def make_item20(content=nil)
- <<-EOI
+ def make_item20(content=nil)
+ <<-EOI
<item>
- <title>#{TITLE_VALUE}</title>
- <link>#{LINK_VALUE}</link>
- <description>#{DESCRIPTION_VALUE}</description>
+ <title>#{TITLE_VALUE}</title>
+ <link>#{LINK_VALUE}</link>
+ <description>#{DESCRIPTION_VALUE}</description>
#{block_given? ? yield : content}
</item>
EOI
- end
+ end
- def make_cloud20
- <<-EOC
+ def make_cloud20
+ <<-EOC
<cloud
domain="#{CLOUD_DOMAIN}"
port="#{CLOUD_PORT}"
@@ -187,7 +187,7 @@ EOI
registerProcedure="#{CLOUD_REGISTER_PROCEDURE}"
protocol="#{CLOUD_PROTOCOL}" />
EOC
- end
+ end
- end
+ end
end
diff --git a/test/rss/test_1.0.rb b/test/rss/test_1.0.rb
index 0ea3e884d8..43a168d035 100644
--- a/test/rss/test_1.0.rb
+++ b/test/rss/test_1.0.rb
@@ -7,264 +7,264 @@ require "rss-testcase"
require "rss/1.0"
module RSS
- class TestCore < TestCase
-
- def setup
-
- @rdf_prefix = "rdf"
- @rdf_uri = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- @uri = "http://purl.org/rss/1.0/"
-
- end
-
- def test_RDF
-
- version = "1.0"
- encoding = "UTF-8"
- standalone = "no"
-
- rdf = RDF.new(version, encoding, standalone)
-
- doc = REXML::Document.new(rdf.to_s(false))
-
- xmldecl = doc.xml_decl
-
- %w(version encoding standalone).each do |x|
- assert_equal(instance_eval(x), xmldecl.send(x))
- end
-
- assert_equal(@rdf_uri, doc.root.namespace)
-
- end
-
- def test_not_displayed_xml_stylesheets
- rdf = RDF.new()
- plain_rdf = rdf.to_s
- 3.times do
- rdf.xml_stylesheets.push(XMLStyleSheet.new)
- assert_equal(plain_rdf, rdf.to_s)
- end
- end
-
- def test_xml_stylesheets
- [
- [{:href => "a.xsl", :type => "text/xsl"}],
- [
- {:href => "a.xsl", :type => "text/xsl"},
- {:href => "a.css", :type => "text/css"},
- ],
- ].each do |attrs_ary|
- assert_xml_stylesheet_pis(attrs_ary)
- end
- end
-
- def test_channel
- about = "http://hoge.com"
- title = "fugafuga"
- link = "http://hoge.com"
- description = "fugafugafugafuga"
- resource = "http://hoge.com/hoge.png"
- image = RDF::Channel::Image.new(resource)
- items = RDF::Channel::Items.new
- textinput = RDF::Channel::Textinput.new(resource)
-
- channel = RDF::Channel.new(about)
- %w(title link description image items textinput).each do |x|
- channel.send("#{x}=", instance_eval(x))
- end
-
- doc = REXML::Document.new(make_RDF(channel.to_s))
- c = doc.root.elements[1]
-
- assert_equal(about, c.attributes["about"])
- %w(title link description image textinput).each do |x|
- elem = c.elements[x]
- assert_equal(x, elem.name)
- assert_equal(@uri, elem.namespace)
- if x == "image" or x == "textinput"
- excepted = resource
- res = elem.attributes.get_attribute("resource")
- assert_equal(@rdf_uri, res.namespace)
- value = res.value
- else
- excepted = instance_eval(x)
- value = elem.text
- end
- assert_equal(excepted, value)
- end
- assert_equal(@uri, c.elements["items"].namespace)
- assert_equal("items", c.elements["items"].name)
-
- end
-
- def test_channel_image
-
- resource = "http://hoge.com/hoge.png"
- image = RDF::Channel::Image.new(resource)
-
- doc = REXML::Document.new(make_RDF(image.to_s))
- i = doc.root.elements[1]
-
- assert_equal("image", i.name)
- assert_equal(@uri, i.namespace)
-
- res = i.attributes.get_attribute("resource")
-
- assert_equal(@rdf_uri, res.namespace)
- assert_equal(resource, res.value)
-
- end
-
- def test_channel_textinput
-
- resource = "http://hoge.com/hoge.png"
- textinput = RDF::Channel::Textinput.new(resource)
-
- doc = REXML::Document.new(make_RDF(textinput.to_s))
- t = doc.root.elements[1]
-
- assert_equal("textinput", t.name)
- assert_equal(@uri, t.namespace)
-
- res = t.attributes.get_attribute("resource")
-
- assert_equal(@rdf_uri, res.namespace)
- assert_equal(resource, res.value)
-
- end
-
- def test_items
-
- items = RDF::Channel::Items.new
-
- doc = REXML::Document.new(make_RDF(items.to_s))
- i = doc.root.elements[1]
-
- assert_equal("items", i.name)
- assert_equal(@uri, i.namespace)
-
- assert_equal(1, i.elements.size)
- assert_equal("Seq", i.elements[1].name)
- assert_equal(@rdf_uri, i.elements[1].namespace)
-
- end
-
- def test_seq
-
- seq = RDF::Seq.new
-
- doc = REXML::Document.new(make_RDF(seq.to_s))
- s = doc.root.elements[1]
-
- assert_equal("Seq", s.name)
- assert_equal(@rdf_uri, s.namespace)
-
- end
-
- def test_li
-
- resource = "http://hoge.com/"
- li = RDF::Li.new(resource)
-
- doc = REXML::Document.new(make_RDF(li.to_s))
- l = doc.root.elements[1]
-
- assert_equal("li", l.name)
- assert_equal(@rdf_uri, l.namespace(l.prefix))
-
- res = l.attributes.get_attribute("resource")
-
- assert_equal('', res.instance_eval("@prefix"))
- assert_equal(resource, res.value)
-
- end
-
- def test_image
-
- about = "http://hoge.com"
- title = "fugafuga"
- url = "http://hoge.com/hoge"
- link = "http://hoge.com/fuga"
-
- image = RDF::Image.new(about)
- %w(title url link).each do |x|
- image.send("#{x}=", instance_eval(x))
- end
-
- doc = REXML::Document.new(make_RDF(image.to_s))
- i = doc.root.elements[1]
-
- assert_equal(about, i.attributes["about"])
- %w(title url link).each do |x|
- elem = i.elements[x]
- assert_equal(x, elem.name)
- assert_equal(@uri, elem.namespace)
- assert_equal(instance_eval(x), elem.text)
- end
-
- end
-
- def test_item
-
- about = "http://hoge.com"
- title = "fugafuga"
- link = "http://hoge.com/fuga"
- description = "hogehogehoge"
-
- item = RDF::Item.new(about)
- %w(title link description).each do |x|
- item.send("#{x}=", instance_eval(x))
- end
-
- doc = REXML::Document.new(make_RDF(item.to_s))
- i = doc.root.elements[1]
-
- assert_equal(about, i.attributes["about"])
- %w(title link description).each do |x|
- elem = i.elements[x]
- assert_equal(x, elem.name)
- assert_equal(@uri, elem.namespace)
- assert_equal(instance_eval(x), elem.text)
- end
-
- end
-
- def test_textinput
-
- about = "http://hoge.com"
- title = "fugafuga"
- link = "http://hoge.com/fuga"
- name = "foo"
- description = "hogehogehoge"
-
- textinput = RDF::Textinput.new(about)
- %w(title link name description).each do |x|
- textinput.send("#{x}=", instance_eval(x))
- end
-
- doc = REXML::Document.new(make_RDF(textinput.to_s))
- t = doc.root.elements[1]
-
- assert_equal(about, t.attributes["about"])
- %w(title link name description).each do |x|
- elem = t.elements[x]
- assert_equal(x, elem.name)
- assert_equal(@uri, elem.namespace)
- assert_equal(instance_eval(x), elem.text)
- end
-
- end
+ class TestCore < TestCase
+
+ def setup
+
+ @rdf_prefix = "rdf"
+ @rdf_uri = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ @uri = "http://purl.org/rss/1.0/"
+
+ end
+
+ def test_RDF
+
+ version = "1.0"
+ encoding = "UTF-8"
+ standalone = "no"
+
+ rdf = RDF.new(version, encoding, standalone)
+
+ doc = REXML::Document.new(rdf.to_s(false))
+
+ xmldecl = doc.xml_decl
+
+ %w(version encoding standalone).each do |x|
+ assert_equal(instance_eval(x), xmldecl.send(x))
+ end
+
+ assert_equal(@rdf_uri, doc.root.namespace)
+
+ end
+
+ def test_not_displayed_xml_stylesheets
+ rdf = RDF.new()
+ plain_rdf = rdf.to_s
+ 3.times do
+ rdf.xml_stylesheets.push(XMLStyleSheet.new)
+ assert_equal(plain_rdf, rdf.to_s)
+ end
+ end
+
+ def test_xml_stylesheets
+ [
+ [{:href => "a.xsl", :type => "text/xsl"}],
+ [
+ {:href => "a.xsl", :type => "text/xsl"},
+ {:href => "a.css", :type => "text/css"},
+ ],
+ ].each do |attrs_ary|
+ assert_xml_stylesheet_pis(attrs_ary)
+ end
+ end
+
+ def test_channel
+ about = "http://hoge.com"
+ title = "fugafuga"
+ link = "http://hoge.com"
+ description = "fugafugafugafuga"
+ resource = "http://hoge.com/hoge.png"
+ image = RDF::Channel::Image.new(resource)
+ items = RDF::Channel::Items.new
+ textinput = RDF::Channel::Textinput.new(resource)
+
+ channel = RDF::Channel.new(about)
+ %w(title link description image items textinput).each do |x|
+ channel.send("#{x}=", instance_eval(x))
+ end
+
+ doc = REXML::Document.new(make_RDF(channel.to_s))
+ c = doc.root.elements[1]
+
+ assert_equal(about, c.attributes["about"])
+ %w(title link description image textinput).each do |x|
+ elem = c.elements[x]
+ assert_equal(x, elem.name)
+ assert_equal(@uri, elem.namespace)
+ if x == "image" or x == "textinput"
+ excepted = resource
+ res = elem.attributes.get_attribute("resource")
+ assert_equal(@rdf_uri, res.namespace)
+ value = res.value
+ else
+ excepted = instance_eval(x)
+ value = elem.text
+ end
+ assert_equal(excepted, value)
+ end
+ assert_equal(@uri, c.elements["items"].namespace)
+ assert_equal("items", c.elements["items"].name)
+
+ end
+
+ def test_channel_image
+
+ resource = "http://hoge.com/hoge.png"
+ image = RDF::Channel::Image.new(resource)
+
+ doc = REXML::Document.new(make_RDF(image.to_s))
+ i = doc.root.elements[1]
+
+ assert_equal("image", i.name)
+ assert_equal(@uri, i.namespace)
+
+ res = i.attributes.get_attribute("resource")
+
+ assert_equal(@rdf_uri, res.namespace)
+ assert_equal(resource, res.value)
+
+ end
+
+ def test_channel_textinput
+
+ resource = "http://hoge.com/hoge.png"
+ textinput = RDF::Channel::Textinput.new(resource)
+
+ doc = REXML::Document.new(make_RDF(textinput.to_s))
+ t = doc.root.elements[1]
+
+ assert_equal("textinput", t.name)
+ assert_equal(@uri, t.namespace)
+
+ res = t.attributes.get_attribute("resource")
+
+ assert_equal(@rdf_uri, res.namespace)
+ assert_equal(resource, res.value)
+
+ end
+
+ def test_items
+
+ items = RDF::Channel::Items.new
+
+ doc = REXML::Document.new(make_RDF(items.to_s))
+ i = doc.root.elements[1]
+
+ assert_equal("items", i.name)
+ assert_equal(@uri, i.namespace)
+
+ assert_equal(1, i.elements.size)
+ assert_equal("Seq", i.elements[1].name)
+ assert_equal(@rdf_uri, i.elements[1].namespace)
+
+ end
+
+ def test_seq
+
+ seq = RDF::Seq.new
+
+ doc = REXML::Document.new(make_RDF(seq.to_s))
+ s = doc.root.elements[1]
+
+ assert_equal("Seq", s.name)
+ assert_equal(@rdf_uri, s.namespace)
+
+ end
+
+ def test_li
+
+ resource = "http://hoge.com/"
+ li = RDF::Li.new(resource)
+
+ doc = REXML::Document.new(make_RDF(li.to_s))
+ l = doc.root.elements[1]
+
+ assert_equal("li", l.name)
+ assert_equal(@rdf_uri, l.namespace(l.prefix))
+
+ res = l.attributes.get_attribute("resource")
+
+ assert_equal('', res.instance_eval("@prefix"))
+ assert_equal(resource, res.value)
+
+ end
+
+ def test_image
+
+ about = "http://hoge.com"
+ title = "fugafuga"
+ url = "http://hoge.com/hoge"
+ link = "http://hoge.com/fuga"
+
+ image = RDF::Image.new(about)
+ %w(title url link).each do |x|
+ image.send("#{x}=", instance_eval(x))
+ end
+
+ doc = REXML::Document.new(make_RDF(image.to_s))
+ i = doc.root.elements[1]
+
+ assert_equal(about, i.attributes["about"])
+ %w(title url link).each do |x|
+ elem = i.elements[x]
+ assert_equal(x, elem.name)
+ assert_equal(@uri, elem.namespace)
+ assert_equal(instance_eval(x), elem.text)
+ end
+
+ end
+
+ def test_item
+
+ about = "http://hoge.com"
+ title = "fugafuga"
+ link = "http://hoge.com/fuga"
+ description = "hogehogehoge"
+
+ item = RDF::Item.new(about)
+ %w(title link description).each do |x|
+ item.send("#{x}=", instance_eval(x))
+ end
+
+ doc = REXML::Document.new(make_RDF(item.to_s))
+ i = doc.root.elements[1]
+
+ assert_equal(about, i.attributes["about"])
+ %w(title link description).each do |x|
+ elem = i.elements[x]
+ assert_equal(x, elem.name)
+ assert_equal(@uri, elem.namespace)
+ assert_equal(instance_eval(x), elem.text)
+ end
+
+ end
+
+ def test_textinput
+
+ about = "http://hoge.com"
+ title = "fugafuga"
+ link = "http://hoge.com/fuga"
+ name = "foo"
+ description = "hogehogehoge"
+
+ textinput = RDF::Textinput.new(about)
+ %w(title link name description).each do |x|
+ textinput.send("#{x}=", instance_eval(x))
+ end
+
+ doc = REXML::Document.new(make_RDF(textinput.to_s))
+ t = doc.root.elements[1]
+
+ assert_equal(about, t.attributes["about"])
+ %w(title link name description).each do |x|
+ elem = t.elements[x]
+ assert_equal(x, elem.name)
+ assert_equal(@uri, elem.namespace)
+ assert_equal(instance_eval(x), elem.text)
+ end
+
+ end
- def test_indent_size
- assert_equal(0, RDF.indent_size)
- assert_equal(1, RDF::Channel.indent_size)
- assert_equal(2, RDF::Channel::Image.indent_size)
- assert_equal(2, RDF::Channel::Textinput.indent_size)
- assert_equal(2, RDF::Channel::Items.indent_size)
- assert_equal(1, RDF::Image.indent_size)
- assert_equal(1, RDF::Item.indent_size)
- assert_equal(1, RDF::Textinput.indent_size)
- end
+ def test_indent_size
+ assert_equal(0, RDF.indent_size)
+ assert_equal(1, RDF::Channel.indent_size)
+ assert_equal(2, RDF::Channel::Image.indent_size)
+ assert_equal(2, RDF::Channel::Textinput.indent_size)
+ assert_equal(2, RDF::Channel::Items.indent_size)
+ assert_equal(1, RDF::Image.indent_size)
+ assert_equal(1, RDF::Item.indent_size)
+ assert_equal(1, RDF::Textinput.indent_size)
+ end
- end
+ end
end
diff --git a/test/rss/test_accessor.rb b/test/rss/test_accessor.rb
index 08f565e596..1b92f9d98c 100644
--- a/test/rss/test_accessor.rb
+++ b/test/rss/test_accessor.rb
@@ -6,21 +6,21 @@ require "rss/1.0"
require "rss/2.0"
module RSS
- class TestAccessor < TestCase
-
- def test_date
- channel = Rss::Channel.new
- channel.do_validate = false
- channel.pubDate = nil
- assert_nil(channel.pubDate)
-
- time = Time.now
- channel.pubDate = time
- assert_equal(time, channel.pubDate)
-
- channel.pubDate = nil
- assert_nil(channel.pubDate)
- end
-
- end
+ class TestAccessor < TestCase
+
+ def test_date
+ channel = Rss::Channel.new
+ channel.do_validate = false
+ channel.pubDate = nil
+ assert_nil(channel.pubDate)
+
+ time = Time.now
+ channel.pubDate = time
+ assert_equal(time, channel.pubDate)
+
+ channel.pubDate = nil
+ assert_nil(channel.pubDate)
+ end
+
+ end
end
diff --git a/test/rss/test_content.rb b/test/rss/test_content.rb
index 24877d3ec9..c0f6e4292f 100644
--- a/test/rss/test_content.rb
+++ b/test/rss/test_content.rb
@@ -9,89 +9,89 @@ require "rss/1.0"
require "rss/content"
module RSS
- class TestContent < TestCase
-
- def setup
- @prefix = "content"
- @uri = "http://purl.org/rss/1.0/modules/content/"
-
- @parents = %w(item)
-
- @elems = {
- :encoded => "<em>ATTENTION</em>",
- }
-
- @content_nodes = @elems.collect do |name, value|
- "<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
- end.join("\n")
-
- @rss_source = make_RDF(<<-EOR, {@prefix => @uri})
+ class TestContent < TestCase
+
+ def setup
+ @prefix = "content"
+ @uri = "http://purl.org/rss/1.0/modules/content/"
+
+ @parents = %w(item)
+
+ @elems = {
+ :encoded => "<em>ATTENTION</em>",
+ }
+
+ @content_nodes = @elems.collect do |name, value|
+ "<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
+ end.join("\n")
+
+ @rss_source = make_RDF(<<-EOR, {@prefix => @uri})
#{make_channel()}
#{make_image()}
#{make_item(@content_nodes)}
#{make_textinput()}
EOR
- @rss = Parser.parse(@rss_source)
- end
-
- def test_parser
+ @rss = Parser.parse(@rss_source)
+ end
+
+ def test_parser
- assert_nothing_raised do
- Parser.parse(@rss_source)
- end
-
- @elems.each do |tag, value|
- assert_too_much_tag(tag.to_s, "item") do
- Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
+ assert_nothing_raised do
+ Parser.parse(@rss_source)
+ end
+
+ @elems.each do |tag, value|
+ assert_too_much_tag(tag.to_s, "item") do
+ Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
#{make_channel()}
#{make_item(("<" + @prefix + ":" + tag.to_s + ">" +
- CGI.escapeHTML(value.to_s) +
- "</" + @prefix + ":" + tag.to_s + ">") * 2)}
+ CGI.escapeHTML(value.to_s) +
+ "</" + @prefix + ":" + tag.to_s + ">") * 2)}
EOR
- end
- end
+ end
+ end
- end
-
- def test_accessor
-
- new_value = {
- :encoded => "<![CDATA[<it>hoge</it>]]>",
- }
+ end
+
+ def test_accessor
+
+ new_value = {
+ :encoded => "<![CDATA[<it>hoge</it>]]>",
+ }
- @elems.each do |name, value|
- @parents.each do |parent|
- meth = "#{RSS::CONTENT_PREFIX}_#{name}"
- assert_equal(value, @rss.send(parent).send(meth))
- @rss.send(parent).send("#{meth}=", new_value[name].to_s)
- assert_equal(new_value[name], @rss.send(parent).send(meth))
- end
- end
+ @elems.each do |name, value|
+ @parents.each do |parent|
+ meth = "#{RSS::CONTENT_PREFIX}_#{name}"
+ assert_equal(value, @rss.send(parent).send(meth))
+ @rss.send(parent).send("#{meth}=", new_value[name].to_s)
+ assert_equal(new_value[name], @rss.send(parent).send(meth))
+ end
+ end
- end
-
- def test_to_s
-
- @elems.each do |name, value|
- excepted = "<#{@prefix}:#{name}>#{CGI.escapeHTML(value)}</#{@prefix}:#{name}>"
- @parents.each do |parent|
- meth = "#{RSS::CONTENT_PREFIX}_#{name}_element"
- assert_equal(excepted, @rss.send(parent).send(meth))
- end
- end
+ end
+
+ def test_to_s
+
+ @elems.each do |name, value|
+ excepted = "<#{@prefix}:#{name}>#{CGI.escapeHTML(value)}</#{@prefix}:#{name}>"
+ @parents.each do |parent|
+ meth = "#{RSS::CONTENT_PREFIX}_#{name}_element"
+ assert_equal(excepted, @rss.send(parent).send(meth))
+ end
+ end
- REXML::Document.new(@rss_source).root.each_element do |parent|
- if @parents.include?(parent.name)
- parent.each_element do |elem|
- if elem.namespace == @uri
- assert_equal(elem.text, @elems[elem.name.intern].to_s)
- end
- end
- end
- end
-
- end
-
- end
+ REXML::Document.new(@rss_source).root.each_element do |parent|
+ if @parents.include?(parent.name)
+ parent.each_element do |elem|
+ if elem.namespace == @uri
+ assert_equal(elem.text, @elems[elem.name.intern].to_s)
+ end
+ end
+ end
+ end
+
+ end
+
+ end
end
diff --git a/test/rss/test_dublincore.rb b/test/rss/test_dublincore.rb
index bf5a672837..796666cdb5 100644
--- a/test/rss/test_dublincore.rb
+++ b/test/rss/test_dublincore.rb
@@ -9,118 +9,118 @@ require "rss/1.0"
require "rss/dublincore"
module RSS
- class TestDublinCore < TestCase
+ class TestDublinCore < TestCase
- def setup
- @prefix = "dc"
- @uri = "http://purl.org/dc/elements/1.1/"
-
- @parents = %w(channel image item textinput)
-
- t = Time.iso8601("2000-01-01T12:00:05+00:00")
- class << t
- alias_method(:to_s, :iso8601)
- end
-
- @elems = {
- :title => "hoge",
- :description =>
- " XML is placing increasingly heavy loads on
- the existing technical infrastructure of the Internet.",
- :creator => "Rael Dornfest (mailto:rael@oreilly.com)",
- :subject => "XML",
- :publisher => "The O'Reilly Network",
- :contributor => "hogehoge",
- :type => "fugafuga",
- :format => "hohoho",
- :identifier => "fufufu",
- :source => "barbar",
- :language => "ja",
- :relation => "cococo",
- :rights => "Copyright (c) 2000 O'Reilly &amp; Associates, Inc.",
- :date => t,
- }
+ def setup
+ @prefix = "dc"
+ @uri = "http://purl.org/dc/elements/1.1/"
+
+ @parents = %w(channel image item textinput)
+
+ t = Time.iso8601("2000-01-01T12:00:05+00:00")
+ class << t
+ alias_method(:to_s, :iso8601)
+ end
+
+ @elems = {
+ :title => "hoge",
+ :description =>
+ " XML is placing increasingly heavy loads on
+ the existing technical infrastructure of the Internet.",
+ :creator => "Rael Dornfest (mailto:rael@oreilly.com)",
+ :subject => "XML",
+ :publisher => "The O'Reilly Network",
+ :contributor => "hogehoge",
+ :type => "fugafuga",
+ :format => "hohoho",
+ :identifier => "fufufu",
+ :source => "barbar",
+ :language => "ja",
+ :relation => "cococo",
+ :rights => "Copyright (c) 2000 O'Reilly &amp; Associates, Inc.",
+ :date => t,
+ }
- @dc_nodes = @elems.collect do |name, value|
- "<#{@prefix}:#{name}>#{value}</#{@prefix}:#{name}>"
- end.join("\n")
+ @dc_nodes = @elems.collect do |name, value|
+ "<#{@prefix}:#{name}>#{value}</#{@prefix}:#{name}>"
+ end.join("\n")
- @rss_source = make_RDF(<<-EOR, {@prefix => @uri})
+ @rss_source = make_RDF(<<-EOR, {@prefix => @uri})
#{make_channel(@dc_nodes)}
#{make_image(@dc_nodes)}
#{make_item(@dc_nodes)}
#{make_textinput(@dc_nodes)}
EOR
- @rss = Parser.parse(@rss_source)
- end
-
- def test_parser
+ @rss = Parser.parse(@rss_source)
+ end
+
+ def test_parser
- assert_nothing_raised do
- Parser.parse(@rss_source)
- end
-
- @elems.each do |tag, value|
- assert_too_much_tag(tag.to_s, "channel") do
- Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
+ assert_nothing_raised do
+ Parser.parse(@rss_source)
+ end
+
+ @elems.each do |tag, value|
+ assert_too_much_tag(tag.to_s, "channel") do
+ Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
#{make_channel(("<" + @prefix + ":" + tag.to_s + ">" +
- value.to_s +
- "</" + @prefix + ":" + tag.to_s + ">") * 2)}
+ value.to_s +
+ "</" + @prefix + ":" + tag.to_s + ">") * 2)}
#{make_item}
EOR
- end
- end
+ end
+ end
- end
-
- def test_accessor
-
- new_value = "hoge"
+ end
+
+ def test_accessor
+
+ new_value = "hoge"
- @elems.each do |name, value|
- @parents.each do |parent|
- parsed_value = @rss.send(parent).send("dc_#{name}")
- if parsed_value.kind_of?(String)
- parsed_value = CGI.escapeHTML(parsed_value)
- end
- assert_equal(value, parsed_value)
- if name == :date
- t = Time.iso8601("2003-01-01T02:30:23+09:00")
- class << t
- alias_method(:to_s, :iso8601)
- end
- @rss.send(parent).send("dc_#{name}=", t.iso8601)
- assert_equal(t, @rss.send(parent).send("dc_#{name}"))
- else
- @rss.send(parent).send("dc_#{name}=", new_value)
- assert_equal(new_value, @rss.send(parent).send("dc_#{name}"))
- end
- end
- end
+ @elems.each do |name, value|
+ @parents.each do |parent|
+ parsed_value = @rss.send(parent).send("dc_#{name}")
+ if parsed_value.kind_of?(String)
+ parsed_value = CGI.escapeHTML(parsed_value)
+ end
+ assert_equal(value, parsed_value)
+ if name == :date
+ t = Time.iso8601("2003-01-01T02:30:23+09:00")
+ class << t
+ alias_method(:to_s, :iso8601)
+ end
+ @rss.send(parent).send("dc_#{name}=", t.iso8601)
+ assert_equal(t, @rss.send(parent).send("dc_#{name}"))
+ else
+ @rss.send(parent).send("dc_#{name}=", new_value)
+ assert_equal(new_value, @rss.send(parent).send("dc_#{name}"))
+ end
+ end
+ end
- end
+ end
- def test_to_s
-
- @elems.each do |name, value|
- excepted = "<#{@prefix}:#{name}>#{value}</#{@prefix}:#{name}>"
- @parents.each do |parent|
- assert_equal(excepted, @rss.send(parent).send("dc_#{name}_element"))
- end
- end
-
- REXML::Document.new(@rss_source).root.each_element do |parent|
- if @parents.include?(parent.name)
- parent.each_element do |elem|
- if elem.namespace == @uri
- assert_equal(CGI.escapeHTML(elem.text), @elems[elem.name.intern].to_s)
- end
- end
- end
- end
-
- end
+ def test_to_s
+
+ @elems.each do |name, value|
+ excepted = "<#{@prefix}:#{name}>#{value}</#{@prefix}:#{name}>"
+ @parents.each do |parent|
+ assert_equal(excepted, @rss.send(parent).send("dc_#{name}_element"))
+ end
+ end
+
+ REXML::Document.new(@rss_source).root.each_element do |parent|
+ if @parents.include?(parent.name)
+ parent.each_element do |elem|
+ if elem.namespace == @uri
+ assert_equal(CGI.escapeHTML(elem.text), @elems[elem.name.intern].to_s)
+ end
+ end
+ end
+ end
+
+ end
- end
+ end
end
diff --git a/test/rss/test_parser.rb b/test/rss/test_parser.rb
index 5b15ccb908..3fd26bffb4 100644
--- a/test/rss/test_parser.rb
+++ b/test/rss/test_parser.rb
@@ -7,139 +7,139 @@ require "rss/2.0"
require "rss/dublincore"
module RSS
- class TestParser < TestCase
-
- def setup
- @_default_parser = Parser.default_parser
- end
-
- def teardown
- Parser.default_parser = @_default_parser
- end
-
- def test_RDF
- assert_ns("", RDF::URI) do
- Parser.parse(<<-EOR)
+ class TestParser < TestCase
+
+ def setup
+ @_default_parser = Parser.default_parser
+ end
+
+ def teardown
+ Parser.default_parser = @_default_parser
+ end
+
+ def test_RDF
+ assert_ns("", RDF::URI) do
+ Parser.parse(<<-EOR)
#{make_xmldecl}
<RDF/>
EOR
- end
+ end
- assert_ns("", RDF::URI) do
- Parser.parse(<<-EOR)
+ assert_ns("", RDF::URI) do
+ Parser.parse(<<-EOR)
#{make_xmldecl}
<RDF xmlns="hoge"/>
EOR
- end
+ end
- assert_ns("rdf", RDF::URI) do
- Parser.parse(<<-EOR)
+ assert_ns("rdf", RDF::URI) do
+ Parser.parse(<<-EOR)
#{make_xmldecl}
<rdf:RDF xmlns:rdf="hoge"/>
EOR
- end
+ end
- assert_parse(<<-EOR, :missing_tag, "channel", "RDF")
+ assert_parse(<<-EOR, :missing_tag, "channel", "RDF")
#{make_xmldecl}
<rdf:RDF xmlns:rdf="#{RSS::RDF::URI}"/>
EOR
- assert_parse(<<-EOR, :missing_tag, "channel", "RDF")
+ assert_parse(<<-EOR, :missing_tag, "channel", "RDF")
#{make_xmldecl}
<RDF xmlns="#{RSS::RDF::URI}"/>
EOR
- assert_parse(<<-EOR, :missing_tag, "channel", "RDF")
+ assert_parse(<<-EOR, :missing_tag, "channel", "RDF")
#{make_xmldecl}
<RDF xmlns="#{RSS::RDF::URI}"/>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
#{make_channel}
EOR
- assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
#{make_channel}
#{make_image}
EOR
- assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
#{make_channel}
#{make_textinput}
EOR
- assert_too_much_tag("image", "RDF") do
- Parser.parse(make_RDF(<<-EOR))
+ assert_too_much_tag("image", "RDF") do
+ Parser.parse(make_RDF(<<-EOR))
#{make_channel}
#{make_image}
#{make_image}
#{make_item}
#{make_textinput}
EOR
- end
+ end
- assert_parse(make_RDF(<<-EOR), :nothing_raised)
+ assert_parse(make_RDF(<<-EOR), :nothing_raised)
#{make_channel}
#{make_item}
#{make_image}
#{make_textinput}
EOR
- assert_parse(make_RDF(<<-EOR), :nothing_raised)
+ assert_parse(make_RDF(<<-EOR), :nothing_raised)
#{make_channel}
#{make_item}
#{make_textinput}
#{make_image}
EOR
- assert_parse(make_RDF(<<-EOR), :nothing_raised)
+ assert_parse(make_RDF(<<-EOR), :nothing_raised)
#{make_channel}
#{make_image}
#{make_item}
EOR
- assert_parse(make_RDF(<<-EOR), :nothing_raised)
+ assert_parse(make_RDF(<<-EOR), :nothing_raised)
#{make_channel}
#{make_image}
#{make_item}
#{make_textinput}
EOR
- 1.step(15, 3) do |i|
- rss = make_RDF() do
- res = make_channel
- i.times { res << make_item }
- res
- end
- assert_parse(rss, :nothing_raised)
- end
+ 1.step(15, 3) do |i|
+ rss = make_RDF() do
+ res = make_channel
+ i.times { res << make_item }
+ res
+ end
+ assert_parse(rss, :nothing_raised)
+ end
- end
+ end
- def test_channel
+ def test_channel
- assert_parse(make_RDF(<<-EOR), :missing_attribute, "channel", "about")
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "channel", "about")
<channel />
EOR
- assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "channel")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "channel")
<channel rdf:about="http://example.com/"/>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "channel")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "channel")
<channel rdf:about="http://example.com/">
<title>hoge</title>
</channel>
EOR
- assert_parse(make_RDF(<<EOR), :missing_tag, "description", "channel")
+ assert_parse(make_RDF(<<EOR), :missing_tag, "description", "channel")
<channel rdf:about="http://example.com/">
<title>hoge</title>
<link>http://example.com/</link>
</channel>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_tag, "items", "channel")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "items", "channel")
<channel rdf:about="http://example.com/">
<title>hoge</title>
<link>http://example.com/</link>
@@ -147,7 +147,7 @@ EOR
</channel>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "resource")
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "resource")
<channel rdf:about="http://example.com/">
<title>hoge</title>
<link>http://example.com/</link>
@@ -156,7 +156,7 @@ EOR
</channel>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_tag, "items", "channel")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "items", "channel")
<channel rdf:about="http://example.com/">
<title>hoge</title>
<link>http://example.com/</link>
@@ -165,7 +165,7 @@ EOR
</channel>
EOR
- rss = make_RDF(<<-EOR)
+ rss = make_RDF(<<-EOR)
<channel rdf:about="http://example.com/">
<title>hoge</title>
<link>http://example.com/</link>
@@ -175,15 +175,15 @@ EOR
</channel>
EOR
- assert_missing_tag("Seq", "items") do
- Parser.parse(rss)
- end
+ assert_missing_tag("Seq", "items") do
+ Parser.parse(rss)
+ end
- assert_missing_tag("item", "RDF") do
- Parser.parse(rss, false).validate
- end
+ assert_missing_tag("item", "RDF") do
+ Parser.parse(rss, false).validate
+ end
- assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
<channel rdf:about="http://example.com/">
<title>hoge</title>
<link>http://example.com/</link>
@@ -196,7 +196,7 @@ EOR
</channel>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "resource")
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "resource")
<channel rdf:about="http://example.com/">
<title>hoge</title>
<link>http://example.com/</link>
@@ -210,7 +210,7 @@ EOR
</channel>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
<channel rdf:about="http://example.com/">
<title>hoge</title>
<link>http://example.com/</link>
@@ -224,11 +224,11 @@ EOR
</channel>
EOR
- end
+ end
- def test_rdf_li
+ def test_rdf_li
- rss = make_RDF(<<-EOR)
+ rss = make_RDF(<<-EOR)
<channel rdf:about="http://example.com/">
<title>hoge</title>
<link>http://example.com/</link>
@@ -244,41 +244,41 @@ EOR
#{make_item}
EOR
- source = Proc.new do |rdf_li_attr|
- eval(%Q[%Q[#{rss}]], binding)
- end
+ source = Proc.new do |rdf_li_attr|
+ eval(%Q[%Q[#{rss}]], binding)
+ end
- attr = %q[resource="http://example.com/hoge"]
- assert_parse(source.call(attr), :nothing_raised)
+ attr = %q[resource="http://example.com/hoge"]
+ assert_parse(source.call(attr), :nothing_raised)
- attr = %q[rdf:resource="http://example.com/hoge"]
- assert_parse(source.call(attr), :nothing_raised)
+ attr = %q[rdf:resource="http://example.com/hoge"]
+ assert_parse(source.call(attr), :nothing_raised)
- assert_parse(source.call(""), :missing_attribute, "li", "resource")
- end
+ assert_parse(source.call(""), :missing_attribute, "li", "resource")
+ end
- def test_image
+ def test_image
- assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "about")
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "image", "about")
#{make_channel}
<image>
</image>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "image")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "image")
#{make_channel}
<image rdf:about="http://example.com/hoge.png">
</image>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_tag, "url", "image")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "url", "image")
#{make_channel}
<image rdf:about="http://example.com/hoge.png">
<title>hoge</title>
</image>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "image")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "image")
#{make_channel}
<image rdf:about="http://example.com/hoge.png">
<title>hoge</title>
@@ -286,7 +286,7 @@ EOR
</image>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "item", "RDF")
#{make_channel}
<image rdf:about="http://example.com/hoge.png">
<title>hoge</title>
@@ -295,7 +295,7 @@ EOR
</image>
EOR
- rss = make_RDF(<<-EOR)
+ rss = make_RDF(<<-EOR)
#{make_channel}
<image rdf:about="http://example.com/hoge.png">
<link>http://example.com/</link>
@@ -304,33 +304,33 @@ EOR
</image>
EOR
- assert_missing_tag("item", "RDF") do
- Parser.parse(rss)
- end
+ assert_missing_tag("item", "RDF") do
+ Parser.parse(rss)
+ end
- assert_missing_tag("item", "RDF") do
- Parser.parse(rss, false).validate
- end
+ assert_missing_tag("item", "RDF") do
+ Parser.parse(rss, false).validate
+ end
- end
+ end
- def test_item
+ def test_item
- assert_parse(make_RDF(<<-EOR), :missing_attribute, "item", "about")
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "item", "about")
#{make_channel}
#{make_image}
<item>
</item>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "item")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "item")
#{make_channel}
#{make_image}
<item rdf:about="http://example.com/hoge.html">
</item>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "item")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "item")
#{make_channel}
#{make_image}
<item rdf:about="http://example.com/hoge.html">
@@ -338,8 +338,8 @@ EOR
</item>
EOR
- assert_too_much_tag("title", "item") do
- Parser.parse(make_RDF(<<-EOR))
+ assert_too_much_tag("title", "item") do
+ Parser.parse(make_RDF(<<-EOR))
#{make_channel}
#{make_image}
<item rdf:about="http://example.com/hoge.html">
@@ -348,9 +348,9 @@ EOR
<link>http://example.com/hoge.html</link>
</item>
EOR
- end
+ end
- assert_parse(make_RDF(<<-EOR), :nothing_raised)
+ assert_parse(make_RDF(<<-EOR), :nothing_raised)
#{make_channel}
#{make_image}
<item rdf:about="http://example.com/hoge.html">
@@ -359,7 +359,7 @@ EOR
</item>
EOR
- assert_parse(make_RDF(<<-EOR), :nothing_raised)
+ assert_parse(make_RDF(<<-EOR), :nothing_raised)
#{make_channel}
#{make_image}
<item rdf:about="http://example.com/hoge.html">
@@ -369,11 +369,11 @@ EOR
</item>
EOR
- end
+ end
- def test_textinput
+ def test_textinput
- assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "about")
+ assert_parse(make_RDF(<<-EOR), :missing_attribute, "textinput", "about")
#{make_channel}
#{make_image}
#{make_item}
@@ -381,7 +381,7 @@ EOR
</textinput>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "textinput")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "title", "textinput")
#{make_channel}
#{make_image}
#{make_item}
@@ -389,7 +389,7 @@ EOR
</textinput>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_tag, "description", "textinput")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "description", "textinput")
#{make_channel}
#{make_image}
#{make_item}
@@ -398,8 +398,8 @@ EOR
</textinput>
EOR
- assert_too_much_tag("title", "textinput") do
- Parser.parse(make_RDF(<<-EOR))
+ assert_too_much_tag("title", "textinput") do
+ Parser.parse(make_RDF(<<-EOR))
#{make_channel}
#{make_image}
#{make_item}
@@ -409,9 +409,9 @@ EOR
<description>hogehoge</description>
</textinput>
EOR
- end
+ end
- assert_parse(make_RDF(<<-EOR), :missing_tag, "name", "textinput")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "name", "textinput")
#{make_channel}
#{make_image}
#{make_item}
@@ -421,7 +421,7 @@ EOR
</textinput>
EOR
- assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "textinput")
+ assert_parse(make_RDF(<<-EOR), :missing_tag, "link", "textinput")
#{make_channel}
#{make_image}
#{make_item}
@@ -432,7 +432,7 @@ EOR
</textinput>
EOR
- assert_parse(make_RDF(<<-EOR), :nothing_raised)
+ assert_parse(make_RDF(<<-EOR), :nothing_raised)
#{make_channel}
#{make_image}
#{make_item}
@@ -444,170 +444,170 @@ EOR
</textinput>
EOR
- end
+ end
- def test_rss20
-
- assert_parse(make_rss20(<<-EOR), :missing_tag, "channel", "rss")
+ def test_rss20
+
+ assert_parse(make_rss20(<<-EOR), :missing_tag, "channel", "rss")
EOR
- assert_parse(make_rss20(<<-EOR), :nothing_raised)
+ assert_parse(make_rss20(<<-EOR), :nothing_raised)
#{make_channel20("")}
EOR
- end
-
- def test_cloud20
-
- attrs = [
- ["domain", CLOUD_DOMAIN],
- ["port", CLOUD_PORT],
- ["path", CLOUD_PATH],
- ["registerProcedure", CLOUD_REGISTER_PROCEDURE],
- ["protocol", CLOUD_PROTOCOL],
- ]
-
- (attrs.size + 1).times do |i|
- missing_attr = attrs[i]
- if missing_attr
- meth = :missing_attribute
- args = ["cloud", missing_attr[0]]
- else
- meth = :nothing_raised
- args = []
- end
-
- cloud_attrs = []
- attrs.each_with_index do |attr, j|
- unless i == j
- cloud_attrs << %Q[#{attr[0]}="#{attr[1]}"]
- end
- end
-
- assert_parse(make_rss20(<<-EOR), meth, *args)
+ end
+
+ def test_cloud20
+
+ attrs = [
+ ["domain", CLOUD_DOMAIN],
+ ["port", CLOUD_PORT],
+ ["path", CLOUD_PATH],
+ ["registerProcedure", CLOUD_REGISTER_PROCEDURE],
+ ["protocol", CLOUD_PROTOCOL],
+ ]
+
+ (attrs.size + 1).times do |i|
+ missing_attr = attrs[i]
+ if missing_attr
+ meth = :missing_attribute
+ args = ["cloud", missing_attr[0]]
+ else
+ meth = :nothing_raised
+ args = []
+ end
+
+ cloud_attrs = []
+ attrs.each_with_index do |attr, j|
+ unless i == j
+ cloud_attrs << %Q[#{attr[0]}="#{attr[1]}"]
+ end
+ end
+
+ assert_parse(make_rss20(<<-EOR), meth, *args)
#{make_channel20(%Q[<cloud #{cloud_attrs.join("\n")}/>])}
EOR
- end
+ end
- end
+ end
- def test_source20
+ def test_source20
- assert_parse(make_rss20(<<-EOR), :missing_attribute, "source", "url")
+ assert_parse(make_rss20(<<-EOR), :missing_attribute, "source", "url")
#{make_channel20(make_item20(%Q[<source>Example</source>]))}
EOR
- assert_parse(make_rss20(<<-EOR), :nothing_raised)
+ assert_parse(make_rss20(<<-EOR), :nothing_raised)
#{make_channel20(make_item20(%Q[<source url="http://example.com/" />]))}
EOR
- assert_parse(make_rss20(<<-EOR), :nothing_raised)
+ assert_parse(make_rss20(<<-EOR), :nothing_raised)
#{make_channel20(make_item20(%Q[<source url="http://example.com/">Example</source>]))}
EOR
- end
-
- def test_enclosure20
-
- attrs = [
- ["url", ENCLOSURE_URL],
- ["length", ENCLOSURE_LENGTH],
- ["type", ENCLOSURE_TYPE],
- ]
-
- (attrs.size + 1).times do |i|
- missing_attr = attrs[i]
- if missing_attr
- meth = :missing_attribute
- args = ["enclosure", missing_attr[0]]
- else
- meth = :nothing_raised
- args = []
- end
-
- enclosure_attrs = []
- attrs.each_with_index do |attr, j|
- unless i == j
- enclosure_attrs << %Q[#{attr[0]}="#{attr[1]}"]
- end
- end
-
- assert_parse(make_rss20(<<-EOR), meth, *args)
+ end
+
+ def test_enclosure20
+
+ attrs = [
+ ["url", ENCLOSURE_URL],
+ ["length", ENCLOSURE_LENGTH],
+ ["type", ENCLOSURE_TYPE],
+ ]
+
+ (attrs.size + 1).times do |i|
+ missing_attr = attrs[i]
+ if missing_attr
+ meth = :missing_attribute
+ args = ["enclosure", missing_attr[0]]
+ else
+ meth = :nothing_raised
+ args = []
+ end
+
+ enclosure_attrs = []
+ attrs.each_with_index do |attr, j|
+ unless i == j
+ enclosure_attrs << %Q[#{attr[0]}="#{attr[1]}"]
+ end
+ end
+
+ assert_parse(make_rss20(<<-EOR), meth, *args)
#{make_channel20(%Q[
#{make_item20(%Q[
<enclosure
#{enclosure_attrs.join("\n")} />
- ])}
- ])}
-EOR
-
- end
-
- end
-
- def test_category20
-
- attrs = [
- ["domain", CATEGORY_DOMAIN],
- ]
-
- (attrs.size + 1).times do |i|
- missing_attr = attrs[i]
- if missing_attr
- meth = :missing_attribute
- args = ["category", missing_attr[0]]
- else
- meth = :nothing_raised
- args = []
- end
-
- category_attrs = []
- attrs.each_with_index do |attr, j|
- unless i == j
- category_attrs << %Q[#{attr[0]}="#{attr[1]}"]
- end
- end
-
- ["", "Example Text"].each do |text|
- assert_parse(make_rss20(<<-EOR), meth, *args)
+ ])}
+ ])}
+EOR
+
+ end
+
+ end
+
+ def test_category20
+
+ attrs = [
+ ["domain", CATEGORY_DOMAIN],
+ ]
+
+ (attrs.size + 1).times do |i|
+ missing_attr = attrs[i]
+ if missing_attr
+ meth = :missing_attribute
+ args = ["category", missing_attr[0]]
+ else
+ meth = :nothing_raised
+ args = []
+ end
+
+ category_attrs = []
+ attrs.each_with_index do |attr, j|
+ unless i == j
+ category_attrs << %Q[#{attr[0]}="#{attr[1]}"]
+ end
+ end
+
+ ["", "Example Text"].each do |text|
+ assert_parse(make_rss20(<<-EOR), meth, *args)
#{make_channel20(%Q[
#{make_item20(%Q[
<category
#{category_attrs.join("\n")}>#{text}</category>
- ])}
- ])}
+ ])}
+ ])}
EOR
- end
- end
+ end
+ end
- end
+ end
- def test_ignore
+ def test_ignore
- rss = make_RDF(<<-EOR)
+ rss = make_RDF(<<-EOR)
#{make_channel}
#{make_item}
<a/>
EOR
- assert_parse(rss, :nothing_raised)
+ assert_parse(rss, :nothing_raised)
- assert_not_excepted_tag("a", "RDF") do
- Parser.parse(rss, true, false)
- end
+ assert_not_excepted_tag("a", "RDF") do
+ Parser.parse(rss, true, false)
+ end
- end
+ end
- def test_default_parser
- assert_nothing_raised() do
- Parser.default_parser = RSS::AVAILABLE_PARSERS.first
- end
+ def test_default_parser
+ assert_nothing_raised() do
+ Parser.default_parser = RSS::AVAILABLE_PARSERS.first
+ end
- assert_raise(RSS::NotValidXMLParser) do
- Parser.default_parser = RSS::Parser
- end
- end
+ assert_raise(RSS::NotValidXMLParser) do
+ Parser.default_parser = RSS::Parser
+ end
+ end
- end
+ end
end
diff --git a/test/rss/test_syndication.rb b/test/rss/test_syndication.rb
index 0eec3bacc6..9d620089e1 100644
--- a/test/rss/test_syndication.rb
+++ b/test/rss/test_syndication.rb
@@ -9,117 +9,117 @@ require "rss/1.0"
require "rss/syndication"
module RSS
- class TestSyndication < TestCase
-
- def setup
- @prefix = "sy"
- @uri = "http://purl.org/rss/1.0/modules/syndication/"
-
- @parents = %w(channel)
-
- t = Time.iso8601("2000-01-01T12:00:05+00:00")
- class << t
- alias_method(:to_s, :iso8601)
- end
-
- @elems = {
- :updatePeriod => "hourly",
- :updateFrequency => 2,
- :updateBase => t,
- }
-
- @sy_nodes = @elems.collect do |name, value|
- "<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
- end.join("\n")
-
- @rss_source = make_RDF(<<-EOR, {@prefix => @uri})
+ class TestSyndication < TestCase
+
+ def setup
+ @prefix = "sy"
+ @uri = "http://purl.org/rss/1.0/modules/syndication/"
+
+ @parents = %w(channel)
+
+ t = Time.iso8601("2000-01-01T12:00:05+00:00")
+ class << t
+ alias_method(:to_s, :iso8601)
+ end
+
+ @elems = {
+ :updatePeriod => "hourly",
+ :updateFrequency => 2,
+ :updateBase => t,
+ }
+
+ @sy_nodes = @elems.collect do |name, value|
+ "<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
+ end.join("\n")
+
+ @rss_source = make_RDF(<<-EOR, {@prefix => @uri})
#{make_channel(@sy_nodes)}
#{make_image()}
#{make_item()}
#{make_textinput()}
EOR
- @rss = Parser.parse(@rss_source)
- end
-
- def test_parser
-
- assert_nothing_raised do
- Parser.parse(@rss_source)
- end
-
- @elems.each do |tag, value|
- assert_too_much_tag(tag.to_s, "channel") do
- Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
+ @rss = Parser.parse(@rss_source)
+ end
+
+ def test_parser
+
+ assert_nothing_raised do
+ Parser.parse(@rss_source)
+ end
+
+ @elems.each do |tag, value|
+ assert_too_much_tag(tag.to_s, "channel") do
+ Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
#{make_channel(("<" + @prefix + ":" + tag.to_s + ">" +
- CGI.escapeHTML(value.to_s) +
- "</" + @prefix + ":" + tag.to_s + ">") * 2)}
+ CGI.escapeHTML(value.to_s) +
+ "</" + @prefix + ":" + tag.to_s + ">") * 2)}
#{make_item}
EOR
- end
- end
+ end
+ end
- end
-
- def test_accessor
-
- t = Time.iso8601("2003-01-01T12:00:23+09:00")
- class << t
- alias_method(:to_s, :iso8601)
- end
-
- new_value = {
- :updatePeriod => "daily",
- :updateFrequency => +11,
- :updateBase => t,
- }
-
- @elems.each do |name, value|
- @parents.each do |parent|
- assert_equal(value, @rss.send(parent).send("sy_#{name}"))
- @rss.send(parent).send("sy_#{name}=", new_value[name].to_s)
- assert_equal(new_value[name], @rss.send(parent).send("sy_#{name}"))
- end
- end
-
- %w(hourly daily weekly monthly yearly).each do |x|
- @parents.each do |parent|
- assert_nothing_raised do
- @rss.send(parent).sy_updatePeriod = x
- end
- end
- end
-
- %w(-2 0.3 -0.4).each do |x|
- @parents.each do |parent|
- assert_not_available_value("updateBase", x) do
- @rss.send(parent).sy_updateBase = x
- end
- end
- end
-
- end
+ end
+
+ def test_accessor
+
+ t = Time.iso8601("2003-01-01T12:00:23+09:00")
+ class << t
+ alias_method(:to_s, :iso8601)
+ end
+
+ new_value = {
+ :updatePeriod => "daily",
+ :updateFrequency => +11,
+ :updateBase => t,
+ }
+
+ @elems.each do |name, value|
+ @parents.each do |parent|
+ assert_equal(value, @rss.send(parent).send("sy_#{name}"))
+ @rss.send(parent).send("sy_#{name}=", new_value[name].to_s)
+ assert_equal(new_value[name], @rss.send(parent).send("sy_#{name}"))
+ end
+ end
+
+ %w(hourly daily weekly monthly yearly).each do |x|
+ @parents.each do |parent|
+ assert_nothing_raised do
+ @rss.send(parent).sy_updatePeriod = x
+ end
+ end
+ end
+
+ %w(-2 0.3 -0.4).each do |x|
+ @parents.each do |parent|
+ assert_not_available_value("updateBase", x) do
+ @rss.send(parent).sy_updateBase = x
+ end
+ end
+ end
+
+ end
- def test_to_s
-
- @elems.each do |name, value|
- excepted = "<#{@prefix}:#{name}>#{value}</#{@prefix}:#{name}>"
- @parents.each do |parent|
- assert_equal(excepted, @rss.send(parent).send("sy_#{name}_element"))
- end
- end
-
- REXML::Document.new(@rss_source).root.each_element do |parent|
- if @parents.include?(parent.name)
- parent.each_element do |elem|
- if elem.namespace == @uri
- assert_equal(elem.text, @elems[elem.name.intern].to_s)
- end
- end
- end
- end
-
- end
-
- end
+ def test_to_s
+
+ @elems.each do |name, value|
+ excepted = "<#{@prefix}:#{name}>#{value}</#{@prefix}:#{name}>"
+ @parents.each do |parent|
+ assert_equal(excepted, @rss.send(parent).send("sy_#{name}_element"))
+ end
+ end
+
+ REXML::Document.new(@rss_source).root.each_element do |parent|
+ if @parents.include?(parent.name)
+ parent.each_element do |elem|
+ if elem.namespace == @uri
+ assert_equal(elem.text, @elems[elem.name.intern].to_s)
+ end
+ end
+ end
+ end
+
+ end
+
+ end
end
diff --git a/test/rss/test_trackback.rb b/test/rss/test_trackback.rb
index ab77cf3fb8..9c4b086cae 100644
--- a/test/rss/test_trackback.rb
+++ b/test/rss/test_trackback.rb
@@ -10,128 +10,128 @@ require "rss/2.0"
require "rss/trackback"
module RSS
- class TestTrackBack < TestCase
-
- def setup
- @prefix = "trackback"
- @uri = "http://madskills.com/public/xml/rss/module/trackback/"
-
- @parents = %w(item)
-
- @elems = {
- :ping => "http://bar.com/tb.cgi?tb_id=rssplustrackback",
- :about => "http://foo.com/trackback/tb.cgi?tb_id=20020923",
- }
-
- @content_nodes = @elems.collect do |name, value|
- "<#{@prefix}:#{name} rdf:resource=\"#{CGI.escapeHTML(value.to_s)}\"/>"
- end.join("\n")
-
- @content_nodes2 = @elems.collect do |name, value|
- "<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
- end.join("\n")
-
- @rss_source = make_RDF(<<-EOR, {@prefix => @uri})
+ class TestTrackBack < TestCase
+
+ def setup
+ @prefix = "trackback"
+ @uri = "http://madskills.com/public/xml/rss/module/trackback/"
+
+ @parents = %w(item)
+
+ @elems = {
+ :ping => "http://bar.com/tb.cgi?tb_id=rssplustrackback",
+ :about => "http://foo.com/trackback/tb.cgi?tb_id=20020923",
+ }
+
+ @content_nodes = @elems.collect do |name, value|
+ "<#{@prefix}:#{name} rdf:resource=\"#{CGI.escapeHTML(value.to_s)}\"/>"
+ end.join("\n")
+
+ @content_nodes2 = @elems.collect do |name, value|
+ "<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
+ end.join("\n")
+
+ @rss_source = make_RDF(<<-EOR, {@prefix => @uri})
#{make_channel()}
#{make_image()}
#{make_item(@content_nodes)}
#{make_textinput()}
EOR
- @rss = Parser.parse(@rss_source)
+ @rss = Parser.parse(@rss_source)
- @rss20_source = make_rss20(nil, {@prefix => @uri}) do
- make_channel20(nil) do
- make_item20(@content_nodes2)
- end
- end
+ @rss20_source = make_rss20(nil, {@prefix => @uri}) do
+ make_channel20(nil) do
+ make_item20(@content_nodes2)
+ end
+ end
- @rss20 = Parser.parse(@rss20_source, false)
- end
+ @rss20 = Parser.parse(@rss20_source, false)
+ end
- def test_parser
+ def test_parser
- assert_nothing_raised do
- Parser.parse(@rss_source)
- end
+ assert_nothing_raised do
+ Parser.parse(@rss_source)
+ end
- @elems.find_all{|k, v| k == :ping}.each do |tag, value|
- assert_too_much_tag(tag.to_s, "item") do
- Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
+ @elems.find_all{|k, v| k == :ping}.each do |tag, value|
+ assert_too_much_tag(tag.to_s, "item") do
+ Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
#{make_channel()}
#{make_item(("<" + @prefix + ":" + tag.to_s + " rdf:resource=\"" +
- CGI.escapeHTML(value.to_s) +
- "\"/>") * 2)}
+ CGI.escapeHTML(value.to_s) +
+ "\"/>") * 2)}
EOR
- end
- end
+ end
+ end
- @elems.find_all{|k, v| k == :about}.each do |tag, value|
- assert_missing_tag("trackback:ping", "item") do
- Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
+ @elems.find_all{|k, v| k == :about}.each do |tag, value|
+ assert_missing_tag("trackback:ping", "item") do
+ Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
#{make_channel()}
#{make_item(("<" + @prefix + ":" + tag.to_s + " rdf:resource=\"" +
- CGI.escapeHTML(value.to_s) +
- "\"/>") * 2)}
+ CGI.escapeHTML(value.to_s) +
+ "\"/>") * 2)}
EOR
- end
+ end
- end
+ end
- end
-
- def test_accessor
-
- new_value = {
- :ping => "http://baz.com/trackback/tb.cgi?tb_id=20030808",
- :about => "http://hoge.com/trackback/tb.cgi?tb_id=90030808",
- }
-
- @elems.each do |name, value|
- @parents.each do |parent|
- accessor = "#{RSS::TRACKBACK_PREFIX}_#{name}"
- target_accessor = "resource"
- target = @rss.send(parent).send(accessor)
- target20 = @rss20.channel.send(parent, -1)
- assert_equal(value, target.send(target_accessor))
- assert_equal(value, target20.send(accessor))
- target.send("#{target_accessor}=", new_value[name].to_s)
- if name == :about
- # abount is zero or more
- target20.send("#{accessor}=", 0, new_value[name].to_s)
- else
- target20.send("#{accessor}=", new_value[name].to_s)
- end
- assert_equal(new_value[name], target.send(target_accessor))
- assert_equal(new_value[name], target20.send(accessor))
- end
- end
-
- end
+ end
+
+ def test_accessor
+
+ new_value = {
+ :ping => "http://baz.com/trackback/tb.cgi?tb_id=20030808",
+ :about => "http://hoge.com/trackback/tb.cgi?tb_id=90030808",
+ }
+
+ @elems.each do |name, value|
+ @parents.each do |parent|
+ accessor = "#{RSS::TRACKBACK_PREFIX}_#{name}"
+ target_accessor = "resource"
+ target = @rss.send(parent).send(accessor)
+ target20 = @rss20.channel.send(parent, -1)
+ assert_equal(value, target.send(target_accessor))
+ assert_equal(value, target20.send(accessor))
+ target.send("#{target_accessor}=", new_value[name].to_s)
+ if name == :about
+ # abount is zero or more
+ target20.send("#{accessor}=", 0, new_value[name].to_s)
+ else
+ target20.send("#{accessor}=", new_value[name].to_s)
+ end
+ assert_equal(new_value[name], target.send(target_accessor))
+ assert_equal(new_value[name], target20.send(accessor))
+ end
+ end
+
+ end
- def test_to_s
-
- @elems.each do |name, value|
- excepted = %Q!<#{@prefix}:#{name} rdf:resource="#{CGI.escapeHTML(value)}"/>!
- @parents.each do |parent|
- meth = "#{RSS::TRACKBACK_PREFIX}_#{name}_element"
- meth << "s" if name == :about
- assert_equal(excepted, @rss.send(parent).send(meth))
- end
- end
-
- REXML::Document.new(@rss_source).root.each_element do |parent|
- if @parents.include?(parent.name)
- parent.each_element do |elem|
- if elem.namespace == @uri
- assert_equal(elem.attributes["resource"], @elems[elem.name.intern])
- end
- end
- end
- end
-
- end
-
- end
+ def test_to_s
+
+ @elems.each do |name, value|
+ excepted = %Q!<#{@prefix}:#{name} rdf:resource="#{CGI.escapeHTML(value)}"/>!
+ @parents.each do |parent|
+ meth = "#{RSS::TRACKBACK_PREFIX}_#{name}_element"
+ meth << "s" if name == :about
+ assert_equal(excepted, @rss.send(parent).send(meth))
+ end
+ end
+
+ REXML::Document.new(@rss_source).root.each_element do |parent|
+ if @parents.include?(parent.name)
+ parent.each_element do |elem|
+ if elem.namespace == @uri
+ assert_equal(elem.attributes["resource"], @elems[elem.name.intern])
+ end
+ end
+ end
+ end
+
+ end
+
+ end
end
diff --git a/test/rss/test_xml-stylesheet.rb b/test/rss/test_xml-stylesheet.rb
index ed056257d6..f3dee2c63b 100644
--- a/test/rss/test_xml-stylesheet.rb
+++ b/test/rss/test_xml-stylesheet.rb
@@ -8,103 +8,103 @@ require "rss/1.0"
require "rss/xml-stylesheet"
module RSS
- class TestXMLStyleSheet < TestCase
-
- def test_accessor
- [
- {:href => "a.xsl", :type => "text/xsl"},
- {:media => "print", :title => "FOO"},
- {:charset => "UTF-8", :alternate => "yes"},
- ].each do |attrs|
- assert_xml_stylesheet_attrs(XMLStyleSheet.new(*attrs), attrs)
- end
- end
-
- def test_to_s
- [
- {:href => "a.xsl", :type => "text/xsl"},
- {:type => "text/xsl"},
- {:href => "a.xsl", :guess_type => "text/xsl"},
- {:href => "a.css", :type => "text/css"},
- {:href => "a.css", :type => "text/xsl",
- :guess_type => "text/css"},
- {:href => "a.xsl", :type => "text/xsl",
- :title => "sample", :media => "printer",
- :charset => "UTF-8", :alternate => "yes"},
- {:href => "a.css", :guess_type => "text/css",
- :alternate => "no"},
- {:type => "text/xsl", :title => "sample",
- :media => "printer", :charset => "UTF-8",
- :alternate => "yes"},
- ].each do |attrs|
- target, contents = parse_pi(XMLStyleSheet.new(*attrs).to_s)
- assert_xml_stylesheet(target, XMLStyleSheet.new(*contents), attrs)
- end
- end
-
- def test_bad_alternate
- %w(a ___ ??? BAD_ALTERNATE).each do |value|
- xss = XMLStyleSheet.new
- assert_raise(NotAvailableValueError) do
- xss.alternate = value
- end
- xss.do_validate = false
- assert_nothing_raised do
- xss.alternate = value
- end
- assert_nil(xss.alternate)
- end
- end
-
- def test_parse
- [
- [{:href => "a.xsl", :type => "text/xsl"},],
- [{:media => "print", :title => "FOO"},],
- [{:charset => "UTF-8", :alternate => "yes"},],
- [{:href => "a.xsl", :type => "text/xsl"},
- {:type => "text/xsl"},
- {:href => "a.xsl", :guess_type => "text/xsl"},
- {:href => "a.css", :type => "text/css"},
- {:href => "a.css", :type => "text/xsl",
- :guess_type => "text/css"},
- {:href => "a.xsl", :type => "text/xsl",
- :title => "sample", :media => "printer",
- :charset => "UTF-8", :alternate => "yes"},
- {:href => "a.css", :guess_type => "text/css",
- :alternate => "no"},
- {:type => "text/xsl", :title => "sample",
- :media => "printer", :charset => "UTF-8",
- :alternate => "yes"},],
- ].each do |xsss|
- doc = REXML::Document.new(make_sample_RDF)
- root = doc.root
- xsss.each do |xss|
- content = xss.collect do |key, name|
- %Q[#{key}="#{name}"]
- end.join(" ")
- pi = REXML::Instruction.new("xml-stylesheet", content)
- root.previous_sibling = pi
- end
- rss = Parser.parse(doc.to_s)
- have_href_xsss = xsss.find_all {|xss| xss.has_key?(:href)}
- 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])
- end
- end
- end
-
- def parse_pi(pi)
- /\A\s*<\?(\S+)([^(?:\?>)]+)\?>\s*\z/ =~ pi
- target = $1
- dummy = REXML::Document.new("<dummy #{$2}/>").root
- contents = {}
- dummy.attributes.each do |name, value|
- contents[name] = value
- end
- [target, contents]
- end
-
- end
+ class TestXMLStyleSheet < TestCase
+
+ def test_accessor
+ [
+ {:href => "a.xsl", :type => "text/xsl"},
+ {:media => "print", :title => "FOO"},
+ {:charset => "UTF-8", :alternate => "yes"},
+ ].each do |attrs|
+ assert_xml_stylesheet_attrs(XMLStyleSheet.new(*attrs), attrs)
+ end
+ end
+
+ def test_to_s
+ [
+ {:href => "a.xsl", :type => "text/xsl"},
+ {:type => "text/xsl"},
+ {:href => "a.xsl", :guess_type => "text/xsl"},
+ {:href => "a.css", :type => "text/css"},
+ {:href => "a.css", :type => "text/xsl",
+ :guess_type => "text/css"},
+ {:href => "a.xsl", :type => "text/xsl",
+ :title => "sample", :media => "printer",
+ :charset => "UTF-8", :alternate => "yes"},
+ {:href => "a.css", :guess_type => "text/css",
+ :alternate => "no"},
+ {:type => "text/xsl", :title => "sample",
+ :media => "printer", :charset => "UTF-8",
+ :alternate => "yes"},
+ ].each do |attrs|
+ target, contents = parse_pi(XMLStyleSheet.new(*attrs).to_s)
+ assert_xml_stylesheet(target, XMLStyleSheet.new(*contents), attrs)
+ end
+ end
+
+ def test_bad_alternate
+ %w(a ___ ??? BAD_ALTERNATE).each do |value|
+ xss = XMLStyleSheet.new
+ assert_raise(NotAvailableValueError) do
+ xss.alternate = value
+ end
+ xss.do_validate = false
+ assert_nothing_raised do
+ xss.alternate = value
+ end
+ assert_nil(xss.alternate)
+ end
+ end
+
+ def test_parse
+ [
+ [{:href => "a.xsl", :type => "text/xsl"},],
+ [{:media => "print", :title => "FOO"},],
+ [{:charset => "UTF-8", :alternate => "yes"},],
+ [{:href => "a.xsl", :type => "text/xsl"},
+ {:type => "text/xsl"},
+ {:href => "a.xsl", :guess_type => "text/xsl"},
+ {:href => "a.css", :type => "text/css"},
+ {:href => "a.css", :type => "text/xsl",
+ :guess_type => "text/css"},
+ {:href => "a.xsl", :type => "text/xsl",
+ :title => "sample", :media => "printer",
+ :charset => "UTF-8", :alternate => "yes"},
+ {:href => "a.css", :guess_type => "text/css",
+ :alternate => "no"},
+ {:type => "text/xsl", :title => "sample",
+ :media => "printer", :charset => "UTF-8",
+ :alternate => "yes"},],
+ ].each do |xsss|
+ doc = REXML::Document.new(make_sample_RDF)
+ root = doc.root
+ xsss.each do |xss|
+ content = xss.collect do |key, name|
+ %Q[#{key}="#{name}"]
+ end.join(" ")
+ pi = REXML::Instruction.new("xml-stylesheet", content)
+ root.previous_sibling = pi
+ end
+ rss = Parser.parse(doc.to_s)
+ have_href_xsss = xsss.find_all {|xss| xss.has_key?(:href)}
+ 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])
+ end
+ end
+ end
+
+ def parse_pi(pi)
+ /\A\s*<\?(\S+)([^(?:\?>)]+)\?>\s*\z/ =~ pi
+ target = $1
+ dummy = REXML::Document.new("<dummy #{$2}/>").root
+ contents = {}
+ dummy.attributes.each do |name, value|
+ contents[name] = value
+ end
+ [target, contents]
+ end
+
+ end
end