summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2020-01-11 21:48:06 +0900
committerSHIBATA Hiroshi <hsbt@ruby-lang.org>2020-01-12 12:28:29 +0900
commit83240f315a10b42b53c3b62c1fbc428f97912665 (patch)
tree2d17b6aded6273ecd7b2c8a27bd4accfb7bd5f2d
parentc3ccf23d5807f2ff20127bf5e42df0977bf672fb (diff)
Make rss library to the bundle gems
[Feature #16485][ruby-core:96683]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2832
-rw-r--r--doc/maintainers.rdoc6
-rw-r--r--doc/standard_library.rdoc2
-rw-r--r--gems/bundled_gems1
-rw-r--r--lib/rss/0.9.rb462
-rw-r--r--lib/rss/1.0.rb485
-rw-r--r--lib/rss/2.0.rb143
-rw-r--r--lib/rss/atom.rb1025
-rw-r--r--lib/rss/content.rb34
-rw-r--r--lib/rss/content/1.0.rb10
-rw-r--r--lib/rss/content/2.0.rb12
-rw-r--r--lib/rss/converter.rb171
-rw-r--r--lib/rss/dublincore.rb164
-rw-r--r--lib/rss/dublincore/1.0.rb13
-rw-r--r--lib/rss/dublincore/2.0.rb13
-rw-r--r--lib/rss/dublincore/atom.rb17
-rw-r--r--lib/rss/image.rb198
-rw-r--r--lib/rss/itunes.rb425
-rw-r--r--lib/rss/maker.rb79
-rw-r--r--lib/rss/maker/0.9.rb509
-rw-r--r--lib/rss/maker/1.0.rb436
-rw-r--r--lib/rss/maker/2.0.rb224
-rw-r--r--lib/rss/maker/atom.rb173
-rw-r--r--lib/rss/maker/base.rb945
-rw-r--r--lib/rss/maker/content.rb22
-rw-r--r--lib/rss/maker/dublincore.rb122
-rw-r--r--lib/rss/maker/entry.rb164
-rw-r--r--lib/rss/maker/feed.rb427
-rw-r--r--lib/rss/maker/image.rb112
-rw-r--r--lib/rss/maker/itunes.rb243
-rw-r--r--lib/rss/maker/slash.rb34
-rw-r--r--lib/rss/maker/syndication.rb19
-rw-r--r--lib/rss/maker/taxonomy.rb119
-rw-r--r--lib/rss/maker/trackback.rb62
-rw-r--r--lib/rss/parser.rb589
-rw-r--r--lib/rss/rexmlparser.rb50
-rw-r--r--lib/rss/rss.gemspec80
-rw-r--r--lib/rss/rss.rb1342
-rw-r--r--lib/rss/slash.rb52
-rw-r--r--lib/rss/syndication.rb69
-rw-r--r--lib/rss/taxonomy.rb148
-rw-r--r--lib/rss/trackback.rb291
-rw-r--r--lib/rss/utils.rb200
-rw-r--r--lib/rss/version.rb4
-rw-r--r--lib/rss/xml-stylesheet.rb106
-rw-r--r--lib/rss/xml.rb72
-rw-r--r--lib/rss/xmlparser.rb95
-rw-r--r--lib/rss/xmlscanner.rb122
-rw-r--r--test/rss/dot.pngbin111 -> 0 bytes
-rw-r--r--test/rss/rss-assertions.rb2120
-rw-r--r--test/rss/rss-testcase.rb479
-rw-r--r--test/rss/test_1.0.rb308
-rw-r--r--test/rss/test_2.0.rb412
-rw-r--r--test/rss/test_accessor.rb104
-rw-r--r--test/rss/test_atom.rb684
-rw-r--r--test/rss/test_content.rb105
-rw-r--r--test/rss/test_dublincore.rb270
-rw-r--r--test/rss/test_image.rb215
-rw-r--r--test/rss/test_inherit.rb41
-rw-r--r--test/rss/test_itunes.rb356
-rw-r--r--test/rss/test_maker_0.9.rb477
-rw-r--r--test/rss/test_maker_1.0.rb519
-rw-r--r--test/rss/test_maker_2.0.rb758
-rw-r--r--test/rss/test_maker_atom_entry.rb394
-rw-r--r--test/rss/test_maker_atom_feed.rb455
-rw-r--r--test/rss/test_maker_content.rb48
-rw-r--r--test/rss/test_maker_dc.rb150
-rw-r--r--test/rss/test_maker_image.rb63
-rw-r--r--test/rss/test_maker_itunes.rb487
-rw-r--r--test/rss/test_maker_slash.rb38
-rw-r--r--test/rss/test_maker_sy.rb45
-rw-r--r--test/rss/test_maker_taxo.rb82
-rw-r--r--test/rss/test_maker_trackback.rb42
-rw-r--r--test/rss/test_maker_xml-stylesheet.rb84
-rw-r--r--test/rss/test_parser.rb121
-rw-r--r--test/rss/test_parser_1.0.rb529
-rw-r--r--test/rss/test_parser_2.0.rb123
-rw-r--r--test/rss/test_parser_atom_entry.rb164
-rw-r--r--test/rss/test_parser_atom_feed.rb277
-rw-r--r--test/rss/test_setup_maker_0.9.rb247
-rw-r--r--test/rss/test_setup_maker_1.0.rb551
-rw-r--r--test/rss/test_setup_maker_2.0.rb309
-rw-r--r--test/rss/test_setup_maker_atom_entry.rb410
-rw-r--r--test/rss/test_setup_maker_atom_feed.rb446
-rw-r--r--test/rss/test_setup_maker_itunes.rb144
-rw-r--r--test/rss/test_setup_maker_slash.rb39
-rw-r--r--test/rss/test_slash.rb65
-rw-r--r--test/rss/test_syndication.rb126
-rw-r--r--test/rss/test_taxonomy.rb173
-rw-r--r--test/rss/test_to_s.rb701
-rw-r--r--test/rss/test_trackback.rb136
-rw-r--r--test/rss/test_xml-stylesheet.rb109
-rw-r--r--tool/sync_default_gems.rb4
92 files changed, 5 insertions, 23496 deletions
diff --git a/doc/maintainers.rdoc b/doc/maintainers.rdoc
index c8b4f9af20b..87221bb8f9f 100644
--- a/doc/maintainers.rdoc
+++ b/doc/maintainers.rdoc
@@ -239,10 +239,6 @@ Zachary Scott (zzak)
aycabta
https://github.com/ruby/reline
https://rubygems.org/gems/reline
-[lib/rss.rb, lib/rss/*]
- Kouhei Sutou (kou)
- https://github.com/ruby/rss
- https://rubygems.org/gems/rss
[lib/singleton.rb]
Yukihiro Matsumoto (matz)
https://github.com/ruby/singleton
@@ -355,3 +351,5 @@ Zachary Scott (zzak)
https://github.com/ruby/xmlrpc
[rexml]
https://github.com/ruby/rexml
+[rss]
+ https://github.com/ruby/rss
diff --git a/doc/standard_library.rdoc b/doc/standard_library.rdoc
index 82dda4b532f..c9f72a13c56 100644
--- a/doc/standard_library.rdoc
+++ b/doc/standard_library.rdoc
@@ -80,7 +80,6 @@ Prime:: Prime numbers and factorization library
PStore:: Implements a file based persistence mechanism based on a Hash
Racc:: A LALR(1) parser generator written in Ruby.
RDoc:: Produces HTML and command-line documentation for Ruby
-RSS:: Family of libraries that support various formats of XML "feeds"
Singleton:: Implementation of the Singleton pattern for Ruby
Timeout:: Auto-terminate potentially long-running operations in Ruby
Tracer:: Outputs a source level execution trace of a Ruby program
@@ -119,3 +118,4 @@ Rake:: Ruby build program with capabilities similar to make
Test::Unit:: A compatibility layer for MiniTest
XMLRPC:: Remote Procedure Call over HTTP support for Ruby
REXML:: An XML toolkit for Ruby
+RSS:: Family of libraries that support various formats of XML "feeds"
diff --git a/gems/bundled_gems b/gems/bundled_gems
index 635ff1d1c6d..065a6241d29 100644
--- a/gems/bundled_gems
+++ b/gems/bundled_gems
@@ -5,3 +5,4 @@ rake 13.0.1 https://github.com/ruby/rake
test-unit 3.3.4 https://github.com/test-unit/test-unit
xmlrpc 0.3.0 https://github.com/ruby/xmlrpc
rexml 3.2.3 https://github.com/ruby/rexml
+rss 0.2.8 https://github.com/ruby/rss
diff --git a/lib/rss/0.9.rb b/lib/rss/0.9.rb
deleted file mode 100644
index 219ccefcdbc..00000000000
--- a/lib/rss/0.9.rb
+++ /dev/null
@@ -1,462 +0,0 @@
-# frozen_string_literal: false
-require_relative "parser"
-
-module RSS
-
- ##
- # = RSS 0.9 support
- #
- # RSS has three different versions. This module contains support for version
- # 0.9.1[http://www.rssboard.org/rss-0-9-1-netscape].
- #
- # == Producing RSS 0.9
- #
- # Producing our own RSS feeds is easy as well. Let's make a very basic feed:
- #
- # require "rss"
- #
- # rss = RSS::Maker.make("0.91") do |maker|
- # maker.channel.language = "en"
- # maker.channel.author = "matz"
- # maker.channel.updated = Time.now.to_s
- # maker.channel.link = "http://www.ruby-lang.org/en/feeds/news.rss"
- # maker.channel.title = "Example Feed"
- # maker.channel.description = "A longer description of my feed."
- # maker.image.url = "http://www.ruby-lang.org/images/logo.gif"
- # maker.image.title = "An image"
- # maker.items.new_item do |item|
- # item.link = "http://www.ruby-lang.org/en/news/2010/12/25/ruby-1-9-2-p136-is-released/"
- # item.title = "Ruby 1.9.2-p136 is released"
- # item.updated = Time.now.to_s
- # end
- # end
- #
- # puts rss
- #
- # As you can see, this is a very Builder-like DSL. This code will spit out an
- # RSS 0.9 feed with one item. If we needed a second item, we'd make another
- # block with maker.items.new_item and build a second one.
- module RSS09
- NSPOOL = {}
- ELEMENTS = []
-
- def self.append_features(klass)
- super
-
- klass.install_must_call_validator('', "")
- end
- end
-
- class Rss < Element
-
- include RSS09
- include RootElementMixin
-
- %w(channel).each do |name|
- install_have_child_element(name, "", nil)
- end
-
- attr_writer :feed_version
- alias_method(:rss_version, :feed_version)
- alias_method(:rss_version=, :feed_version=)
-
- def initialize(feed_version, version=nil, encoding=nil, standalone=nil)
- super
- @feed_type = "rss"
- end
-
- def items
- if @channel
- @channel.items
- else
- []
- end
- end
-
- def image
- if @channel
- @channel.image
- else
- nil
- end
- end
-
- def textinput
- if @channel
- @channel.textInput
- else
- nil
- end
- end
-
- def setup_maker_elements(maker)
- super
- items.each do |item|
- item.setup_maker(maker.items)
- end
- image.setup_maker(maker) if image
- textinput.setup_maker(maker) if textinput
- end
-
- private
- def _attrs
- [
- ["version", true, "feed_version"],
- ]
- end
-
- class Channel < Element
-
- include RSS09
-
- [
- ["title", nil, :text],
- ["link", nil, :text],
- ["description", nil, :text],
- ["language", nil, :text],
- ["copyright", "?", :text],
- ["managingEditor", "?", :text],
- ["webMaster", "?", :text],
- ["rating", "?", :text],
- ["pubDate", "?", :date, :rfc822],
- ["lastBuildDate", "?", :date, :rfc822],
- ["docs", "?", :text],
- ["cloud", "?", :have_attribute],
- ["skipDays", "?", :have_child],
- ["skipHours", "?", :have_child],
- ["image", nil, :have_child],
- ["item", "*", :have_children],
- ["textInput", "?", :have_child],
- ].each do |name, occurs, type, *args|
- __send__("install_#{type}_element", name, "", occurs, name, *args)
- end
- alias date pubDate
- alias date= pubDate=
-
- private
- def maker_target(maker)
- maker.channel
- end
-
- def setup_maker_elements(channel)
- super
- [
- [skipDays, "day"],
- [skipHours, "hour"],
- ].each do |skip, key|
- if skip
- skip.__send__("#{key}s").each do |val|
- target_skips = channel.__send__("skip#{key.capitalize}s")
- new_target = target_skips.__send__("new_#{key}")
- new_target.content = val.content
- end
- end
- end
- end
-
- def not_need_to_call_setup_maker_variables
- %w(image textInput)
- end
-
- class SkipDays < Element
- include RSS09
-
- [
- ["day", "*"]
- ].each do |name, occurs|
- install_have_children_element(name, "", occurs)
- end
-
- class Day < Element
- include RSS09
-
- content_setup
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.content = args[0]
- end
- end
-
- end
-
- end
-
- class SkipHours < Element
- include RSS09
-
- [
- ["hour", "*"]
- ].each do |name, occurs|
- install_have_children_element(name, "", occurs)
- end
-
- class Hour < Element
- include RSS09
-
- content_setup(:integer)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.content = args[0]
- end
- end
- end
-
- end
-
- class Image < Element
-
- include RSS09
-
- %w(url title link).each do |name|
- install_text_element(name, "", nil)
- end
- [
- ["width", :integer],
- ["height", :integer],
- ["description"],
- ].each do |name, type|
- install_text_element(name, "", "?", name, type)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.url = args[0]
- self.title = args[1]
- self.link = args[2]
- self.width = args[3]
- self.height = args[4]
- self.description = args[5]
- end
- end
-
- private
- def maker_target(maker)
- maker.image
- end
- end
-
- class Cloud < Element
-
- include RSS09
-
- [
- ["domain", "", true],
- ["port", "", true, :integer],
- ["path", "", true],
- ["registerProcedure", "", true],
- ["protocol", "", true],
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.domain = args[0]
- self.port = args[1]
- self.path = args[2]
- self.registerProcedure = args[3]
- self.protocol = args[4]
- end
- end
- end
-
- class Item < Element
-
- include RSS09
-
- [
- ["title", '?', :text],
- ["link", '?', :text],
- ["description", '?', :text],
- ["category", '*', :have_children, "categories"],
- ["source", '?', :have_child],
- ["enclosure", '?', :have_child],
- ].each do |tag, occurs, type, *args|
- __send__("install_#{type}_element", tag, "", occurs, tag, *args)
- end
-
- private
- def maker_target(items)
- if items.respond_to?("items")
- # For backward compatibility
- items = items.items
- end
- items.new_item
- end
-
- def setup_maker_element(item)
- super
- @enclosure.setup_maker(item) if @enclosure
- @source.setup_maker(item) if @source
- end
-
- class Source < Element
-
- include RSS09
-
- [
- ["url", "", true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- content_setup
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.url = args[0]
- self.content = args[1]
- end
- end
-
- private
- def maker_target(item)
- item.source
- end
-
- def setup_maker_attributes(source)
- source.url = url
- source.content = content
- end
- end
-
- class Enclosure < Element
-
- include RSS09
-
- [
- ["url", "", true],
- ["length", "", true, :integer],
- ["type", "", true],
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.url = args[0]
- self.length = args[1]
- self.type = args[2]
- end
- end
-
- private
- def maker_target(item)
- item.enclosure
- end
-
- def setup_maker_attributes(enclosure)
- enclosure.url = url
- enclosure.length = length
- enclosure.type = type
- end
- end
-
- class Category < Element
-
- include RSS09
-
- [
- ["domain", "", false]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- content_setup
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.domain = args[0]
- self.content = args[1]
- end
- end
-
- private
- def maker_target(item)
- item.new_category
- end
-
- def setup_maker_attributes(category)
- category.domain = domain
- category.content = content
- end
-
- end
-
- end
-
- class TextInput < Element
-
- include RSS09
-
- %w(title description name link).each do |name|
- install_text_element(name, "", nil)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.title = args[0]
- self.description = args[1]
- self.name = args[2]
- self.link = args[3]
- end
- end
-
- private
- def maker_target(maker)
- maker.textinput
- end
- end
-
- end
-
- end
-
- RSS09::ELEMENTS.each do |name|
- BaseListener.install_get_text_element("", name, name)
- end
-
- module ListenerMixin
- private
- def initial_start_rss(tag_name, prefix, attrs, ns)
- check_ns(tag_name, prefix, ns, "", false)
-
- @rss = Rss.new(attrs['version'], @version, @encoding, @standalone)
- @rss.do_validate = @do_validate
- @rss.xml_stylesheets = @xml_stylesheets
- @last_element = @rss
- pr = Proc.new do |text, tags|
- @rss.validate_for_stream(tags, @ignore_unknown_element) if @do_validate
- end
- @proc_stack.push(pr)
- end
-
- end
-
-end
diff --git a/lib/rss/1.0.rb b/lib/rss/1.0.rb
deleted file mode 100644
index c8f92fb54ef..00000000000
--- a/lib/rss/1.0.rb
+++ /dev/null
@@ -1,485 +0,0 @@
-# frozen_string_literal: false
-require_relative "parser"
-
-module RSS
-
- ##
- # = RSS 1.0 support
- #
- # RSS has three different versions. This module contains support for version
- # 1.0[http://web.resource.org/rss/1.0/]
- #
- # == Producing RSS 1.0
- #
- # Producing our own RSS feeds is easy as well. Let's make a very basic feed:
- #
- # require "rss"
- #
- # rss = RSS::Maker.make("1.0") do |maker|
- # maker.channel.language = "en"
- # maker.channel.author = "matz"
- # maker.channel.about = "About my feed."
- # maker.channel.updated = Time.now.to_s
- # maker.channel.link = "http://www.ruby-lang.org/en/feeds/news.rss"
- # maker.channel.title = "Example Feed"
- # maker.channel.description = "A longer description of my feed."
- # maker.items.new_item do |item|
- # item.link = "http://www.ruby-lang.org/en/news/2010/12/25/ruby-1-9-2-p136-is-released/"
- # item.title = "Ruby 1.9.2-p136 is released"
- # item.updated = Time.now.to_s
- # end
- # end
- #
- # puts rss
- #
- # As you can see, this is a very Builder-like DSL. This code will spit out an
- # RSS 1.0 feed with one item. If we needed a second item, we'd make another
- # block with maker.items.new_item and build a second one.
- module RSS10
- NSPOOL = {}
- ELEMENTS = []
-
- def self.append_features(klass)
- super
-
- klass.install_must_call_validator('', ::RSS::URI)
- end
-
- end
-
- class RDF < Element
-
- include RSS10
- include RootElementMixin
-
- class << self
-
- def required_uri
- URI
- end
-
- end
-
- @tag_name = 'RDF'
-
- PREFIX = 'rdf'
- URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-
- install_ns('', ::RSS::URI)
- install_ns(PREFIX, URI)
-
- [
- ["channel", nil],
- ["image", "?"],
- ["item", "+", :children],
- ["textinput", "?"],
- ].each do |tag, occurs, type|
- type ||= :child
- __send__("install_have_#{type}_element", tag, ::RSS::URI, occurs)
- end
-
- alias_method(:rss_version, :feed_version)
- def initialize(version=nil, encoding=nil, standalone=nil)
- super('1.0', version, encoding, standalone)
- @feed_type = "rss"
- end
-
- def full_name
- tag_name_with_prefix(PREFIX)
- end
-
- class Li < Element
-
- include RSS10
-
- class << self
- def required_uri
- URI
- end
- end
-
- [
- ["resource", [URI, ""], true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.resource = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(PREFIX)
- end
- end
-
- class Seq < Element
-
- include RSS10
-
- Li = ::RSS::RDF::Li
-
- class << self
- def required_uri
- URI
- end
- end
-
- @tag_name = 'Seq'
-
- install_have_children_element("li", URI, "*")
- install_must_call_validator('rdf', ::RSS::RDF::URI)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- @li = args[0] if args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(PREFIX)
- end
-
- def setup_maker(target)
- lis.each do |li|
- target << li.resource
- end
- end
- end
-
- class Bag < Element
-
- include RSS10
-
- Li = ::RSS::RDF::Li
-
- class << self
- def required_uri
- URI
- end
- end
-
- @tag_name = 'Bag'
-
- install_have_children_element("li", URI, "*")
- install_must_call_validator('rdf', URI)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- @li = args[0] if args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(PREFIX)
- end
-
- def setup_maker(target)
- lis.each do |li|
- target << li.resource
- end
- 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, nil, nil,
- "#{PREFIX}:#{name}")
- end
-
- [
- ['title', nil, :text],
- ['link', nil, :text],
- ['description', nil, :text],
- ['image', '?', :have_child],
- ['items', nil, :have_child],
- ['textinput', '?', :have_child],
- ].each do |tag, occurs, type|
- __send__("install_#{type}_element", tag, ::RSS::URI, occurs)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.about = args[0]
- end
- end
-
- private
- def maker_target(maker)
- maker.channel
- end
-
- def setup_maker_attributes(channel)
- channel.about = about
- 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, nil, nil,
- "#{PREFIX}:#{name}")
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.resource = args[0]
- end
- 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, nil, nil,
- "#{PREFIX}:#{name}")
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.resource = args[0]
- end
- end
- end
-
- class Items < Element
-
- include RSS10
-
- Seq = ::RSS::RDF::Seq
-
- class << self
-
- def required_uri
- ::RSS::URI
- end
-
- end
-
- install_have_child_element("Seq", URI, nil)
- install_must_call_validator('rdf', URI)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.Seq = args[0]
- end
- self.Seq ||= Seq.new
- end
-
- def resources
- if @Seq
- @Seq.lis.collect do |li|
- li.resource
- end
- else
- []
- end
- 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, nil, nil,
- "#{PREFIX}:#{name}")
- end
-
- %w(title url link).each do |name|
- install_text_element(name, ::RSS::URI, nil)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.about = args[0]
- end
- end
-
- private
- def maker_target(maker)
- maker.image
- 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, nil, nil,
- "#{PREFIX}:#{name}")
- end
-
- [
- ["title", nil],
- ["link", nil],
- ["description", "?"],
- ].each do |tag, occurs|
- install_text_element(tag, ::RSS::URI, occurs)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.about = args[0]
- end
- end
-
- private
- def maker_target(items)
- if items.respond_to?("items")
- # For backward compatibility
- items = items.items
- end
- items.new_item
- 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, nil, nil,
- "#{PREFIX}:#{name}")
- end
-
- %w(title description name link).each do |name|
- install_text_element(name, ::RSS::URI, nil)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.about = args[0]
- end
- end
-
- private
- def maker_target(maker)
- maker.textinput
- end
- end
-
- end
-
- RSS10::ELEMENTS.each do |name|
- BaseListener.install_get_text_element(URI, name, name)
- end
-
- module ListenerMixin
- private
- def initial_start_RDF(tag_name, prefix, attrs, ns)
- check_ns(tag_name, prefix, ns, RDF::URI, false)
-
- @rss = RDF.new(@version, @encoding, @standalone)
- @rss.do_validate = @do_validate
- @rss.xml_stylesheets = @xml_stylesheets
- @last_element = @rss
- pr = Proc.new do |text, tags|
- @rss.validate_for_stream(tags, @ignore_unknown_element) if @do_validate
- end
- @proc_stack.push(pr)
- end
- end
-
-end
diff --git a/lib/rss/2.0.rb b/lib/rss/2.0.rb
deleted file mode 100644
index 13f9ade918a..00000000000
--- a/lib/rss/2.0.rb
+++ /dev/null
@@ -1,143 +0,0 @@
-# frozen_string_literal: false
-require "rss/0.9"
-
-module RSS
-
- ##
- # = RSS 2.0 support
- #
- # RSS has three different versions. This module contains support for version
- # 2.0[http://www.rssboard.org/rss-specification]
- #
- # == Producing RSS 2.0
- #
- # Producing our own RSS feeds is easy as well. Let's make a very basic feed:
- #
- # require "rss"
- #
- # rss = RSS::Maker.make("2.0") do |maker|
- # maker.channel.language = "en"
- # maker.channel.author = "matz"
- # maker.channel.updated = Time.now.to_s
- # maker.channel.link = "http://www.ruby-lang.org/en/feeds/news.rss"
- # maker.channel.title = "Example Feed"
- # maker.channel.description = "A longer description of my feed."
- # maker.items.new_item do |item|
- # item.link = "http://www.ruby-lang.org/en/news/2010/12/25/ruby-1-9-2-p136-is-released/"
- # item.title = "Ruby 1.9.2-p136 is released"
- # item.updated = Time.now.to_s
- # end
- # end
- #
- # puts rss
- #
- # As you can see, this is a very Builder-like DSL. This code will spit out an
- # RSS 2.0 feed with one item. If we needed a second item, we'd make another
- # block with maker.items.new_item and build a second one.
- class Rss
-
- class Channel
-
- [
- ["generator"],
- ["ttl", :integer],
- ].each do |name, type|
- install_text_element(name, "", "?", name, type)
- end
-
- [
- %w(category categories),
- ].each do |name, plural_name|
- install_have_children_element(name, "", "*", name, plural_name)
- end
-
- [
- ["image", "?"],
- ["language", "?"],
- ].each do |name, occurs|
- install_model(name, "", occurs)
- end
-
- Category = Item::Category
-
- class Item
-
- [
- ["comments", "?"],
- ["author", "?"],
- ].each do |name, occurs|
- install_text_element(name, "", occurs)
- end
-
- [
- ["pubDate", '?'],
- ].each do |name, occurs|
- install_date_element(name, "", occurs, name, 'rfc822')
- end
- alias date pubDate
- alias date= pubDate=
-
- [
- ["guid", '?'],
- ].each do |name, occurs|
- install_have_child_element(name, "", occurs)
- end
-
- private
- alias _setup_maker_element setup_maker_element
- def setup_maker_element(item)
- _setup_maker_element(item)
- @guid.setup_maker(item) if @guid
- end
-
- class Guid < Element
-
- include RSS09
-
- [
- ["isPermaLink", "", false, :boolean]
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- content_setup
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.isPermaLink = args[0]
- self.content = args[1]
- end
- end
-
- alias_method :_PermaLink?, :PermaLink?
- private :_PermaLink?
- def PermaLink?
- perma = _PermaLink?
- perma or perma.nil?
- end
-
- private
- def maker_target(item)
- item.guid
- end
-
- def setup_maker_attributes(guid)
- guid.isPermaLink = isPermaLink
- guid.content = content
- end
- end
-
- end
-
- end
-
- end
-
- RSS09::ELEMENTS.each do |name|
- BaseListener.install_get_text_element("", name, name)
- end
-
-end
diff --git a/lib/rss/atom.rb b/lib/rss/atom.rb
deleted file mode 100644
index 48c27330d0b..00000000000
--- a/lib/rss/atom.rb
+++ /dev/null
@@ -1,1025 +0,0 @@
-# frozen_string_literal: false
-require_relative 'parser'
-
-module RSS
- ##
- # Atom is an XML-based document format that is used to describe 'feeds' of related information.
- # A typical use is in a news feed where the information is periodically updated and which users
- # can subscribe to. The Atom format is described in http://tools.ietf.org/html/rfc4287
- #
- # The Atom module provides support in reading and creating feeds.
- #
- # See the RSS module for examples consuming and creating feeds.
- module Atom
-
- ##
- # The Atom URI W3C Namespace
-
- URI = "http://www.w3.org/2005/Atom"
-
- ##
- # The XHTML URI W3C Namespace
-
- XHTML_URI = "http://www.w3.org/1999/xhtml"
-
- module CommonModel
- NSPOOL = {}
- ELEMENTS = []
-
- def self.append_features(klass)
- super
- klass.install_must_call_validator("atom", URI)
- [
- ["lang", :xml],
- ["base", :xml],
- ].each do |name, uri, required|
- klass.install_get_attribute(name, uri, required, [nil, :inherit])
- end
- klass.class_eval do
- class << self
- # Returns the Atom URI W3C Namespace
- def required_uri
- URI
- end
-
- # Returns true
- def need_parent?
- true
- end
- end
- end
- end
- end
-
- module ContentModel
- module ClassMethods
- def content_type
- @content_type ||= nil
- end
- end
-
- class << self
- def append_features(klass)
- super
- klass.extend(ClassMethods)
- klass.content_setup(klass.content_type, klass.tag_name)
- end
- end
-
- def maker_target(target)
- target
- end
-
- private
- def setup_maker_element_writer
- "#{self.class.name.split(/::/).last.downcase}="
- end
-
- def setup_maker_element(target)
- target.__send__(setup_maker_element_writer, content)
- super
- end
- end
-
- module URIContentModel
- class << self
- def append_features(klass)
- super
- klass.class_eval do
- @content_type = [nil, :uri]
- include(ContentModel)
- end
- end
- end
- end
-
- # The TextConstruct module is used to define a Text construct Atom element,
- # which is used to store small quantities of human-readable text.
- #
- # The TextConstruct has a type attribute, e.g. text, html, xhtml
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#text.constructs
- module TextConstruct
- def self.append_features(klass)
- super
- klass.class_eval do
- [
- ["type", ""],
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required, :text_type)
- end
-
- content_setup
- add_need_initialize_variable("xhtml")
-
- class << self
- def xml_getter
- "xhtml"
- end
-
- def xml_setter
- "xhtml="
- end
- end
- end
- end
-
- attr_writer :xhtml
-
- # Returns or builds the XHTML content.
- def xhtml
- return @xhtml if @xhtml.nil?
- if @xhtml.is_a?(XML::Element) and
- [@xhtml.name, @xhtml.uri] == ["div", XHTML_URI]
- return @xhtml
- end
-
- children = @xhtml
- children = [children] unless children.is_a?(Array)
- XML::Element.new("div", nil, XHTML_URI,
- {"xmlns" => XHTML_URI}, children)
- end
-
- # Returns true if type is "xhtml".
- def have_xml_content?
- @type == "xhtml"
- end
-
- # Raises a MissingTagError or NotExpectedTagError
- # if the element is not properly formatted.
- def atom_validate(ignore_unknown_element, tags, uri)
- if have_xml_content?
- if @xhtml.nil?
- raise MissingTagError.new("div", tag_name)
- end
- unless [@xhtml.name, @xhtml.uri] == ["div", XHTML_URI]
- raise NotExpectedTagError.new(@xhtml.name, @xhtml.uri, tag_name)
- end
- end
- end
-
- private
- def maker_target(target)
- target.__send__(self.class.name.split(/::/).last.downcase) {|x| x}
- end
-
- def setup_maker_attributes(target)
- target.type = type
- target.content = content
- target.xml_content = @xhtml
- end
- end
-
- # The PersonConstruct module is used to define a person Atom element that can be
- # used to describe a person, corporation or similar entity.
- #
- # The PersonConstruct has a Name, Uri and Email child elements.
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#atomPersonConstruct
- module PersonConstruct
-
- # Adds attributes for name, uri, and email to the +klass+
- def self.append_features(klass)
- super
- klass.class_eval do
- [
- ["name", nil],
- ["uri", "?"],
- ["email", "?"],
- ].each do |tag, occurs|
- install_have_attribute_element(tag, URI, occurs, nil, :content)
- end
- end
- end
-
- def maker_target(target)
- target.__send__("new_#{self.class.name.split(/::/).last.downcase}")
- end
-
- # The name of the person or entity.
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.name
- class Name < RSS::Element
- include CommonModel
- include ContentModel
- end
-
- # The URI of the person or entity.
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.uri
- class Uri < RSS::Element
- include CommonModel
- include URIContentModel
- end
-
- # The email of the person or entity.
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.email
- class Email < RSS::Element
- include CommonModel
- include ContentModel
- end
- end
-
- # Element used to describe an Atom date and time in the ISO 8601 format
- #
- # Examples:
- # * 2013-03-04T15:30:02Z
- # * 2013-03-04T10:30:02-05:00
- module DateConstruct
- def self.append_features(klass)
- super
- klass.class_eval do
- @content_type = :w3cdtf
- include(ContentModel)
- end
- end
-
- # Raises NotAvailableValueError if element content is nil
- def atom_validate(ignore_unknown_element, tags, uri)
- raise NotAvailableValueError.new(tag_name, "") if content.nil?
- end
- end
-
- module DuplicateLinkChecker
- # Checks if there are duplicate links with the same type and hreflang attributes
- # that have an alternate (or empty) rel attribute
- #
- # Raises a TooMuchTagError if there are duplicates found
- def validate_duplicate_links(links)
- link_infos = {}
- links.each do |link|
- rel = link.rel || "alternate"
- next unless rel == "alternate"
- key = [link.hreflang, link.type]
- if link_infos.has_key?(key)
- raise TooMuchTagError.new("link", tag_name)
- end
- link_infos[key] = true
- end
- end
- end
-
- # Defines the top-level element of an Atom Feed Document.
- # It consists of a number of children Entry elements,
- # and has the following attributes:
- #
- # * author
- # * categories
- # * category
- # * content
- # * contributor
- # * entries (aliased as items)
- # * entry
- # * generator
- # * icon
- # * id
- # * link
- # * logo
- # * rights
- # * subtitle
- # * title
- # * updated
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.feed
- class Feed < RSS::Element
- include RootElementMixin
- include CommonModel
- include DuplicateLinkChecker
-
- install_ns('', URI)
-
- [
- ["author", "*", :children],
- ["category", "*", :children, "categories"],
- ["contributor", "*", :children],
- ["generator", "?"],
- ["icon", "?", nil, :content],
- ["id", nil, nil, :content],
- ["link", "*", :children],
- ["logo", "?"],
- ["rights", "?"],
- ["subtitle", "?", nil, :content],
- ["title", nil, nil, :content],
- ["updated", nil, nil, :content],
- ["entry", "*", :children, "entries"],
- ].each do |tag, occurs, type, *args|
- type ||= :child
- __send__("install_have_#{type}_element",
- tag, URI, occurs, tag, *args)
- end
-
- # Creates a new Atom feed
- def initialize(version=nil, encoding=nil, standalone=nil)
- super("1.0", version, encoding, standalone)
- @feed_type = "atom"
- @feed_subtype = "feed"
- end
-
- alias_method :items, :entries
-
- # Returns true if there are any authors for the feed or any of the Entry
- # child elements have an author
- def have_author?
- authors.any? {|author| !author.to_s.empty?} or
- entries.any? {|entry| entry.have_author?(false)}
- end
-
- private
- def atom_validate(ignore_unknown_element, tags, uri)
- unless have_author?
- raise MissingTagError.new("author", tag_name)
- end
- validate_duplicate_links(links)
- end
-
- def have_required_elements?
- super and have_author?
- end
-
- def maker_target(maker)
- maker.channel
- end
-
- def setup_maker_element(channel)
- prev_dc_dates = channel.dc_dates.to_a.dup
- super
- channel.about = id.content if id
- channel.dc_dates.replace(prev_dc_dates)
- end
-
- def setup_maker_elements(channel)
- super
- items = channel.maker.items
- entries.each do |entry|
- entry.setup_maker(items)
- end
- end
-
- # PersonConstruct that contains information regarding the author
- # of a Feed or Entry.
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.author
- class Author < RSS::Element
- include CommonModel
- include PersonConstruct
- end
-
- # Contains information about a category associated with a Feed or Entry.
- # It has the following attributes:
- #
- # * term
- # * scheme
- # * label
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.category
- class Category < RSS::Element
- include CommonModel
-
- [
- ["term", "", true],
- ["scheme", "", false, [nil, :uri]],
- ["label", ""],
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- private
- def maker_target(target)
- target.new_category
- end
- end
-
- # PersonConstruct that contains information regarding the
- # contributors of a Feed or Entry.
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.contributor
- class Contributor < RSS::Element
- include CommonModel
- include PersonConstruct
- end
-
- # Contains information on the agent used to generate the feed.
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.generator
- class Generator < RSS::Element
- include CommonModel
- include ContentModel
-
- [
- ["uri", "", false, [nil, :uri]],
- ["version", ""],
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- private
- def setup_maker_attributes(target)
- target.generator do |generator|
- generator.uri = uri if uri
- generator.version = version if version
- end
- end
- end
-
- # Defines an image that provides a visual identification for a eed.
- # The image should have an aspect ratio of 1:1.
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.icon
- class Icon < RSS::Element
- include CommonModel
- include URIContentModel
- end
-
- # Defines the Universally Unique Identifier (UUID) for a Feed or Entry.
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.id
- class Id < RSS::Element
- include CommonModel
- include URIContentModel
- end
-
- # Defines a reference to a Web resource. It has the following
- # attributes:
- #
- # * href
- # * rel
- # * type
- # * hreflang
- # * title
- # * length
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.link
- class Link < RSS::Element
- include CommonModel
-
- [
- ["href", "", true, [nil, :uri]],
- ["rel", ""],
- ["type", ""],
- ["hreflang", ""],
- ["title", ""],
- ["length", ""],
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- private
- def maker_target(target)
- target.new_link
- end
- end
-
- # Defines an image that provides a visual identification for the Feed.
- # The image should have an aspect ratio of 2:1 (horizontal:vertical).
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.logo
- class Logo < RSS::Element
- include CommonModel
- include URIContentModel
-
- def maker_target(target)
- target.maker.image
- end
-
- private
- def setup_maker_element_writer
- "url="
- end
- end
-
- # TextConstruct that contains copyright information regarding
- # the content in an Entry or Feed. It should not be used to
- # convey machine readable licensing information.
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.rights
- class Rights < RSS::Element
- include CommonModel
- include TextConstruct
- end
-
- # TextConstruct that conveys a description or subtitle for a Feed.
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.subtitle
- class Subtitle < RSS::Element
- include CommonModel
- include TextConstruct
- end
-
- # TextConstruct that conveys a description or title for a Feed or Entry.
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.title
- class Title < RSS::Element
- include CommonModel
- include TextConstruct
- end
-
- # DateConstruct indicating the most recent time when a Feed or
- # Entry was modified in a way the publisher considers
- # significant.
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.updated
- class Updated < RSS::Element
- include CommonModel
- include DateConstruct
- end
-
- # Defines a child Atom Entry element of an Atom Feed element.
- # It has the following attributes:
- #
- # * author
- # * category
- # * categories
- # * content
- # * contributor
- # * id
- # * link
- # * published
- # * rights
- # * source
- # * summary
- # * title
- # * updated
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.entry
- class Entry < RSS::Element
- include CommonModel
- include DuplicateLinkChecker
-
- [
- ["author", "*", :children],
- ["category", "*", :children, "categories"],
- ["content", "?", :child],
- ["contributor", "*", :children],
- ["id", nil, nil, :content],
- ["link", "*", :children],
- ["published", "?", :child, :content],
- ["rights", "?", :child],
- ["source", "?"],
- ["summary", "?", :child],
- ["title", nil],
- ["updated", nil, :child, :content],
- ].each do |tag, occurs, type, *args|
- type ||= :attribute
- __send__("install_have_#{type}_element",
- tag, URI, occurs, tag, *args)
- end
-
- # Returns whether any of the following are true:
- #
- # * There are any authors in the feed
- # * If the parent element has an author and the +check_parent+
- # parameter was given.
- # * There is a source element that has an author
- def have_author?(check_parent=true)
- authors.any? {|author| !author.to_s.empty?} or
- (check_parent and @parent and @parent.have_author?) or
- (source and source.have_author?)
- end
-
- private
- def atom_validate(ignore_unknown_element, tags, uri)
- unless have_author?
- raise MissingTagError.new("author", tag_name)
- end
- validate_duplicate_links(links)
- end
-
- def have_required_elements?
- super and have_author?
- end
-
- def maker_target(items)
- if items.respond_to?("items")
- # For backward compatibility
- items = items.items
- end
- items.new_item
- end
-
- # Feed::Author
- Author = Feed::Author
- # Feed::Category
- Category = Feed::Category
-
- # Contains or links to the content of the Entry.
- # It has the following attributes:
- #
- # * type
- # * src
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.content
- class Content < RSS::Element
- include CommonModel
-
- class << self
- def xml_setter
- "xml="
- end
-
- def xml_getter
- "xml"
- end
- end
-
- [
- ["type", ""],
- ["src", "", false, [nil, :uri]],
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- content_setup
- add_need_initialize_variable("xml")
-
- # Returns the element content in XML.
- attr_writer :xml
-
- # Returns true if the element has inline XML content.
- def have_xml_content?
- inline_xhtml? or inline_other_xml?
- end
-
- # Returns or builds the element content in XML.
- def xml
- return @xml unless inline_xhtml?
- return @xml if @xml.nil?
- if @xml.is_a?(XML::Element) and
- [@xml.name, @xml.uri] == ["div", XHTML_URI]
- return @xml
- end
-
- children = @xml
- children = [children] unless children.is_a?(Array)
- XML::Element.new("div", nil, XHTML_URI,
- {"xmlns" => XHTML_URI}, children)
- end
-
- # Returns the element content in XHTML.
- def xhtml
- if inline_xhtml?
- xml
- else
- nil
- end
- end
-
- # Raises a MissingAttributeError, NotAvailableValueError,
- # MissingTagError or NotExpectedTagError if the element is
- # not properly formatted.
- def atom_validate(ignore_unknown_element, tags, uri)
- if out_of_line?
- raise MissingAttributeError.new(tag_name, "type") if @type.nil?
- unless (content.nil? or content.empty?)
- raise NotAvailableValueError.new(tag_name, content)
- end
- elsif inline_xhtml?
- if @xml.nil?
- raise MissingTagError.new("div", tag_name)
- end
- unless @xml.name == "div" and @xml.uri == XHTML_URI
- raise NotExpectedTagError.new(@xml.name, @xml.uri, tag_name)
- end
- end
- end
-
- # Returns true if the element contains inline content
- # that has a text or HTML media type, or no media type at all.
- def inline_text?
- !out_of_line? and [nil, "text", "html"].include?(@type)
- end
-
- # Returns true if the element contains inline content that
- # has a HTML media type.
- def inline_html?
- return false if out_of_line?
- @type == "html" or mime_split == ["text", "html"]
- end
-
- # Returns true if the element contains inline content that
- # has a XHTML media type.
- def inline_xhtml?
- !out_of_line? and @type == "xhtml"
- end
-
- # Returns true if the element contains inline content that
- # has a MIME media type.
- def inline_other?
- return false if out_of_line?
- media_type, subtype = mime_split
- return false if media_type.nil? or subtype.nil?
- true
- end
-
- # Returns true if the element contains inline content that
- # has a text media type.
- def inline_other_text?
- return false unless inline_other?
- return false if inline_other_xml?
-
- media_type, = mime_split
- return true if "text" == media_type.downcase
- false
- end
-
- # Returns true if the element contains inline content that
- # has a XML media type.
- def inline_other_xml?
- return false unless inline_other?
-
- media_type, subtype = mime_split
- normalized_mime_type = "#{media_type}/#{subtype}".downcase
- if /(?:\+xml|^xml)$/ =~ subtype or
- %w(text/xml-external-parsed-entity
- application/xml-external-parsed-entity
- application/xml-dtd).find {|x| x == normalized_mime_type}
- return true
- end
- false
- end
-
- # Returns true if the element contains inline content
- # encoded in base64.
- def inline_other_base64?
- inline_other? and !inline_other_text? and !inline_other_xml?
- end
-
- # Returns true if the element contains linked content.
- def out_of_line?
- not @src.nil?
- end
-
- # Splits the type attribute into an array, e.g. ["text", "xml"]
- def mime_split
- media_type = subtype = nil
- if /\A\s*([a-z]+)\/([a-z\+]+)\s*(?:;.*)?\z/i =~ @type.to_s
- media_type = $1.downcase
- subtype = $2.downcase
- end
- [media_type, subtype]
- end
-
- # Returns true if the content needs to be encoded in base64.
- def need_base64_encode?
- inline_other_base64?
- end
-
- private
- def empty_content?
- out_of_line? or super
- end
- end
-
- # Feed::Contributor
- Contributor = Feed::Contributor
- # Feed::Id
- Id = Feed::Id
- # Feed::Link
- Link = Feed::Link
-
- # DateConstruct that usually indicates the time of the initial
- # creation of an Entry.
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.published
- class Published < RSS::Element
- include CommonModel
- include DateConstruct
- end
-
- # Feed::Rights
- Rights = Feed::Rights
-
- # Defines a Atom Source element. It has the following attributes:
- #
- # * author
- # * category
- # * categories
- # * content
- # * contributor
- # * generator
- # * icon
- # * id
- # * link
- # * logo
- # * rights
- # * subtitle
- # * title
- # * updated
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.source
- class Source < RSS::Element
- include CommonModel
-
- [
- ["author", "*", :children],
- ["category", "*", :children, "categories"],
- ["contributor", "*", :children],
- ["generator", "?"],
- ["icon", "?"],
- ["id", "?", nil, :content],
- ["link", "*", :children],
- ["logo", "?"],
- ["rights", "?"],
- ["subtitle", "?"],
- ["title", "?"],
- ["updated", "?", nil, :content],
- ].each do |tag, occurs, type, *args|
- type ||= :attribute
- __send__("install_have_#{type}_element",
- tag, URI, occurs, tag, *args)
- end
-
- # Returns true if the Source element has an author.
- def have_author?
- !author.to_s.empty?
- end
-
- # Feed::Author
- Author = Feed::Author
- # Feed::Category
- Category = Feed::Category
- # Feed::Contributor
- Contributor = Feed::Contributor
- # Feed::Generator
- Generator = Feed::Generator
- # Feed::Icon
- Icon = Feed::Icon
- # Feed::Id
- Id = Feed::Id
- # Feed::Link
- Link = Feed::Link
- # Feed::Logo
- Logo = Feed::Logo
- # Feed::Rights
- Rights = Feed::Rights
- # Feed::Subtitle
- Subtitle = Feed::Subtitle
- # Feed::Title
- Title = Feed::Title
- # Feed::Updated
- Updated = Feed::Updated
- end
-
- # TextConstruct that describes a summary of the Entry.
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.summary
- class Summary < RSS::Element
- include CommonModel
- include TextConstruct
- end
-
- # Feed::Title
- Title = Feed::Title
- # Feed::Updated
- Updated = Feed::Updated
- end
- end
-
- # Defines a top-level Atom Entry element,
- # used as the document element of a stand-alone Atom Entry Document.
- # It has the following attributes:
- #
- # * author
- # * category
- # * categories
- # * content
- # * contributor
- # * id
- # * link
- # * published
- # * rights
- # * source
- # * summary
- # * title
- # * updated
- #
- # Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.entry]
- class Entry < RSS::Element
- include RootElementMixin
- include CommonModel
- include DuplicateLinkChecker
-
- [
- ["author", "*", :children],
- ["category", "*", :children, "categories"],
- ["content", "?"],
- ["contributor", "*", :children],
- ["id", nil, nil, :content],
- ["link", "*", :children],
- ["published", "?", :child, :content],
- ["rights", "?"],
- ["source", "?"],
- ["summary", "?"],
- ["title", nil],
- ["updated", nil, nil, :content],
- ].each do |tag, occurs, type, *args|
- type ||= :attribute
- __send__("install_have_#{type}_element",
- tag, URI, occurs, tag, *args)
- end
-
- # Creates a new Atom Entry element.
- def initialize(version=nil, encoding=nil, standalone=nil)
- super("1.0", version, encoding, standalone)
- @feed_type = "atom"
- @feed_subtype = "entry"
- end
-
- # Returns the Entry in an array.
- def items
- [self]
- end
-
- # Sets up the +maker+ for constructing Entry elements.
- def setup_maker(maker)
- maker = maker.maker if maker.respond_to?("maker")
- super(maker)
- end
-
- # Returns where there are any authors present or there is a
- # source with an author.
- def have_author?
- authors.any? {|author| !author.to_s.empty?} or
- (source and source.have_author?)
- end
-
- private
- def atom_validate(ignore_unknown_element, tags, uri)
- unless have_author?
- raise MissingTagError.new("author", tag_name)
- end
- validate_duplicate_links(links)
- end
-
- def have_required_elements?
- super and have_author?
- end
-
- def maker_target(maker)
- maker.items.new_item
- end
-
- # Feed::Entry::Author
- Author = Feed::Entry::Author
- # Feed::Entry::Category
- Category = Feed::Entry::Category
- # Feed::Entry::Content
- Content = Feed::Entry::Content
- # Feed::Entry::Contributor
- Contributor = Feed::Entry::Contributor
- # Feed::Entry::Id
- Id = Feed::Entry::Id
- # Feed::Entry::Link
- Link = Feed::Entry::Link
- # Feed::Entry::Published
- Published = Feed::Entry::Published
- # Feed::Entry::Rights
- Rights = Feed::Entry::Rights
- # Feed::Entry::Source
- Source = Feed::Entry::Source
- # Feed::Entry::Summary
- Summary = Feed::Entry::Summary
- # Feed::Entry::Title
- Title = Feed::Entry::Title
- # Feed::Entry::Updated
- Updated = Feed::Entry::Updated
- end
- end
-
- Atom::CommonModel::ELEMENTS.each do |name|
- BaseListener.install_get_text_element(Atom::URI, name, "#{name}=")
- end
-
- module ListenerMixin
- private
- def initial_start_feed(tag_name, prefix, attrs, ns)
- check_ns(tag_name, prefix, ns, Atom::URI, false)
-
- @rss = Atom::Feed.new(@version, @encoding, @standalone)
- @rss.do_validate = @do_validate
- @rss.xml_stylesheets = @xml_stylesheets
- @rss.lang = attrs["xml:lang"]
- @rss.base = attrs["xml:base"]
- @last_element = @rss
- pr = Proc.new do |text, tags|
- @rss.validate_for_stream(tags) if @do_validate
- end
- @proc_stack.push(pr)
- end
-
- def initial_start_entry(tag_name, prefix, attrs, ns)
- check_ns(tag_name, prefix, ns, Atom::URI, false)
-
- @rss = Atom::Entry.new(@version, @encoding, @standalone)
- @rss.do_validate = @do_validate
- @rss.xml_stylesheets = @xml_stylesheets
- @rss.lang = attrs["xml:lang"]
- @rss.base = attrs["xml:base"]
- @last_element = @rss
- pr = Proc.new do |text, tags|
- @rss.validate_for_stream(tags) if @do_validate
- end
- @proc_stack.push(pr)
- end
- end
-end
diff --git a/lib/rss/content.rb b/lib/rss/content.rb
deleted file mode 100644
index 78c18d103c3..00000000000
--- a/lib/rss/content.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss"
-
-module RSS
- # The prefix for the Content XML namespace.
- CONTENT_PREFIX = 'content'
- # The URI of the Content specification.
- CONTENT_URI = "http://purl.org/rss/1.0/modules/content/"
-
- module ContentModel
- extend BaseModel
-
- ELEMENTS = ["#{CONTENT_PREFIX}_encoded"]
-
- def self.append_features(klass)
- super
-
- klass.install_must_call_validator(CONTENT_PREFIX, CONTENT_URI)
- ELEMENTS.each do |full_name|
- name = full_name[(CONTENT_PREFIX.size + 1)..-1]
- klass.install_text_element(name, CONTENT_URI, "?", full_name)
- end
- end
- end
-
- prefix_size = CONTENT_PREFIX.size + 1
- ContentModel::ELEMENTS.each do |full_name|
- name = full_name[prefix_size..-1]
- BaseListener.install_get_text_element(CONTENT_URI, name, full_name)
- end
-end
-
-require 'rss/content/1.0'
-require 'rss/content/2.0'
diff --git a/lib/rss/content/1.0.rb b/lib/rss/content/1.0.rb
deleted file mode 100644
index 1367dfe0924..00000000000
--- a/lib/rss/content/1.0.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-# frozen_string_literal: false
-require 'rss/1.0'
-
-module RSS
- RDF.install_ns(CONTENT_PREFIX, CONTENT_URI)
-
- class RDF
- class Item; include ContentModel; end
- end
-end
diff --git a/lib/rss/content/2.0.rb b/lib/rss/content/2.0.rb
deleted file mode 100644
index 3b468248ace..00000000000
--- a/lib/rss/content/2.0.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-# frozen_string_literal: false
-require "rss/2.0"
-
-module RSS
- Rss.install_ns(CONTENT_PREFIX, CONTENT_URI)
-
- class Rss
- class Channel
- class Item; include ContentModel; end
- end
- end
-end
diff --git a/lib/rss/converter.rb b/lib/rss/converter.rb
deleted file mode 100644
index d372e067256..00000000000
--- a/lib/rss/converter.rb
+++ /dev/null
@@ -1,171 +0,0 @@
-# frozen_string_literal: false
-require_relative "utils"
-
-module RSS
-
- class Converter
-
- include Utils
-
- def initialize(to_enc, from_enc=nil)
- if "".respond_to?(:encode)
- @to_encoding = to_enc
- return
- end
- 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)
- if value.is_a?(String) and value.respond_to?(:encode)
- value.encode(@to_encoding)
- else
- value
- end
- 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_uconv_convert_if_can(meth, to_enc, from_enc, nkf_arg)
- 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
- require 'nkf'
- if NKF.const_defined?(:UTF8)
- def_convert(1) do |value|
- "NKF.nkf(#{nkf_arg.dump}, #{value})"
- end
- else
- def_iconv_convert(to_enc, from_enc, 1)
- end
- end
- end
-
- def def_to_euc_jp_from_utf_8
- def_uconv_convert_if_can('u8toeuc', 'EUC-JP', 'UTF-8', '-We')
- end
-
- def def_to_utf_8_from_euc_jp
- def_uconv_convert_if_can('euctou8', 'UTF-8', 'EUC-JP', '-Ew')
- end
-
- def def_to_shift_jis_from_utf_8
- def_uconv_convert_if_can('u8tosjis', 'Shift_JIS', 'UTF-8', '-Ws')
- end
-
- def def_to_utf_8_from_shift_jis
- def_uconv_convert_if_can('sjistou8', 'UTF-8', 'Shift_JIS', '-Sw')
- 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
-
-end
diff --git a/lib/rss/dublincore.rb b/lib/rss/dublincore.rb
deleted file mode 100644
index 85b836d3bf3..00000000000
--- a/lib/rss/dublincore.rb
+++ /dev/null
@@ -1,164 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss"
-
-module RSS
- # The prefix for the Dublin Core XML namespace.
- DC_PREFIX = 'dc'
- # The URI of the Dublin Core specification.
- DC_URI = "http://purl.org/dc/elements/1.1/"
-
- module BaseDublinCoreModel
- def append_features(klass)
- super
-
- return if klass.instance_of?(Module)
- DublinCoreModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
- plural = plural_name || "#{name}s"
- full_name = "#{DC_PREFIX}_#{name}"
- full_plural_name = "#{DC_PREFIX}_#{plural}"
- klass_name = "DublinCore#{Utils.to_class_name(name)}"
- klass.install_must_call_validator(DC_PREFIX, DC_URI)
- klass.install_have_children_element(name, DC_URI, "*",
- full_name, full_plural_name)
- klass.module_eval(<<-EOC, *get_file_and_line_from_caller(0))
- remove_method :#{full_name}
- remove_method :#{full_name}=
- remove_method :set_#{full_name}
-
- def #{full_name}
- @#{full_name}.first and @#{full_name}.first.value
- end
-
- def #{full_name}=(new_value)
- @#{full_name}[0] = Utils.new_with_value_if_need(#{klass_name}, new_value)
- end
- alias set_#{full_name} #{full_name}=
- EOC
- end
- klass.module_eval(<<-EOC, *get_file_and_line_from_caller(0))
- if method_defined?(:date)
- alias date_without_#{DC_PREFIX}_date= date=
-
- def date=(value)
- self.date_without_#{DC_PREFIX}_date = value
- self.#{DC_PREFIX}_date = value
- end
- else
- alias date #{DC_PREFIX}_date
- alias date= #{DC_PREFIX}_date=
- end
-
- # For backward compatibility
- alias #{DC_PREFIX}_rightses #{DC_PREFIX}_rights_list
- EOC
- end
- end
-
- module DublinCoreModel
-
- extend BaseModel
- extend BaseDublinCoreModel
-
- TEXT_ELEMENTS = {
- "title" => nil,
- "description" => nil,
- "creator" => nil,
- "subject" => nil,
- "publisher" => nil,
- "contributor" => nil,
- "type" => nil,
- "format" => nil,
- "identifier" => nil,
- "source" => nil,
- "language" => nil,
- "relation" => nil,
- "coverage" => nil,
- "rights" => "rights_list"
- }
-
- DATE_ELEMENTS = {
- "date" => "w3cdtf",
- }
-
- ELEMENT_NAME_INFOS = DublinCoreModel::TEXT_ELEMENTS.to_a
- DublinCoreModel::DATE_ELEMENTS.each do |name, |
- ELEMENT_NAME_INFOS << [name, nil]
- end
-
- ELEMENTS = TEXT_ELEMENTS.keys + DATE_ELEMENTS.keys
-
- ELEMENTS.each do |name, plural_name|
- module_eval(<<-EOC, *get_file_and_line_from_caller(0))
- class DublinCore#{Utils.to_class_name(name)} < Element
- include RSS10
-
- content_setup
-
- class << self
- def required_prefix
- DC_PREFIX
- end
-
- def required_uri
- DC_URI
- end
- end
-
- @tag_name = #{name.dump}
-
- alias_method(:value, :content)
- alias_method(:value=, :content=)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.content = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(DC_PREFIX)
- end
-
- def maker_target(target)
- target.new_#{name}
- end
-
- def setup_maker_attributes(#{name})
- #{name}.content = content
- end
- end
- EOC
- end
-
- DATE_ELEMENTS.each do |name, type|
- tag_name = "#{DC_PREFIX}:#{name}"
- module_eval(<<-EOC, *get_file_and_line_from_caller(0))
- class DublinCore#{Utils.to_class_name(name)} < Element
- remove_method(:content=)
- remove_method(:value=)
-
- date_writer("content", #{type.dump}, #{tag_name.dump})
-
- alias_method(:value=, :content=)
- end
- EOC
- end
- end
-
- # For backward compatibility
- DublincoreModel = DublinCoreModel
-
- DublinCoreModel::ELEMENTS.each do |name|
- class_name = Utils.to_class_name(name)
- BaseListener.install_class_name(DC_URI, name, "DublinCore#{class_name}")
- end
-
- DublinCoreModel::ELEMENTS.collect! {|name| "#{DC_PREFIX}_#{name}"}
-end
-
-require 'rss/dublincore/1.0'
-require 'rss/dublincore/2.0'
-require_relative 'dublincore/atom'
diff --git a/lib/rss/dublincore/1.0.rb b/lib/rss/dublincore/1.0.rb
deleted file mode 100644
index 1d96fab9b91..00000000000
--- a/lib/rss/dublincore/1.0.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# frozen_string_literal: false
-require "rss/1.0"
-
-module RSS
- RDF.install_ns(DC_PREFIX, DC_URI)
-
- class RDF
- class Channel; include DublinCoreModel; end
- class Image; include DublinCoreModel; end
- class Item; include DublinCoreModel; end
- class Textinput; include DublinCoreModel; end
- end
-end
diff --git a/lib/rss/dublincore/2.0.rb b/lib/rss/dublincore/2.0.rb
deleted file mode 100644
index e3011fef6a3..00000000000
--- a/lib/rss/dublincore/2.0.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# frozen_string_literal: false
-require "rss/2.0"
-
-module RSS
- Rss.install_ns(DC_PREFIX, DC_URI)
-
- class Rss
- class Channel
- include DublinCoreModel
- class Item; include DublinCoreModel; end
- end
- end
-end
diff --git a/lib/rss/dublincore/atom.rb b/lib/rss/dublincore/atom.rb
deleted file mode 100644
index 1cfcdec677c..00000000000
--- a/lib/rss/dublincore/atom.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: false
-require_relative "../atom"
-
-module RSS
- module Atom
- Feed.install_ns(DC_PREFIX, DC_URI)
-
- class Feed
- include DublinCoreModel
- class Entry; include DublinCoreModel; end
- end
-
- class Entry
- include DublinCoreModel
- end
- end
-end
diff --git a/lib/rss/image.rb b/lib/rss/image.rb
deleted file mode 100644
index 837f7d18f4d..00000000000
--- a/lib/rss/image.rb
+++ /dev/null
@@ -1,198 +0,0 @@
-# frozen_string_literal: false
-require 'rss/1.0'
-require_relative 'dublincore'
-
-module RSS
-
- # The prefix for the Image XML namespace.
- IMAGE_PREFIX = 'image'
- # The URI for the Image specification.
- IMAGE_URI = 'http://purl.org/rss/1.0/modules/image/'
-
- RDF.install_ns(IMAGE_PREFIX, IMAGE_URI)
-
- # This constant holds strings which contain the names of
- # image elements, with the appropriate prefix.
- IMAGE_ELEMENTS = []
-
- %w(item favicon).each do |name|
- class_name = Utils.to_class_name(name)
- BaseListener.install_class_name(IMAGE_URI, name, "Image#{class_name}")
- IMAGE_ELEMENTS << "#{IMAGE_PREFIX}_#{name}"
- end
-
- module ImageModelUtils
- def validate_one_tag_name(ignore_unknown_element, name, tags)
- if !ignore_unknown_element
- invalid = tags.find {|tag| tag != name}
- raise UnknownTagError.new(invalid, IMAGE_URI) if invalid
- end
- raise TooMuchTagError.new(name, tag_name) if tags.size > 1
- end
- end
-
- module ImageItemModel
- include ImageModelUtils
- extend BaseModel
-
- def self.append_features(klass)
- super
-
- klass.install_have_child_element("item", IMAGE_URI, "?",
- "#{IMAGE_PREFIX}_item")
- klass.install_must_call_validator(IMAGE_PREFIX, IMAGE_URI)
- end
-
- class ImageItem < Element
- include RSS10
- include DublinCoreModel
-
- @tag_name = "item"
-
- class << self
- def required_prefix
- IMAGE_PREFIX
- end
-
- def required_uri
- IMAGE_URI
- end
- end
-
- install_must_call_validator(IMAGE_PREFIX, IMAGE_URI)
-
- [
- ["about", ::RSS::RDF::URI, true],
- ["resource", ::RSS::RDF::URI, false],
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required, nil, nil,
- "#{::RSS::RDF::PREFIX}:#{name}")
- end
-
- %w(width height).each do |tag|
- full_name = "#{IMAGE_PREFIX}_#{tag}"
- disp_name = "#{IMAGE_PREFIX}:#{tag}"
- install_text_element(tag, IMAGE_URI, "?",
- full_name, :integer, disp_name)
- BaseListener.install_get_text_element(IMAGE_URI, tag, full_name)
- end
-
- alias width= image_width=
- alias width image_width
- alias height= image_height=
- alias height image_height
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.about = args[0]
- self.resource = args[1]
- end
- end
-
- def full_name
- tag_name_with_prefix(IMAGE_PREFIX)
- end
-
- private
- def maker_target(target)
- target.image_item
- end
-
- def setup_maker_attributes(item)
- item.about = self.about
- item.resource = self.resource
- end
- end
- end
-
- module ImageFaviconModel
- include ImageModelUtils
- extend BaseModel
-
- def self.append_features(klass)
- super
-
- unless klass.class == Module
- klass.install_have_child_element("favicon", IMAGE_URI, "?",
- "#{IMAGE_PREFIX}_favicon")
- klass.install_must_call_validator(IMAGE_PREFIX, IMAGE_URI)
- end
- end
-
- class ImageFavicon < Element
- include RSS10
- include DublinCoreModel
-
- @tag_name = "favicon"
-
- class << self
- def required_prefix
- IMAGE_PREFIX
- end
-
- def required_uri
- IMAGE_URI
- end
- end
-
- [
- ["about", ::RSS::RDF::URI, true, ::RSS::RDF::PREFIX],
- ["size", IMAGE_URI, true, IMAGE_PREFIX],
- ].each do |name, uri, required, prefix|
- install_get_attribute(name, uri, required, nil, nil,
- "#{prefix}:#{name}")
- end
-
- AVAILABLE_SIZES = %w(small medium large)
- alias_method :set_size, :size=
- private :set_size
- def size=(new_value)
- if @do_validate and !new_value.nil?
- new_value = new_value.strip
- unless AVAILABLE_SIZES.include?(new_value)
- attr_name = "#{IMAGE_PREFIX}:size"
- raise NotAvailableValueError.new(full_name, new_value, attr_name)
- end
- end
- set_size(new_value)
- end
-
- alias image_size= size=
- alias image_size size
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.about = args[0]
- self.size = args[1]
- end
- end
-
- def full_name
- tag_name_with_prefix(IMAGE_PREFIX)
- end
-
- private
- def maker_target(target)
- target.image_favicon
- end
-
- def setup_maker_attributes(favicon)
- favicon.about = self.about
- favicon.size = self.size
- end
- end
-
- end
-
- class RDF
- class Channel; include ImageFaviconModel; end
- class Item; include ImageItemModel; end
- end
-
-end
diff --git a/lib/rss/itunes.rb b/lib/rss/itunes.rb
deleted file mode 100644
index bc3e25448a7..00000000000
--- a/lib/rss/itunes.rb
+++ /dev/null
@@ -1,425 +0,0 @@
-# frozen_string_literal: false
-require 'rss/2.0'
-
-module RSS
- # The prefix for the iTunes XML namespace.
- ITUNES_PREFIX = 'itunes'
- # The URI of the iTunes specification.
- ITUNES_URI = 'http://www.itunes.com/dtds/podcast-1.0.dtd'
-
- Rss.install_ns(ITUNES_PREFIX, ITUNES_URI)
-
- module ITunesModelUtils
- include Utils
-
- def def_class_accessor(klass, name, type, *args)
- normalized_name = name.gsub(/-/, "_")
- full_name = "#{ITUNES_PREFIX}_#{normalized_name}"
- klass_name = "ITunes#{Utils.to_class_name(normalized_name)}"
-
- case type
- when :element, :attribute
- klass::ELEMENTS << full_name
- def_element_class_accessor(klass, name, full_name, klass_name, *args)
- when :elements
- klass::ELEMENTS << full_name
- def_elements_class_accessor(klass, name, full_name, klass_name, *args)
- else
- klass.install_must_call_validator(ITUNES_PREFIX, ITUNES_URI)
- klass.install_text_element(normalized_name, ITUNES_URI, "?",
- full_name, type, name)
- end
- end
-
- def def_element_class_accessor(klass, name, full_name, klass_name,
- recommended_attribute_name=nil)
- klass.install_have_child_element(name, ITUNES_PREFIX, "?", full_name)
- end
-
- def def_elements_class_accessor(klass, name, full_name, klass_name,
- plural_name, recommended_attribute_name=nil)
- full_plural_name = "#{ITUNES_PREFIX}_#{plural_name}"
- klass.install_have_children_element(name, ITUNES_PREFIX, "*",
- full_name, full_plural_name)
- end
- end
-
- module ITunesBaseModel
- extend ITunesModelUtils
-
- ELEMENTS = []
-
- ELEMENT_INFOS = [["author"],
- ["block", :yes_other],
- ["explicit", :explicit_clean_other],
- ["keywords", :csv],
- ["subtitle"],
- ["summary"]]
- end
-
- module ITunesChannelModel
- extend BaseModel
- extend ITunesModelUtils
- include ITunesBaseModel
-
- ELEMENTS = []
-
- class << self
- def append_features(klass)
- super
-
- return if klass.instance_of?(Module)
- ELEMENT_INFOS.each do |name, type, *additional_infos|
- def_class_accessor(klass, name, type, *additional_infos)
- end
- end
- end
-
- ELEMENT_INFOS = [
- ["category", :elements, "categories", "text"],
- ["image", :attribute, "href"],
- ["owner", :element],
- ["new-feed-url"],
- ] + ITunesBaseModel::ELEMENT_INFOS
-
- class ITunesCategory < Element
- include RSS09
-
- @tag_name = "category"
-
- class << self
- def required_prefix
- ITUNES_PREFIX
- end
-
- def required_uri
- ITUNES_URI
- end
- end
-
- [
- ["text", "", true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- ITunesCategory = self
- install_have_children_element("category", ITUNES_URI, "*",
- "#{ITUNES_PREFIX}_category",
- "#{ITUNES_PREFIX}_categories")
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.text = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(ITUNES_PREFIX)
- end
-
- private
- def maker_target(categories)
- if text or !itunes_categories.empty?
- categories.new_category
- else
- nil
- end
- end
-
- def setup_maker_attributes(category)
- category.text = text if text
- end
-
- def setup_maker_elements(category)
- super(category)
- itunes_categories.each do |sub_category|
- sub_category.setup_maker(category)
- end
- end
- end
-
- class ITunesImage < Element
- include RSS09
-
- @tag_name = "image"
-
- class << self
- def required_prefix
- ITUNES_PREFIX
- end
-
- def required_uri
- ITUNES_URI
- end
- end
-
- [
- ["href", "", true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.href = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(ITUNES_PREFIX)
- end
-
- private
- def maker_target(target)
- if href
- target.itunes_image {|image| image}
- else
- nil
- end
- end
-
- def setup_maker_attributes(image)
- image.href = href
- end
- end
-
- class ITunesOwner < Element
- include RSS09
-
- @tag_name = "owner"
-
- class << self
- def required_prefix
- ITUNES_PREFIX
- end
-
- def required_uri
- ITUNES_URI
- end
- end
-
- install_must_call_validator(ITUNES_PREFIX, ITUNES_URI)
- [
- ["name"],
- ["email"],
- ].each do |name,|
- ITunesBaseModel::ELEMENT_INFOS << name
- install_text_element(name, ITUNES_URI, nil, "#{ITUNES_PREFIX}_#{name}")
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.itunes_name = args[0]
- self.itunes_email = args[1]
- end
- end
-
- def full_name
- tag_name_with_prefix(ITUNES_PREFIX)
- end
-
- private
- def maker_target(target)
- target.itunes_owner
- end
-
- def setup_maker_element(owner)
- super(owner)
- owner.itunes_name = itunes_name
- owner.itunes_email = itunes_email
- end
- end
- end
-
- module ITunesItemModel
- extend BaseModel
- extend ITunesModelUtils
- include ITunesBaseModel
-
- class << self
- def append_features(klass)
- super
-
- return if klass.instance_of?(Module)
- ELEMENT_INFOS.each do |name, type|
- def_class_accessor(klass, name, type)
- end
- end
- end
-
- ELEMENT_INFOS = ITunesBaseModel::ELEMENT_INFOS +
- [["duration", :element, "content"]]
-
- class ITunesDuration < Element
- include RSS09
-
- @tag_name = "duration"
-
- class << self
- def required_prefix
- ITUNES_PREFIX
- end
-
- def required_uri
- ITUNES_URI
- end
-
- def parse(duration, do_validate=true)
- if do_validate and /\A(?:
- \d?\d:[0-5]\d:[0-5]\d|
- [0-5]?\d:[0-5]\d|
- \d+
- )\z/x !~ duration
- raise ArgumentError,
- "must be one of HH:MM:SS, H:MM:SS, MM:SS, M:SS, S+: " +
- duration.inspect
- end
-
- if duration.include?(':')
- components = duration.split(':')
- components[3..-1] = nil if components.size > 3
-
- components.unshift("00") until components.size == 3
- components.collect do |component|
- component.to_i
- end
- else
- seconds_to_components(duration.to_i)
- end
- end
-
- def construct(hours, minutes, seconds)
- components = [minutes, seconds]
- if components.include?(nil)
- nil
- else
- components.unshift(hours) if hours and hours > 0
- components.collect do |component|
- "%02d" % component
- end.join(':')
- end
- end
-
- private
- def seconds_to_components(total_seconds)
- hours = total_seconds / (60 * 60)
- minutes = (total_seconds / 60) % 60
- seconds = total_seconds % 60
- [hours, minutes, seconds]
- end
- end
-
- content_setup
- alias_method(:value, :content)
- remove_method(:content=)
-
- attr_reader :hour, :minute, :second
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- args = args[0] if args.size == 1 and args[0].is_a?(Array)
- if args.size == 1
- self.content = args[0]
- elsif args.size > 3
- raise ArgumentError,
- "must be (do_validate, params), (content), " +
- "(minute, second), ([minute, second]), " +
- "(hour, minute, second) or ([hour, minute, second]): " +
- args.inspect
- else
- @second, @minute, @hour = args.reverse
- update_content
- end
- end
- end
-
- def content=(value)
- if value.nil?
- @content = nil
- elsif value.is_a?(self.class)
- self.content = value.content
- else
- begin
- @hour, @minute, @second = self.class.parse(value, @do_validate)
- rescue ArgumentError
- raise NotAvailableValueError.new(tag_name, value)
- end
- @content = value
- end
- end
- alias_method(:value=, :content=)
-
- def hour=(hour)
- @hour = @do_validate ? Integer(hour) : hour.to_i
- update_content
- hour
- end
-
- def minute=(minute)
- @minute = @do_validate ? Integer(minute) : minute.to_i
- update_content
- minute
- end
-
- def second=(second)
- @second = @do_validate ? Integer(second) : second.to_i
- update_content
- second
- end
-
- def full_name
- tag_name_with_prefix(ITUNES_PREFIX)
- end
-
- private
- def update_content
- @content = self.class.construct(hour, minute, second)
- end
-
- def maker_target(target)
- if @content
- target.itunes_duration {|duration| duration}
- else
- nil
- end
- end
-
- def setup_maker_element(duration)
- super(duration)
- duration.content = @content
- end
- end
- end
-
- class Rss
- class Channel
- include ITunesChannelModel
- class Item; include ITunesItemModel; end
- end
- end
-
- element_infos =
- ITunesChannelModel::ELEMENT_INFOS + ITunesItemModel::ELEMENT_INFOS
- element_infos.each do |name, type|
- case type
- when :element, :elements, :attribute
- class_name = Utils.to_class_name(name)
- BaseListener.install_class_name(ITUNES_URI, name, "ITunes#{class_name}")
- else
- accessor_base = "#{ITUNES_PREFIX}_#{name.gsub(/-/, '_')}"
- BaseListener.install_get_text_element(ITUNES_URI, name, accessor_base)
- end
- end
-end
diff --git a/lib/rss/maker.rb b/lib/rss/maker.rb
deleted file mode 100644
index e32de818066..00000000000
--- a/lib/rss/maker.rb
+++ /dev/null
@@ -1,79 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss"
-
-module RSS
- ##
- #
- # Provides a set of builders for various RSS objects
- #
- # * Feeds
- # * RSS 0.91
- # * RSS 1.0
- # * RSS 2.0
- # * Atom 1.0
- #
- # * Elements
- # * Atom::Entry
-
- module Maker
-
- # Collection of supported makers
- MAKERS = {}
-
- class << self
- # Builder for an RSS object
- # Creates an object of the type passed in +args+
- #
- # Executes the +block+ to populate elements of the created RSS object
- def make(version, &block)
- self[version].make(&block)
- end
-
- # Returns the maker for the +version+
- def [](version)
- maker_info = maker(version)
- raise UnsupportedMakerVersionError.new(version) if maker_info.nil?
- maker_info[:maker]
- end
-
- # Adds a maker to the set of supported makers
- def add_maker(version, normalized_version, maker)
- MAKERS[version] = {:maker => maker, :version => normalized_version}
- end
-
- # Returns collection of supported maker versions
- def versions
- MAKERS.keys.uniq.sort
- end
-
- # Returns collection of supported makers
- def makers
- MAKERS.values.collect { |info| info[:maker] }.uniq
- end
-
- # Returns true if the version is supported
- def supported?(version)
- versions.include?(version)
- end
-
- private
- # Can I remove this method?
- def maker(version)
- MAKERS[version]
- end
- end
- end
-end
-
-require_relative "maker/1.0"
-require_relative "maker/2.0"
-require_relative "maker/feed"
-require_relative "maker/entry"
-require_relative "maker/content"
-require_relative "maker/dublincore"
-require_relative "maker/slash"
-require_relative "maker/syndication"
-require_relative "maker/taxonomy"
-require_relative "maker/trackback"
-require_relative "maker/image"
-require_relative "maker/itunes"
diff --git a/lib/rss/maker/0.9.rb b/lib/rss/maker/0.9.rb
deleted file mode 100644
index eb35fc14e1a..00000000000
--- a/lib/rss/maker/0.9.rb
+++ /dev/null
@@ -1,509 +0,0 @@
-# frozen_string_literal: false
-require_relative "../0.9"
-
-require_relative "base"
-
-module RSS
- module Maker
-
- class RSS09 < RSSBase
-
- def initialize(feed_version)
- super
- @feed_type = "rss"
- end
-
- private
- def make_feed
- Rss.new(@feed_version, @version, @encoding, @standalone)
- end
-
- def setup_elements(rss)
- setup_channel(rss)
- end
-
- class Channel < ChannelBase
- def to_feed(rss)
- channel = Rss::Channel.new
- setup_values(channel)
- _not_set_required_variables = not_set_required_variables
- if _not_set_required_variables.empty?
- rss.channel = channel
- set_parent(channel, rss)
- setup_items(rss)
- setup_image(rss)
- setup_textinput(rss)
- setup_other_elements(rss, channel)
- rss
- else
- raise NotSetError.new("maker.channel", _not_set_required_variables)
- end
- end
-
- private
- def setup_items(rss)
- @maker.items.to_feed(rss)
- end
-
- def setup_image(rss)
- @maker.image.to_feed(rss)
- end
-
- def setup_textinput(rss)
- @maker.textinput.to_feed(rss)
- end
-
- def variables
- super + ["pubDate"]
- end
-
- def required_variable_names
- %w(link language)
- end
-
- def not_set_required_variables
- vars = super
- vars << "description" unless description {|d| d.have_required_values?}
- vars << "title" unless title {|t| t.have_required_values?}
- vars
- end
-
- class SkipDays < SkipDaysBase
- def to_feed(rss, channel)
- unless @days.empty?
- skipDays = Rss::Channel::SkipDays.new
- channel.skipDays = skipDays
- set_parent(skipDays, channel)
- @days.each do |day|
- day.to_feed(rss, skipDays.days)
- end
- end
- end
-
- class Day < DayBase
- def to_feed(rss, days)
- day = Rss::Channel::SkipDays::Day.new
- set = setup_values(day)
- if set
- days << day
- set_parent(day, days)
- setup_other_elements(rss, day)
- end
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
-
- class SkipHours < SkipHoursBase
- def to_feed(rss, channel)
- unless @hours.empty?
- skipHours = Rss::Channel::SkipHours.new
- channel.skipHours = skipHours
- set_parent(skipHours, channel)
- @hours.each do |hour|
- hour.to_feed(rss, skipHours.hours)
- end
- end
- end
-
- class Hour < HourBase
- def to_feed(rss, hours)
- hour = Rss::Channel::SkipHours::Hour.new
- set = setup_values(hour)
- if set
- hours << hour
- set_parent(hour, hours)
- setup_other_elements(rss, hour)
- end
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
-
- class Cloud < CloudBase
- def to_feed(*args)
- end
- end
-
- class Categories < CategoriesBase
- def to_feed(*args)
- end
-
- class Category < CategoryBase
- end
- end
-
- class Links < LinksBase
- def to_feed(rss, channel)
- return if @links.empty?
- @links.first.to_feed(rss, channel)
- end
-
- class Link < LinkBase
- def to_feed(rss, channel)
- if have_required_values?
- channel.link = href
- else
- raise NotSetError.new("maker.channel.link",
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(href)
- end
- end
- end
-
- class Authors < AuthorsBase
- def to_feed(rss, channel)
- end
-
- class Author < AuthorBase
- def to_feed(rss, channel)
- end
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(rss, channel)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Generator < GeneratorBase
- def to_feed(rss, channel)
- end
- end
-
- class Copyright < CopyrightBase
- def to_feed(rss, channel)
- channel.copyright = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- class Description < DescriptionBase
- def to_feed(rss, channel)
- channel.description = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- class Title < TitleBase
- def to_feed(rss, channel)
- channel.title = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
-
- class Image < ImageBase
- def to_feed(rss)
- image = Rss::Channel::Image.new
- set = setup_values(image)
- if set
- image.link = link
- rss.channel.image = image
- set_parent(image, rss.channel)
- setup_other_elements(rss, image)
- elsif required_element?
- raise NotSetError.new("maker.image", not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(url title link)
- end
-
- def required_element?
- true
- end
- end
-
- class Items < ItemsBase
- def to_feed(rss)
- if rss.channel
- normalize.each do |item|
- item.to_feed(rss)
- end
- setup_other_elements(rss, rss.items)
- end
- end
-
- class Item < ItemBase
- def to_feed(rss)
- item = Rss::Channel::Item.new
- setup_values(item)
- _not_set_required_variables = not_set_required_variables
- if _not_set_required_variables.empty?
- rss.items << item
- set_parent(item, rss.channel)
- setup_other_elements(rss, item)
- elsif variable_is_set?
- raise NotSetError.new("maker.items", _not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- []
- end
-
- def not_set_required_variables
- vars = super
- if @maker.feed_version == "0.91"
- vars << "title" unless title {|t| t.have_required_values?}
- vars << "link" unless link
- end
- vars
- end
-
- class Guid < GuidBase
- def to_feed(*args)
- end
- end
-
- class Enclosure < EnclosureBase
- def to_feed(*args)
- end
- end
-
- class Source < SourceBase
- def to_feed(*args)
- end
-
- class Authors < AuthorsBase
- def to_feed(*args)
- end
-
- class Author < AuthorBase
- end
- end
-
- class Categories < CategoriesBase
- def to_feed(*args)
- end
-
- class Category < CategoryBase
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(*args)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Generator < GeneratorBase
- def to_feed(*args)
- end
- end
-
- class Icon < IconBase
- def to_feed(*args)
- end
- end
-
- class Links < LinksBase
- def to_feed(*args)
- end
-
- class Link < LinkBase
- end
- end
-
- class Logo < LogoBase
- def to_feed(*args)
- end
- end
-
- class Rights < RightsBase
- def to_feed(*args)
- end
- end
-
- class Subtitle < SubtitleBase
- def to_feed(*args)
- end
- end
-
- class Title < TitleBase
- def to_feed(*args)
- end
- end
- end
-
- class Categories < CategoriesBase
- def to_feed(*args)
- end
-
- class Category < CategoryBase
- end
- end
-
- class Authors < AuthorsBase
- def to_feed(*args)
- end
-
- class Author < AuthorBase
- end
- end
-
- class Links < LinksBase
- def to_feed(rss, item)
- return if @links.empty?
- @links.first.to_feed(rss, item)
- end
-
- class Link < LinkBase
- def to_feed(rss, item)
- if have_required_values?
- item.link = href
- else
- raise NotSetError.new("maker.link",
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(href)
- end
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(rss, item)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Rights < RightsBase
- def to_feed(rss, item)
- end
- end
-
- class Description < DescriptionBase
- def to_feed(rss, item)
- item.description = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- class Content < ContentBase
- def to_feed(rss, item)
- end
- end
-
- class Title < TitleBase
- def to_feed(rss, item)
- item.title = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
- end
-
- class Textinput < TextinputBase
- def to_feed(rss)
- textInput = Rss::Channel::TextInput.new
- set = setup_values(textInput)
- if set
- rss.channel.textInput = textInput
- set_parent(textInput, rss.channel)
- setup_other_elements(rss, textInput)
- end
- end
-
- private
- def required_variable_names
- %w(title description name link)
- end
- end
- end
-
- class RSS091 < RSS09
- def initialize(feed_version="0.91")
- super
- end
-
- class Channel < RSS09::Channel
- end
-
- class Items < RSS09::Items
- class Item < RSS09::Items::Item
- end
- end
-
- class Image < RSS09::Image
- end
-
- class Textinput < RSS09::Textinput
- end
- end
-
- class RSS092 < RSS09
- def initialize(feed_version="0.92")
- super
- end
-
- class Channel < RSS09::Channel
- end
-
- class Items < RSS09::Items
- class Item < RSS09::Items::Item
- end
- end
-
- class Image < RSS09::Image
- end
-
- class Textinput < RSS09::Textinput
- end
- end
-
- add_maker("0.9", "0.92", RSS092)
- add_maker("0.91", "0.91", RSS091)
- add_maker("0.92", "0.92", RSS092)
- add_maker("rss0.9", "0.92", RSS092)
- add_maker("rss0.91", "0.91", RSS091)
- add_maker("rss0.92", "0.92", RSS092)
- end
-end
diff --git a/lib/rss/maker/1.0.rb b/lib/rss/maker/1.0.rb
deleted file mode 100644
index 3934f9536c9..00000000000
--- a/lib/rss/maker/1.0.rb
+++ /dev/null
@@ -1,436 +0,0 @@
-# frozen_string_literal: false
-require_relative "../1.0"
-
-require_relative "base"
-
-module RSS
- module Maker
-
- class RSS10 < RSSBase
-
- def initialize(feed_version="1.0")
- super
- @feed_type = "rss"
- end
-
- private
- def make_feed
- RDF.new(@version, @encoding, @standalone)
- end
-
- def setup_elements(rss)
- setup_channel(rss)
- setup_image(rss)
- setup_items(rss)
- setup_textinput(rss)
- end
-
- class Channel < ChannelBase
- include SetupDefaultLanguage
-
- def to_feed(rss)
- set_default_values do
- _not_set_required_variables = not_set_required_variables
- if _not_set_required_variables.empty?
- channel = RDF::Channel.new(@about)
- setup_values(channel)
- channel.dc_dates.clear
- rss.channel = channel
- set_parent(channel, rss)
- setup_items(rss)
- setup_image(rss)
- setup_textinput(rss)
- setup_other_elements(rss, channel)
- else
- raise NotSetError.new("maker.channel", _not_set_required_variables)
- end
- end
- end
-
- private
- def setup_items(rss)
- items = RDF::Channel::Items.new
- seq = items.Seq
- set_parent(items, seq)
- target_items = @maker.items.normalize
- raise NotSetError.new("maker", ["items"]) if target_items.empty?
- target_items.each do |item|
- li = RDF::Channel::Items::Seq::Li.new(item.link)
- seq.lis << li
- set_parent(li, seq)
- end
- rss.channel.items = items
- set_parent(rss.channel, items)
- end
-
- def setup_image(rss)
- if @maker.image.have_required_values?
- image = RDF::Channel::Image.new(@maker.image.url)
- rss.channel.image = image
- set_parent(image, rss.channel)
- end
- end
-
- def setup_textinput(rss)
- if @maker.textinput.have_required_values?
- textinput = RDF::Channel::Textinput.new(@maker.textinput.link)
- rss.channel.textinput = textinput
- set_parent(textinput, rss.channel)
- end
- end
-
- def required_variable_names
- %w(about link)
- end
-
- def not_set_required_variables
- vars = super
- vars << "description" unless description {|d| d.have_required_values?}
- vars << "title" unless title {|t| t.have_required_values?}
- vars
- end
-
- class SkipDays < SkipDaysBase
- def to_feed(*args)
- end
-
- class Day < DayBase
- end
- end
-
- class SkipHours < SkipHoursBase
- def to_feed(*args)
- end
-
- class Hour < HourBase
- end
- end
-
- class Cloud < CloudBase
- def to_feed(*args)
- end
- end
-
- class Categories < CategoriesBase
- def to_feed(*args)
- end
-
- class Category < CategoryBase
- end
- end
-
- class Links < LinksBase
- def to_feed(rss, channel)
- return if @links.empty?
- @links.first.to_feed(rss, channel)
- end
-
- class Link < LinkBase
- def to_feed(rss, channel)
- if have_required_values?
- channel.link = href
- else
- raise NotSetError.new("maker.channel.link",
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(href)
- end
- end
- end
-
- class Authors < AuthorsBase
- def to_feed(rss, channel)
- end
-
- class Author < AuthorBase
- def to_feed(rss, channel)
- end
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(rss, channel)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Generator < GeneratorBase
- def to_feed(rss, channel)
- end
- end
-
- class Copyright < CopyrightBase
- def to_feed(rss, channel)
- end
- end
-
- class Description < DescriptionBase
- def to_feed(rss, channel)
- channel.description = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- class Title < TitleBase
- def to_feed(rss, channel)
- channel.title = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
-
- class Image < ImageBase
- def to_feed(rss)
- if @url
- image = RDF::Image.new(@url)
- set = setup_values(image)
- if set
- rss.image = image
- set_parent(image, rss)
- setup_other_elements(rss, image)
- end
- end
- end
-
- def have_required_values?
- super and @maker.channel.have_required_values?
- end
-
- private
- def variables
- super + ["link"]
- end
-
- def required_variable_names
- %w(url title link)
- end
- end
-
- class Items < ItemsBase
- def to_feed(rss)
- if rss.channel
- normalize.each do |item|
- item.to_feed(rss)
- end
- setup_other_elements(rss, rss.items)
- end
- end
-
- class Item < ItemBase
- def to_feed(rss)
- set_default_values do
- item = RDF::Item.new(link)
- set = setup_values(item)
- if set
- item.dc_dates.clear
- rss.items << item
- set_parent(item, rss)
- setup_other_elements(rss, item)
- elsif !have_required_values?
- raise NotSetError.new("maker.item", not_set_required_variables)
- end
- end
- end
-
- private
- def required_variable_names
- %w(link)
- end
-
- def variables
- super + %w(link)
- end
-
- def not_set_required_variables
- set_default_values do
- vars = super
- vars << "title" unless title {|t| t.have_required_values?}
- vars
- end
- end
-
- class Guid < GuidBase
- def to_feed(*args)
- end
- end
-
- class Enclosure < EnclosureBase
- def to_feed(*args)
- end
- end
-
- class Source < SourceBase
- def to_feed(*args)
- end
-
- class Authors < AuthorsBase
- def to_feed(*args)
- end
-
- class Author < AuthorBase
- end
- end
-
- class Categories < CategoriesBase
- def to_feed(*args)
- end
-
- class Category < CategoryBase
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(*args)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Generator < GeneratorBase
- def to_feed(*args)
- end
- end
-
- class Icon < IconBase
- def to_feed(*args)
- end
- end
-
- class Links < LinksBase
- def to_feed(*args)
- end
-
- class Link < LinkBase
- end
- end
-
- class Logo < LogoBase
- def to_feed(*args)
- end
- end
-
- class Rights < RightsBase
- def to_feed(*args)
- end
- end
-
- class Subtitle < SubtitleBase
- def to_feed(*args)
- end
- end
-
- class Title < TitleBase
- def to_feed(*args)
- end
- end
- end
-
- class Categories < CategoriesBase
- def to_feed(*args)
- end
-
- class Category < CategoryBase
- end
- end
-
- class Authors < AuthorsBase
- def to_feed(*args)
- end
-
- class Author < AuthorBase
- end
- end
-
- class Links < LinksBase
- def to_feed(*args)
- end
-
- class Link < LinkBase
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(rss, item)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Rights < RightsBase
- def to_feed(rss, item)
- end
- end
-
- class Description < DescriptionBase
- def to_feed(rss, item)
- item.description = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- class Content < ContentBase
- def to_feed(rss, item)
- end
- end
-
- class Title < TitleBase
- def to_feed(rss, item)
- item.title = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
- end
-
- class Textinput < TextinputBase
- def to_feed(rss)
- if @link
- textinput = RDF::Textinput.new(@link)
- set = setup_values(textinput)
- if set
- rss.textinput = textinput
- set_parent(textinput, rss)
- setup_other_elements(rss, textinput)
- end
- end
- end
-
- def have_required_values?
- super and @maker.channel.have_required_values?
- end
-
- private
- def required_variable_names
- %w(title description name link)
- end
- end
- end
-
- add_maker("1.0", "1.0", RSS10)
- add_maker("rss1.0", "1.0", RSS10)
- end
-end
diff --git a/lib/rss/maker/2.0.rb b/lib/rss/maker/2.0.rb
deleted file mode 100644
index 43d00226b7f..00000000000
--- a/lib/rss/maker/2.0.rb
+++ /dev/null
@@ -1,224 +0,0 @@
-# frozen_string_literal: false
-require_relative "../2.0"
-
-require_relative "0.9"
-
-module RSS
- module Maker
-
- class RSS20 < RSS09
-
- def initialize(feed_version="2.0")
- super
- end
-
- class Channel < RSS09::Channel
-
- private
- def required_variable_names
- %w(link)
- end
-
- class SkipDays < RSS09::Channel::SkipDays
- class Day < RSS09::Channel::SkipDays::Day
- end
- end
-
- class SkipHours < RSS09::Channel::SkipHours
- class Hour < RSS09::Channel::SkipHours::Hour
- end
- end
-
- class Cloud < RSS09::Channel::Cloud
- def to_feed(rss, channel)
- cloud = Rss::Channel::Cloud.new
- set = setup_values(cloud)
- if set
- channel.cloud = cloud
- set_parent(cloud, channel)
- setup_other_elements(rss, cloud)
- end
- end
-
- private
- def required_variable_names
- %w(domain port path registerProcedure protocol)
- end
- end
-
- class Categories < RSS09::Channel::Categories
- def to_feed(rss, channel)
- @categories.each do |category|
- category.to_feed(rss, channel)
- end
- end
-
- class Category < RSS09::Channel::Categories::Category
- def to_feed(rss, channel)
- category = Rss::Channel::Category.new
- set = setup_values(category)
- if set
- channel.categories << category
- set_parent(category, channel)
- setup_other_elements(rss, category)
- end
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
-
- class Generator < GeneratorBase
- def to_feed(rss, channel)
- channel.generator = content
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
-
- class Image < RSS09::Image
- private
- def required_element?
- false
- end
- end
-
- class Items < RSS09::Items
- class Item < RSS09::Items::Item
- private
- def required_variable_names
- []
- end
-
- def not_set_required_variables
- vars = super
- if !title {|t| t.have_required_values?} and
- !description {|d| d.have_required_values?}
- vars << "title or description"
- end
- vars
- end
-
- def variables
- super + ["pubDate"]
- end
-
- class Guid < RSS09::Items::Item::Guid
- def to_feed(rss, item)
- guid = Rss::Channel::Item::Guid.new
- set = setup_values(guid)
- if set
- item.guid = guid
- set_parent(guid, item)
- setup_other_elements(rss, guid)
- end
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- class Enclosure < RSS09::Items::Item::Enclosure
- def to_feed(rss, item)
- enclosure = Rss::Channel::Item::Enclosure.new
- set = setup_values(enclosure)
- if set
- item.enclosure = enclosure
- set_parent(enclosure, item)
- setup_other_elements(rss, enclosure)
- end
- end
-
- private
- def required_variable_names
- %w(url length type)
- end
- end
-
- class Source < RSS09::Items::Item::Source
- def to_feed(rss, item)
- source = Rss::Channel::Item::Source.new
- set = setup_values(source)
- if set
- item.source = source
- set_parent(source, item)
- setup_other_elements(rss, source)
- end
- end
-
- private
- def required_variable_names
- %w(url content)
- end
-
- class Links < RSS09::Items::Item::Source::Links
- def to_feed(rss, source)
- return if @links.empty?
- @links.first.to_feed(rss, source)
- end
-
- class Link < RSS09::Items::Item::Source::Links::Link
- def to_feed(rss, source)
- source.url = href
- end
- end
- end
- end
-
- class Categories < RSS09::Items::Item::Categories
- def to_feed(rss, item)
- @categories.each do |category|
- category.to_feed(rss, item)
- end
- end
-
- class Category < RSS09::Items::Item::Categories::Category
- def to_feed(rss, item)
- category = Rss::Channel::Item::Category.new
- set = setup_values(category)
- if set
- item.categories << category
- set_parent(category, item)
- setup_other_elements(rss)
- end
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
-
- class Authors < RSS09::Items::Item::Authors
- def to_feed(rss, item)
- return if @authors.empty?
- @authors.first.to_feed(rss, item)
- end
-
- class Author < RSS09::Items::Item::Authors::Author
- def to_feed(rss, item)
- item.author = name
- end
- end
- end
- end
- end
-
- class Textinput < RSS09::Textinput
- end
- end
-
- add_maker("2.0", "2.0", RSS20)
- add_maker("rss2.0", "2.0", RSS20)
- end
-end
diff --git a/lib/rss/maker/atom.rb b/lib/rss/maker/atom.rb
deleted file mode 100644
index cdd1d8753e2..00000000000
--- a/lib/rss/maker/atom.rb
+++ /dev/null
@@ -1,173 +0,0 @@
-# frozen_string_literal: false
-require_relative "../atom"
-
-require_relative "base"
-
-module RSS
- module Maker
- module AtomPersons
- module_function
- def def_atom_persons(klass, name, maker_name, plural=nil)
- plural ||= "#{name}s"
- klass_name = Utils.to_class_name(name)
- plural_klass_name = Utils.to_class_name(plural)
-
- klass.class_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class #{plural_klass_name} < #{plural_klass_name}Base
- class #{klass_name} < #{klass_name}Base
- def to_feed(feed, current)
- #{name} = feed.class::#{klass_name}.new
- set = setup_values(#{name})
- unless set
- raise NotSetError.new(#{maker_name.dump},
- not_set_required_variables)
- end
- current.#{plural} << #{name}
- set_parent(#{name}, current)
- setup_other_elements(#{name})
- end
-
- private
- def required_variable_names
- %w(name)
- end
- end
- end
-EOC
- end
- end
-
- module AtomTextConstruct
- class << self
- def def_atom_text_construct(klass, name, maker_name, klass_name=nil,
- atom_klass_name=nil)
- klass_name ||= Utils.to_class_name(name)
- atom_klass_name ||= Utils.to_class_name(name)
-
- klass.class_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class #{klass_name} < #{klass_name}Base
- include #{self.name}
- def to_feed(feed, current)
- #{name} = current.class::#{atom_klass_name}.new
- if setup_values(#{name})
- current.#{name} = #{name}
- set_parent(#{name}, current)
- setup_other_elements(feed)
- elsif variable_is_set?
- raise NotSetError.new(#{maker_name.dump},
- not_set_required_variables)
- end
- end
- end
- EOC
- end
- end
-
- private
- def required_variable_names
- if type == "xhtml"
- %w(xml_content)
- else
- %w(content)
- end
- end
-
- def variables
- if type == "xhtml"
- super + %w(xhtml)
- else
- super
- end
- end
- end
-
- module AtomCategory
- def to_feed(feed, current)
- category = feed.class::Category.new
- set = setup_values(category)
- if set
- current.categories << category
- set_parent(category, current)
- setup_other_elements(feed)
- else
- raise NotSetError.new(self.class.not_set_name,
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(term)
- end
-
- def variables
- super + ["term", "scheme"]
- end
- end
-
- module AtomLink
- def to_feed(feed, current)
- link = feed.class::Link.new
- set = setup_values(link)
- if set
- current.links << link
- set_parent(link, current)
- setup_other_elements(feed)
- else
- raise NotSetError.new(self.class.not_set_name,
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(href)
- end
- end
-
- module AtomGenerator
- def to_feed(feed, current)
- generator = current.class::Generator.new
- if setup_values(generator)
- current.generator = generator
- set_parent(generator, current)
- setup_other_elements(feed)
- elsif variable_is_set?
- raise NotSetError.new(self.class.not_set_name,
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- module AtomLogo
- def to_feed(feed, current)
- logo = current.class::Logo.new
- class << logo
- alias_method(:uri=, :content=)
- end
- set = setup_values(logo)
- class << logo
- remove_method(:uri=)
- end
- if set
- current.logo = logo
- set_parent(logo, current)
- setup_other_elements(feed)
- elsif variable_is_set?
- raise NotSetError.new(self.class.not_set_name,
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(uri)
- end
- end
- end
-end
diff --git a/lib/rss/maker/base.rb b/lib/rss/maker/base.rb
deleted file mode 100644
index 17537b70062..00000000000
--- a/lib/rss/maker/base.rb
+++ /dev/null
@@ -1,945 +0,0 @@
-# frozen_string_literal: false
-require 'forwardable'
-
-require_relative '../rss'
-
-module RSS
- module Maker
- class Base
- extend Utils::InheritedReader
-
- OTHER_ELEMENTS = []
- NEED_INITIALIZE_VARIABLES = []
-
- class << self
- def other_elements
- inherited_array_reader("OTHER_ELEMENTS")
- end
- def need_initialize_variables
- inherited_array_reader("NEED_INITIALIZE_VARIABLES")
- end
-
- def inherited_base
- ::RSS::Maker::Base
- end
-
- def inherited(subclass)
- subclass.const_set(:OTHER_ELEMENTS, [])
- subclass.const_set(:NEED_INITIALIZE_VARIABLES, [])
- end
-
- def add_other_element(variable_name)
- self::OTHER_ELEMENTS << variable_name
- end
-
- def add_need_initialize_variable(variable_name, init_value=nil,
- &init_block)
- init_value ||= init_block
- self::NEED_INITIALIZE_VARIABLES << [variable_name, init_value]
- end
-
- def def_array_element(name, plural=nil, klass_name=nil)
- include Enumerable
- extend Forwardable
-
- plural ||= "#{name}s"
- klass_name ||= Utils.to_class_name(name)
- def_delegators("@#{plural}", :<<, :[], :[]=, :first, :last)
- def_delegators("@#{plural}", :push, :pop, :shift, :unshift)
- def_delegators("@#{plural}", :each, :size, :empty?, :clear)
-
- add_need_initialize_variable(plural) {[]}
-
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def new_#{name}
- #{name} = self.class::#{klass_name}.new(@maker)
- @#{plural} << #{name}
- if block_given?
- yield #{name}
- else
- #{name}
- end
- end
- alias new_child new_#{name}
-
- def to_feed(*args)
- @#{plural}.each do |#{name}|
- #{name}.to_feed(*args)
- end
- end
-
- def replace(elements)
- @#{plural}.replace(elements.to_a)
- end
- EOC
- end
-
- def def_classed_element_without_accessor(name, class_name=nil)
- class_name ||= Utils.to_class_name(name)
- add_other_element(name)
- add_need_initialize_variable(name) do |object|
- object.send("make_#{name}")
- end
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- private
- def setup_#{name}(feed, current)
- @#{name}.to_feed(feed, current)
- end
-
- def make_#{name}
- self.class::#{class_name}.new(@maker)
- end
- EOC
- end
-
- def def_classed_element(name, class_name=nil, attribute_name=nil)
- def_classed_element_without_accessor(name, class_name)
- if attribute_name
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}
- if block_given?
- yield(@#{name})
- else
- @#{name}.#{attribute_name}
- end
- end
-
- def #{name}=(new_value)
- @#{name}.#{attribute_name} = new_value
- end
- EOC
- else
- attr_reader name
- end
- end
-
- def def_classed_elements(name, attribute, plural_class_name=nil,
- plural_name=nil, new_name=nil)
- plural_name ||= "#{name}s"
- new_name ||= name
- def_classed_element(plural_name, plural_class_name)
- local_variable_name = "_#{name}"
- new_value_variable_name = "new_value"
- additional_setup_code = nil
- if block_given?
- additional_setup_code = yield(local_variable_name,
- new_value_variable_name)
- end
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}
- #{local_variable_name} = #{plural_name}.first
- #{local_variable_name} ? #{local_variable_name}.#{attribute} : nil
- end
-
- def #{name}=(#{new_value_variable_name})
- #{local_variable_name} =
- #{plural_name}.first || #{plural_name}.new_#{new_name}
- #{additional_setup_code}
- #{local_variable_name}.#{attribute} = #{new_value_variable_name}
- end
- EOC
- end
-
- def def_other_element(name)
- attr_accessor name
- def_other_element_without_accessor(name)
- end
-
- def def_other_element_without_accessor(name)
- add_need_initialize_variable(name)
- add_other_element(name)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def setup_#{name}(feed, current)
- if !@#{name}.nil? and current.respond_to?(:#{name}=)
- current.#{name} = @#{name}
- end
- end
- EOC
- end
-
- def def_csv_element(name, type=nil)
- def_other_element_without_accessor(name)
- attr_reader(name)
- converter = ""
- if type == :integer
- converter = "{|v| Integer(v)}"
- end
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}=(value)
- @#{name} = Utils::CSV.parse(value)#{converter}
- end
- EOC
- end
- end
-
- attr_reader :maker
- def initialize(maker)
- @maker = maker
- @default_values_are_set = false
- initialize_variables
- end
-
- def have_required_values?
- not_set_required_variables.empty?
- end
-
- def variable_is_set?
- variables.any? {|var| not __send__(var).nil?}
- end
-
- private
- def initialize_variables
- self.class.need_initialize_variables.each do |variable_name, init_value|
- if init_value.nil?
- value = nil
- else
- if init_value.respond_to?(:call)
- value = init_value.call(self)
- elsif init_value.is_a?(String)
- # just for backward compatibility
- value = instance_eval(init_value, __FILE__, __LINE__)
- else
- value = init_value
- end
- end
- instance_variable_set("@#{variable_name}", value)
- end
- end
-
- def setup_other_elements(feed, current=nil)
- current ||= current_element(feed)
- self.class.other_elements.each do |element|
- __send__("setup_#{element}", feed, current)
- end
- end
-
- def current_element(feed)
- feed
- end
-
- def set_default_values(&block)
- return yield if @default_values_are_set
-
- begin
- @default_values_are_set = true
- _set_default_values(&block)
- ensure
- @default_values_are_set = false
- end
- end
-
- def _set_default_values(&block)
- yield
- end
-
- def setup_values(target)
- set = false
- if have_required_values?
- variables.each do |var|
- setter = "#{var}="
- if target.respond_to?(setter)
- value = __send__(var)
- unless value.nil?
- target.__send__(setter, value)
- set = true
- end
- end
- end
- end
- set
- end
-
- def set_parent(target, parent)
- target.parent = parent if target.class.need_parent?
- end
-
- def variables
- self.class.need_initialize_variables.find_all do |name, init|
- # init == "nil" is just for backward compatibility
- init.nil? or init == "nil"
- end.collect do |name, init|
- name
- end
- end
-
- def not_set_required_variables
- required_variable_names.find_all do |var|
- __send__(var).nil?
- end
- end
-
- def required_variables_are_set?
- required_variable_names.each do |var|
- return false if __send__(var).nil?
- end
- true
- end
- end
-
- module AtomPersonConstructBase
- def self.append_features(klass)
- super
-
- klass.class_eval(<<-EOC, __FILE__, __LINE__ + 1)
- %w(name uri email).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- EOC
- end
- end
-
- module AtomTextConstructBase
- module EnsureXMLContent
- class << self
- def included(base)
- super
- base.class_eval do
- %w(type content xml_content).each do |element|
- attr_reader element
- attr_writer element if element != "xml_content"
- add_need_initialize_variable(element)
- end
-
- alias_method(:xhtml, :xml_content)
- end
- end
- end
-
- def ensure_xml_content(content)
- xhtml_uri = ::RSS::Atom::XHTML_URI
- unless content.is_a?(RSS::XML::Element) and
- ["div", xhtml_uri] == [content.name, content.uri]
- children = content
- children = [children] unless content.is_a?(Array)
- children = set_xhtml_uri_as_default_uri(children)
- content = RSS::XML::Element.new("div", nil, xhtml_uri,
- {"xmlns" => xhtml_uri},
- children)
- end
- content
- end
-
- def xml_content=(content)
- @xml_content = ensure_xml_content(content)
- end
-
- def xhtml=(content)
- self.xml_content = content
- end
-
- private
- def set_xhtml_uri_as_default_uri(children)
- children.collect do |child|
- if child.is_a?(RSS::XML::Element) and
- child.prefix.nil? and child.uri.nil?
- RSS::XML::Element.new(child.name, nil, ::RSS::Atom::XHTML_URI,
- child.attributes.dup,
- set_xhtml_uri_as_default_uri(child.children))
- else
- child
- end
- end
- end
- end
-
- def self.append_features(klass)
- super
-
- klass.class_eval do
- include EnsureXMLContent
- end
- end
- end
-
- module SetupDefaultDate
- private
- def _set_default_values
- keep = {
- :date => date,
- :dc_dates => dc_dates.to_a.dup,
- }
- _date = _parse_date_if_needed(date)
- if _date and !dc_dates.any? {|dc_date| dc_date.value == _date}
- dc_date = self.class::DublinCoreDates::DublinCoreDate.new(self)
- dc_date.value = _date.dup
- dc_dates.unshift(dc_date)
- end
- self.date ||= self.dc_date
- super
- ensure
- self.date = keep[:date]
- dc_dates.replace(keep[:dc_dates])
- end
-
- def _parse_date_if_needed(date_value)
- date_value = Time.parse(date_value) if date_value.is_a?(String)
- date_value
- end
- end
-
- module SetupDefaultLanguage
- private
- def _set_default_values
- keep = {
- :dc_languages => dc_languages.to_a.dup,
- }
- _language = language
- if _language and
- !dc_languages.any? {|dc_language| dc_language.value == _language}
- dc_language = self.class::DublinCoreLanguages::DublinCoreLanguage.new(self)
- dc_language.value = _language.dup
- dc_languages.unshift(dc_language)
- end
- super
- ensure
- dc_languages.replace(keep[:dc_languages])
- end
- end
-
- class RSSBase < Base
- class << self
- def make(*args, &block)
- new(*args).make(&block)
- end
- end
-
- %w(xml_stylesheets channel image items textinput).each do |element|
- attr_reader element
- add_need_initialize_variable(element) do |object|
- object.send("make_#{element}")
- end
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- private
- def setup_#{element}(feed)
- @#{element}.to_feed(feed)
- end
-
- def make_#{element}
- self.class::#{Utils.to_class_name(element)}.new(self)
- end
- EOC
- end
-
- attr_reader :feed_version
- alias_method(:rss_version, :feed_version)
- attr_accessor :version, :encoding, :standalone
-
- def initialize(feed_version)
- super(self)
- @feed_type = nil
- @feed_subtype = nil
- @feed_version = feed_version
- @version = "1.0"
- @encoding = "UTF-8"
- @standalone = nil
- end
-
- def make
- yield(self)
- to_feed
- end
-
- def to_feed
- feed = make_feed
- setup_xml_stylesheets(feed)
- setup_elements(feed)
- setup_other_elements(feed)
- feed.validate
- feed
- end
-
- private
- remove_method :make_xml_stylesheets
- def make_xml_stylesheets
- XMLStyleSheets.new(self)
- end
- end
-
- class XMLStyleSheets < Base
- def_array_element("xml_stylesheet", nil, "XMLStyleSheet")
-
- class XMLStyleSheet < Base
-
- ::RSS::XMLStyleSheet::ATTRIBUTES.each do |attribute|
- attr_accessor attribute
- add_need_initialize_variable(attribute)
- end
-
- def to_feed(feed)
- xss = ::RSS::XMLStyleSheet.new
- guess_type_if_need(xss)
- set = setup_values(xss)
- if set
- feed.xml_stylesheets << xss
- end
- end
-
- private
- def guess_type_if_need(xss)
- if @type.nil?
- xss.href = @href
- @type = xss.type
- end
- end
-
- def required_variable_names
- %w(href type)
- end
- end
- end
-
- class ChannelBase < Base
- include SetupDefaultDate
-
- %w(cloud categories skipDays skipHours).each do |name|
- def_classed_element(name)
- end
-
- %w(generator copyright description title).each do |name|
- def_classed_element(name, nil, "content")
- end
-
- [
- ["link", "href", Proc.new {|target,| "#{target}.href = 'self'"}],
- ["author", "name"],
- ["contributor", "name"],
- ].each do |name, attribute, additional_setup_maker|
- def_classed_elements(name, attribute, &additional_setup_maker)
- end
-
- %w(id about language
- managingEditor webMaster rating docs ttl).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
-
- %w(date lastBuildDate).each do |date_element|
- attr_reader date_element
- add_need_initialize_variable(date_element)
- end
-
- def date=(_date)
- @date = _parse_date_if_needed(_date)
- end
-
- def lastBuildDate=(_date)
- @lastBuildDate = _parse_date_if_needed(_date)
- end
-
- def pubDate
- date
- end
-
- def pubDate=(date)
- self.date = date
- end
-
- def updated
- date
- end
-
- def updated=(date)
- self.date = date
- end
-
- alias_method(:rights, :copyright)
- alias_method(:rights=, :copyright=)
-
- alias_method(:subtitle, :description)
- alias_method(:subtitle=, :description=)
-
- def icon
- image_favicon.about
- end
-
- def icon=(url)
- image_favicon.about = url
- end
-
- def logo
- maker.image.url
- end
-
- def logo=(url)
- maker.image.url = url
- end
-
- class SkipDaysBase < Base
- def_array_element("day")
-
- class DayBase < Base
- %w(content).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
- end
-
- class SkipHoursBase < Base
- def_array_element("hour")
-
- class HourBase < Base
- %w(content).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
- end
-
- class CloudBase < Base
- %w(domain port path registerProcedure protocol).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
-
- class CategoriesBase < Base
- def_array_element("category", "categories")
-
- class CategoryBase < Base
- %w(domain content label).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
-
- alias_method(:term, :domain)
- alias_method(:term=, :domain=)
- alias_method(:scheme, :content)
- alias_method(:scheme=, :content=)
- end
- end
-
- class LinksBase < Base
- def_array_element("link")
-
- class LinkBase < Base
- %w(href rel type hreflang title length).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
- end
-
- class AuthorsBase < Base
- def_array_element("author")
-
- class AuthorBase < Base
- include AtomPersonConstructBase
- end
- end
-
- class ContributorsBase < Base
- def_array_element("contributor")
-
- class ContributorBase < Base
- include AtomPersonConstructBase
- end
- end
-
- class GeneratorBase < Base
- %w(uri version content).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
-
- class CopyrightBase < Base
- include AtomTextConstructBase
- end
-
- class DescriptionBase < Base
- include AtomTextConstructBase
- end
-
- class TitleBase < Base
- include AtomTextConstructBase
- end
- end
-
- class ImageBase < Base
- %w(title url width height description).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
-
- def link
- @maker.channel.link
- end
- end
-
- class ItemsBase < Base
- def_array_element("item")
-
- attr_accessor :do_sort, :max_size
-
- def initialize(maker)
- super
- @do_sort = false
- @max_size = -1
- end
-
- def normalize
- if @max_size >= 0
- sort_if_need[0...@max_size]
- else
- sort_if_need[0..@max_size]
- end
- end
-
- private
- def sort_if_need
- if @do_sort.respond_to?(:call)
- @items.sort do |x, y|
- @do_sort.call(x, y)
- end
- elsif @do_sort
- @items.sort do |x, y|
- y <=> x
- end
- else
- @items
- end
- end
-
- class ItemBase < Base
- include SetupDefaultDate
-
- %w(guid enclosure source categories content).each do |name|
- def_classed_element(name)
- end
-
- %w(rights description title).each do |name|
- def_classed_element(name, nil, "content")
- end
-
- [
- ["author", "name"],
- ["link", "href", Proc.new {|target,| "#{target}.href = 'alternate'"}],
- ["contributor", "name"],
- ].each do |name, attribute|
- def_classed_elements(name, attribute)
- end
-
- %w(comments id published).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
-
- %w(date).each do |date_element|
- attr_reader date_element
- add_need_initialize_variable(date_element)
- end
-
- def date=(_date)
- @date = _parse_date_if_needed(_date)
- end
-
- def pubDate
- date
- end
-
- def pubDate=(date)
- self.date = date
- end
-
- def updated
- date
- end
-
- def updated=(date)
- self.date = date
- end
-
- alias_method(:summary, :description)
- alias_method(:summary=, :description=)
-
- def <=>(other)
- _date = date || dc_date
- _other_date = other.date || other.dc_date
- if _date and _other_date
- _date <=> _other_date
- elsif _date
- 1
- elsif _other_date
- -1
- else
- 0
- end
- end
-
- class GuidBase < Base
- %w(isPermaLink content).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
-
- def permanent_link?
- isPermaLink
- end
-
- def permanent_link=(bool)
- self.isPermaLink = bool
- end
- end
-
- class EnclosureBase < Base
- %w(url length type).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
-
- class SourceBase < Base
- include SetupDefaultDate
-
- %w(authors categories contributors generator icon
- logo rights subtitle title).each do |name|
- def_classed_element(name)
- end
-
- [
- ["link", "href"],
- ].each do |name, attribute|
- def_classed_elements(name, attribute)
- end
-
- %w(id content).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
-
- alias_method(:url, :link)
- alias_method(:url=, :link=)
-
- %w(date).each do |date_element|
- attr_reader date_element
- add_need_initialize_variable(date_element)
- end
-
- def date=(_date)
- @date = _parse_date_if_needed(_date)
- end
-
- def updated
- date
- end
-
- def updated=(date)
- self.date = date
- end
-
- private
- AuthorsBase = ChannelBase::AuthorsBase
- CategoriesBase = ChannelBase::CategoriesBase
- ContributorsBase = ChannelBase::ContributorsBase
- GeneratorBase = ChannelBase::GeneratorBase
-
- class IconBase < Base
- %w(url).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
-
- LinksBase = ChannelBase::LinksBase
-
- class LogoBase < Base
- %w(uri).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
-
- class RightsBase < Base
- include AtomTextConstructBase
- end
-
- class SubtitleBase < Base
- include AtomTextConstructBase
- end
-
- class TitleBase < Base
- include AtomTextConstructBase
- end
- end
-
- CategoriesBase = ChannelBase::CategoriesBase
- AuthorsBase = ChannelBase::AuthorsBase
- LinksBase = ChannelBase::LinksBase
- ContributorsBase = ChannelBase::ContributorsBase
-
- class RightsBase < Base
- include AtomTextConstructBase
- end
-
- class DescriptionBase < Base
- include AtomTextConstructBase
- end
-
- class ContentBase < Base
- include AtomTextConstructBase::EnsureXMLContent
-
- %w(src).each do |element|
- attr_accessor(element)
- add_need_initialize_variable(element)
- end
-
- def xml_content=(content)
- content = ensure_xml_content(content) if inline_xhtml?
- @xml_content = content
- end
-
- alias_method(:xml, :xml_content)
- alias_method(:xml=, :xml_content=)
-
- def inline_text?
- [nil, "text", "html"].include?(@type)
- end
-
- def inline_html?
- @type == "html"
- end
-
- def inline_xhtml?
- @type == "xhtml"
- end
-
- def inline_other?
- !out_of_line? and ![nil, "text", "html", "xhtml"].include?(@type)
- end
-
- def inline_other_text?
- return false if @type.nil? or out_of_line?
- /\Atext\//i.match(@type) ? true : false
- end
-
- def inline_other_xml?
- return false if @type.nil? or out_of_line?
- /[\+\/]xml\z/i.match(@type) ? true : false
- end
-
- def inline_other_base64?
- return false if @type.nil? or out_of_line?
- @type.include?("/") and !inline_other_text? and !inline_other_xml?
- end
-
- def out_of_line?
- not @src.nil? and @content.nil?
- end
- end
-
- class TitleBase < Base
- include AtomTextConstructBase
- end
- end
- end
-
- class TextinputBase < Base
- %w(title description name link).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
- end
-end
diff --git a/lib/rss/maker/content.rb b/lib/rss/maker/content.rb
deleted file mode 100644
index b3f4e5036e8..00000000000
--- a/lib/rss/maker/content.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# frozen_string_literal: false
-require_relative '../content'
-require_relative '1.0'
-require_relative '2.0'
-
-module RSS
- module Maker
- module ContentModel
- def self.append_features(klass)
- super
-
- ::RSS::ContentModel::ELEMENTS.each do |name|
- klass.def_other_element(name)
- end
- end
- end
-
- class ItemsBase
- class ItemBase; include ContentModel; end
- end
- end
-end
diff --git a/lib/rss/maker/dublincore.rb b/lib/rss/maker/dublincore.rb
deleted file mode 100644
index beea3134b4f..00000000000
--- a/lib/rss/maker/dublincore.rb
+++ /dev/null
@@ -1,122 +0,0 @@
-# frozen_string_literal: false
-require_relative '../dublincore'
-require_relative '1.0'
-
-module RSS
- module Maker
- module DublinCoreModel
- def self.append_features(klass)
- super
-
- ::RSS::DublinCoreModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
- plural_name ||= "#{name}s"
- full_name = "#{RSS::DC_PREFIX}_#{name}"
- full_plural_name = "#{RSS::DC_PREFIX}_#{plural_name}"
- plural_klass_name = "DublinCore#{Utils.to_class_name(plural_name)}"
- klass.def_classed_elements(full_name, "value", plural_klass_name,
- full_plural_name, name)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def new_#{full_name}(value=nil)
- _#{full_name} = #{full_plural_name}.new_#{name}
- _#{full_name}.value = value
- if block_given?
- yield _#{full_name}
- else
- _#{full_name}
- end
- end
- EOC
- end
-
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- # For backward compatibility
- alias #{DC_PREFIX}_rightses #{DC_PREFIX}_rights_list
- EOC
- end
-
- ::RSS::DublinCoreModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
- plural_name ||= "#{name}s"
- full_name ||= "#{DC_PREFIX}_#{name}"
- full_plural_name ||= "#{DC_PREFIX}_#{plural_name}"
- klass_name = Utils.to_class_name(name)
- full_klass_name = "DublinCore#{klass_name}"
- plural_klass_name = "DublinCore#{Utils.to_class_name(plural_name)}"
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class #{plural_klass_name}Base < Base
- def_array_element(#{name.dump}, #{full_plural_name.dump},
- #{full_klass_name.dump})
-
- class #{full_klass_name}Base < Base
- attr_accessor :value
- add_need_initialize_variable("value")
- alias_method(:content, :value)
- alias_method(:content=, :value=)
-
- def have_required_values?
- @value
- end
-
- def to_feed(feed, current)
- if value and current.respond_to?(:#{full_name})
- new_item = current.class::#{full_klass_name}.new(value)
- current.#{full_plural_name} << new_item
- end
- end
- end
- #{klass_name}Base = #{full_klass_name}Base
- end
- EOC
- end
-
- def self.install_dublin_core(klass)
- ::RSS::DublinCoreModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
- plural_name ||= "#{name}s"
- klass_name = Utils.to_class_name(name)
- full_klass_name = "DublinCore#{klass_name}"
- plural_klass_name = "DublinCore#{Utils.to_class_name(plural_name)}"
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class #{plural_klass_name} < #{plural_klass_name}Base
- class #{full_klass_name} < #{full_klass_name}Base
- end
- #{klass_name} = #{full_klass_name}
- end
-EOC
- end
- end
- end
-
- class ChannelBase
- include DublinCoreModel
- end
-
- class ImageBase; include DublinCoreModel; end
- class ItemsBase
- class ItemBase
- include DublinCoreModel
- end
- end
- class TextinputBase; include DublinCoreModel; end
-
- makers.each do |maker|
- maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class Channel
- DublinCoreModel.install_dublin_core(self)
- end
-
- class Image
- DublinCoreModel.install_dublin_core(self)
- end
-
- class Items
- class Item
- DublinCoreModel.install_dublin_core(self)
- end
- end
-
- class Textinput
- DublinCoreModel.install_dublin_core(self)
- end
- EOC
- end
- end
-end
diff --git a/lib/rss/maker/entry.rb b/lib/rss/maker/entry.rb
deleted file mode 100644
index ccdf9608ae6..00000000000
--- a/lib/rss/maker/entry.rb
+++ /dev/null
@@ -1,164 +0,0 @@
-# frozen_string_literal: false
-require_relative "atom"
-require_relative "feed"
-
-module RSS
- module Maker
- module Atom
- class Entry < RSSBase
- def initialize(feed_version="1.0")
- super
- @feed_type = "atom"
- @feed_subtype = "entry"
- end
-
- private
- def make_feed
- ::RSS::Atom::Entry.new(@version, @encoding, @standalone)
- end
-
- def setup_elements(entry)
- setup_items(entry)
- end
-
- class Channel < ChannelBase
- class SkipDays < SkipDaysBase
- class Day < DayBase
- end
- end
-
- class SkipHours < SkipHoursBase
- class Hour < HourBase
- end
- end
-
- class Cloud < CloudBase
- end
-
- Categories = Feed::Channel::Categories
- Links = Feed::Channel::Links
- Authors = Feed::Channel::Authors
- Contributors = Feed::Channel::Contributors
-
- class Generator < GeneratorBase
- include AtomGenerator
-
- def self.not_set_name
- "maker.channel.generator"
- end
- end
-
- Copyright = Feed::Channel::Copyright
-
- class Description < DescriptionBase
- end
-
- Title = Feed::Channel::Title
- end
-
- class Image < ImageBase
- end
-
- class Items < ItemsBase
- def to_feed(entry)
- (normalize.first || Item.new(@maker)).to_feed(entry)
- end
-
- class Item < ItemBase
- def to_feed(entry)
- set_default_values do
- setup_values(entry)
- entry.dc_dates.clear
- setup_other_elements(entry)
- unless have_required_values?
- raise NotSetError.new("maker.item", not_set_required_variables)
- end
- end
- end
-
- private
- def required_variable_names
- %w(id updated)
- end
-
- def variables
- super + ["updated"]
- end
-
- def variable_is_set?
- super or !authors.empty?
- end
-
- def not_set_required_variables
- set_default_values do
- vars = super
- if authors.all? {|author| !author.have_required_values?}
- vars << "author"
- end
- vars << "title" unless title {|t| t.have_required_values?}
- vars
- end
- end
-
- def _set_default_values
- keep = {
- :authors => authors.to_a.dup,
- :contributors => contributors.to_a.dup,
- :categories => categories.to_a.dup,
- :id => id,
- :links => links.to_a.dup,
- :rights => @rights,
- :title => @title,
- :updated => updated,
- }
- authors.replace(@maker.channel.authors) if keep[:authors].empty?
- if keep[:contributors].empty?
- contributors.replace(@maker.channel.contributors)
- end
- if keep[:categories].empty?
- categories.replace(@maker.channel.categories)
- end
- self.id ||= link || @maker.channel.id
- links.replace(@maker.channel.links) if keep[:links].empty?
- unless keep[:rights].variable_is_set?
- @maker.channel.rights {|r| @rights = r}
- end
- unless keep[:title].variable_is_set?
- @maker.channel.title {|t| @title = t}
- end
- self.updated ||= @maker.channel.updated
- super
- ensure
- authors.replace(keep[:authors])
- contributors.replace(keep[:contributors])
- categories.replace(keep[:categories])
- links.replace(keep[:links])
- self.id = keep[:id]
- @rights = keep[:rights]
- @title = keep[:title]
- self.updated = keep[:updated]
- end
-
- Guid = Feed::Items::Item::Guid
- Enclosure = Feed::Items::Item::Enclosure
- Source = Feed::Items::Item::Source
- Categories = Feed::Items::Item::Categories
- Authors = Feed::Items::Item::Authors
- Contributors = Feed::Items::Item::Contributors
- Links = Feed::Items::Item::Links
- Rights = Feed::Items::Item::Rights
- Description = Feed::Items::Item::Description
- Title = Feed::Items::Item::Title
- Content = Feed::Items::Item::Content
- end
- end
-
- class Textinput < TextinputBase
- end
- end
- end
-
- add_maker("atom:entry", "1.0", Atom::Entry)
- add_maker("atom1.0:entry", "1.0", Atom::Entry)
- end
-end
diff --git a/lib/rss/maker/feed.rb b/lib/rss/maker/feed.rb
deleted file mode 100644
index 72ee704d6af..00000000000
--- a/lib/rss/maker/feed.rb
+++ /dev/null
@@ -1,427 +0,0 @@
-# frozen_string_literal: false
-require_relative "atom"
-
-module RSS
- module Maker
- module Atom
- class Feed < RSSBase
- def initialize(feed_version="1.0")
- super
- @feed_type = "atom"
- @feed_subtype = "feed"
- end
-
- private
- def make_feed
- ::RSS::Atom::Feed.new(@version, @encoding, @standalone)
- end
-
- def setup_elements(feed)
- setup_channel(feed)
- setup_image(feed)
- setup_items(feed)
- end
-
- class Channel < ChannelBase
- include SetupDefaultLanguage
-
- def to_feed(feed)
- set_default_values do
- setup_values(feed)
- feed.dc_dates.clear
- setup_other_elements(feed)
- if image_favicon.about
- icon = feed.class::Icon.new
- icon.content = image_favicon.about
- feed.icon = icon
- end
- unless have_required_values?
- raise NotSetError.new("maker.channel",
- not_set_required_variables)
- end
- end
- end
-
- def have_required_values?
- super and
- (!authors.empty? or
- @maker.items.any? {|item| !item.authors.empty?})
- end
-
- private
- def required_variable_names
- %w(id updated)
- end
-
- def variables
- super + %w(id updated)
- end
-
- def variable_is_set?
- super or !authors.empty?
- end
-
- def not_set_required_variables
- vars = super
- if authors.empty? and
- @maker.items.all? {|item| item.author.to_s.empty?}
- vars << "author"
- end
- vars << "title" unless title {|t| t.have_required_values?}
- vars
- end
-
- def _set_default_values(&block)
- keep = {
- :id => id,
- }
- self.id ||= about
- super(&block)
- ensure
- self.id = keep[:id]
- end
-
- class SkipDays < SkipDaysBase
- def to_feed(*args)
- end
-
- class Day < DayBase
- end
- end
-
- class SkipHours < SkipHoursBase
- def to_feed(*args)
- end
-
- class Hour < HourBase
- end
- end
-
- class Cloud < CloudBase
- def to_feed(*args)
- end
- end
-
- class Categories < CategoriesBase
- class Category < CategoryBase
- include AtomCategory
-
- def self.not_set_name
- "maker.channel.category"
- end
- end
- end
-
- class Links < LinksBase
- class Link < LinkBase
- include AtomLink
-
- def self.not_set_name
- "maker.channel.link"
- end
- end
- end
-
- AtomPersons.def_atom_persons(self, "author", "maker.channel.author")
- AtomPersons.def_atom_persons(self, "contributor",
- "maker.channel.contributor")
-
- class Generator < GeneratorBase
- include AtomGenerator
-
- def self.not_set_name
- "maker.channel.generator"
- end
- end
-
- AtomTextConstruct.def_atom_text_construct(self, "rights",
- "maker.channel.copyright",
- "Copyright")
- AtomTextConstruct.def_atom_text_construct(self, "subtitle",
- "maker.channel.description",
- "Description")
- AtomTextConstruct.def_atom_text_construct(self, "title",
- "maker.channel.title")
- end
-
- class Image < ImageBase
- def to_feed(feed)
- logo = feed.class::Logo.new
- class << logo
- alias_method(:url=, :content=)
- end
- set = setup_values(logo)
- class << logo
- remove_method(:url=)
- end
- if set
- feed.logo = logo
- set_parent(logo, feed)
- setup_other_elements(feed, logo)
- elsif variable_is_set?
- raise NotSetError.new("maker.image", not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(url)
- end
- end
-
- class Items < ItemsBase
- def to_feed(feed)
- normalize.each do |item|
- item.to_feed(feed)
- end
- setup_other_elements(feed, feed.entries)
- end
-
- class Item < ItemBase
- def to_feed(feed)
- set_default_values do
- entry = feed.class::Entry.new
- set = setup_values(entry)
- entry.dc_dates.clear
- setup_other_elements(feed, entry)
- if set
- feed.entries << entry
- set_parent(entry, feed)
- elsif variable_is_set?
- raise NotSetError.new("maker.item", not_set_required_variables)
- end
- end
- end
-
- def have_required_values?
- set_default_values do
- super and title {|t| t.have_required_values?}
- end
- end
-
- private
- def required_variable_names
- %w(id updated)
- end
-
- def variables
- super + ["updated"]
- end
-
- def not_set_required_variables
- vars = super
- vars << "title" unless title {|t| t.have_required_values?}
- vars
- end
-
- def _set_default_values(&block)
- keep = {
- :id => id,
- }
- self.id ||= link
- super(&block)
- ensure
- self.id = keep[:id]
- end
-
- class Guid < GuidBase
- def to_feed(feed, current)
- end
- end
-
- class Enclosure < EnclosureBase
- def to_feed(feed, current)
- end
- end
-
- class Source < SourceBase
- def to_feed(feed, current)
- source = current.class::Source.new
- setup_values(source)
- current.source = source
- set_parent(source, current)
- setup_other_elements(feed, source)
- current.source = nil if source.to_s == "<source/>"
- end
-
- private
- def required_variable_names
- []
- end
-
- def variables
- super + ["updated"]
- end
-
- AtomPersons.def_atom_persons(self, "author",
- "maker.item.source.author")
- AtomPersons.def_atom_persons(self, "contributor",
- "maker.item.source.contributor")
-
- class Categories < CategoriesBase
- class Category < CategoryBase
- include AtomCategory
-
- def self.not_set_name
- "maker.item.source.category"
- end
- end
- end
-
- class Generator < GeneratorBase
- include AtomGenerator
-
- def self.not_set_name
- "maker.item.source.generator"
- end
- end
-
- class Icon < IconBase
- def to_feed(feed, current)
- icon = current.class::Icon.new
- class << icon
- alias_method(:url=, :content=)
- end
- set = setup_values(icon)
- class << icon
- remove_method(:url=)
- end
- if set
- current.icon = icon
- set_parent(icon, current)
- setup_other_elements(feed, icon)
- elsif variable_is_set?
- raise NotSetError.new("maker.item.source.icon",
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(url)
- end
- end
-
- class Links < LinksBase
- class Link < LinkBase
- include AtomLink
-
- def self.not_set_name
- "maker.item.source.link"
- end
- end
- end
-
- class Logo < LogoBase
- include AtomLogo
-
- def self.not_set_name
- "maker.item.source.logo"
- end
- end
-
- maker_name_base = "maker.item.source."
- maker_name = "#{maker_name_base}rights"
- AtomTextConstruct.def_atom_text_construct(self, "rights",
- maker_name)
- maker_name = "#{maker_name_base}subtitle"
- AtomTextConstruct.def_atom_text_construct(self, "subtitle",
- maker_name)
- maker_name = "#{maker_name_base}title"
- AtomTextConstruct.def_atom_text_construct(self, "title",
- maker_name)
- end
-
- class Categories < CategoriesBase
- class Category < CategoryBase
- include AtomCategory
-
- def self.not_set_name
- "maker.item.category"
- end
- end
- end
-
- AtomPersons.def_atom_persons(self, "author", "maker.item.author")
- AtomPersons.def_atom_persons(self, "contributor",
- "maker.item.contributor")
-
- class Links < LinksBase
- class Link < LinkBase
- include AtomLink
-
- def self.not_set_name
- "maker.item.link"
- end
- end
- end
-
- AtomTextConstruct.def_atom_text_construct(self, "rights",
- "maker.item.rights")
- AtomTextConstruct.def_atom_text_construct(self, "summary",
- "maker.item.description",
- "Description")
- AtomTextConstruct.def_atom_text_construct(self, "title",
- "maker.item.title")
-
- class Content < ContentBase
- def to_feed(feed, current)
- content = current.class::Content.new
- if setup_values(content)
- content.src = nil if content.src and content.content
- current.content = content
- set_parent(content, current)
- setup_other_elements(feed, content)
- elsif variable_is_set?
- raise NotSetError.new("maker.item.content",
- not_set_required_variables)
- end
- end
-
- alias_method(:xml, :xml_content)
-
- private
- def required_variable_names
- if out_of_line?
- %w(type)
- elsif xml_type?
- %w(xml_content)
- else
- %w(content)
- end
- end
-
- def variables
- if out_of_line?
- super
- elsif xml_type?
- super + %w(xml)
- else
- super
- end
- end
-
- def xml_type?
- _type = type
- return false if _type.nil?
- _type == "xhtml" or
- /(?:\+xml|\/xml)$/i =~ _type or
- %w(text/xml-external-parsed-entity
- application/xml-external-parsed-entity
- application/xml-dtd).include?(_type.downcase)
- end
- end
- end
- end
-
- class Textinput < TextinputBase
- end
- end
- end
-
- add_maker("atom", "1.0", Atom::Feed)
- add_maker("atom:feed", "1.0", Atom::Feed)
- add_maker("atom1.0", "1.0", Atom::Feed)
- add_maker("atom1.0:feed", "1.0", Atom::Feed)
- end
-end
diff --git a/lib/rss/maker/image.rb b/lib/rss/maker/image.rb
deleted file mode 100644
index e3e62d8b9e9..00000000000
--- a/lib/rss/maker/image.rb
+++ /dev/null
@@ -1,112 +0,0 @@
-# frozen_string_literal: false
-require_relative '../image'
-require_relative '1.0'
-require_relative 'dublincore'
-
-module RSS
- module Maker
- module ImageItemModel
- def self.append_features(klass)
- super
-
- name = "#{RSS::IMAGE_PREFIX}_item"
- klass.def_classed_element(name)
- end
-
- def self.install_image_item(klass)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class ImageItem < ImageItemBase
- DublinCoreModel.install_dublin_core(self)
- end
-EOC
- end
-
- class ImageItemBase < Base
- include Maker::DublinCoreModel
-
- attr_accessor :about, :resource, :image_width, :image_height
- add_need_initialize_variable("about")
- add_need_initialize_variable("resource")
- add_need_initialize_variable("image_width")
- add_need_initialize_variable("image_height")
- alias width= image_width=
- alias width image_width
- alias height= image_height=
- alias height image_height
-
- def have_required_values?
- @about
- end
-
- def to_feed(feed, current)
- if current.respond_to?(:image_item=) and have_required_values?
- item = current.class::ImageItem.new
- setup_values(item)
- setup_other_elements(item)
- current.image_item = item
- end
- end
- end
- end
-
- module ImageFaviconModel
- def self.append_features(klass)
- super
-
- name = "#{RSS::IMAGE_PREFIX}_favicon"
- klass.def_classed_element(name)
- end
-
- def self.install_image_favicon(klass)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class ImageFavicon < ImageFaviconBase
- DublinCoreModel.install_dublin_core(self)
- end
- EOC
- end
-
- class ImageFaviconBase < Base
- include Maker::DublinCoreModel
-
- attr_accessor :about, :image_size
- add_need_initialize_variable("about")
- add_need_initialize_variable("image_size")
- alias size image_size
- alias size= image_size=
-
- def have_required_values?
- @about and @image_size
- end
-
- def to_feed(feed, current)
- if current.respond_to?(:image_favicon=) and have_required_values?
- favicon = current.class::ImageFavicon.new
- setup_values(favicon)
- setup_other_elements(favicon)
- current.image_favicon = favicon
- end
- end
- end
- end
-
- class ChannelBase; include Maker::ImageFaviconModel; end
-
- class ItemsBase
- class ItemBase; include Maker::ImageItemModel; end
- end
-
- makers.each do |maker|
- maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class Channel
- ImageFaviconModel.install_image_favicon(self)
- end
-
- class Items
- class Item
- ImageItemModel.install_image_item(self)
- end
- end
- EOC
- end
- end
-end
diff --git a/lib/rss/maker/itunes.rb b/lib/rss/maker/itunes.rb
deleted file mode 100644
index 28cca320213..00000000000
--- a/lib/rss/maker/itunes.rb
+++ /dev/null
@@ -1,243 +0,0 @@
-# frozen_string_literal: false
-require_relative '../itunes'
-require_relative '2.0'
-
-module RSS
- module Maker
- module ITunesBaseModel
- def def_class_accessor(klass, name, type, *args)
- name = name.gsub(/-/, "_").gsub(/^itunes_/, '')
- full_name = "#{RSS::ITUNES_PREFIX}_#{name}"
- case type
- when nil
- klass.def_other_element(full_name)
- when :yes_other
- def_yes_other_accessor(klass, full_name)
- when :explicit_clean_other
- def_explicit_clean_other_accessor(klass, full_name)
- when :csv
- def_csv_accessor(klass, full_name)
- when :element, :attribute
- recommended_attribute_name, = *args
- klass_name = "ITunes#{Utils.to_class_name(name)}"
- klass.def_classed_element(full_name, klass_name,
- recommended_attribute_name)
- when :elements
- plural_name, recommended_attribute_name = args
- plural_name ||= "#{name}s"
- full_plural_name = "#{RSS::ITUNES_PREFIX}_#{plural_name}"
- klass_name = "ITunes#{Utils.to_class_name(name)}"
- plural_klass_name = "ITunes#{Utils.to_class_name(plural_name)}"
- def_elements_class_accessor(klass, name, full_name, full_plural_name,
- klass_name, plural_klass_name,
- recommended_attribute_name)
- end
- end
-
- def def_yes_other_accessor(klass, full_name)
- klass.def_other_element(full_name)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{full_name}?
- Utils::YesOther.parse(@#{full_name})
- end
- EOC
- end
-
- def def_explicit_clean_other_accessor(klass, full_name)
- klass.def_other_element(full_name)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{full_name}?
- Utils::ExplicitCleanOther.parse(#{full_name})
- end
- EOC
- end
-
- def def_csv_accessor(klass, full_name)
- klass.def_csv_element(full_name)
- end
-
- def def_elements_class_accessor(klass, name, full_name, full_plural_name,
- klass_name, plural_klass_name,
- recommended_attribute_name=nil)
- if recommended_attribute_name
- klass.def_classed_elements(full_name, recommended_attribute_name,
- plural_klass_name, full_plural_name)
- else
- klass.def_classed_element(full_plural_name, plural_klass_name)
- end
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def new_#{full_name}(text=nil)
- #{full_name} = @#{full_plural_name}.new_#{name}
- #{full_name}.text = text
- if block_given?
- yield #{full_name}
- else
- #{full_name}
- end
- end
- EOC
- end
- end
-
- module ITunesChannelModel
- extend ITunesBaseModel
-
- class << self
- def append_features(klass)
- super
-
- ::RSS::ITunesChannelModel::ELEMENT_INFOS.each do |name, type, *args|
- def_class_accessor(klass, name, type, *args)
- end
- end
- end
-
- class ITunesCategoriesBase < Base
- def_array_element("category", "itunes_categories",
- "ITunesCategory")
- class ITunesCategoryBase < Base
- attr_accessor :text
- add_need_initialize_variable("text")
- def_array_element("category", "itunes_categories",
- "ITunesCategory")
-
- def have_required_values?
- text
- end
-
- alias_method :to_feed_for_categories, :to_feed
- def to_feed(feed, current)
- if text and current.respond_to?(:itunes_category)
- new_item = current.class::ITunesCategory.new(text)
- to_feed_for_categories(feed, new_item)
- current.itunes_categories << new_item
- end
- end
- end
- end
-
- class ITunesImageBase < Base
- add_need_initialize_variable("href")
- attr_accessor("href")
-
- def to_feed(feed, current)
- if @href and current.respond_to?(:itunes_image)
- current.itunes_image ||= current.class::ITunesImage.new
- current.itunes_image.href = @href
- end
- end
- end
-
- class ITunesOwnerBase < Base
- %w(itunes_name itunes_email).each do |name|
- add_need_initialize_variable(name)
- attr_accessor(name)
- end
-
- def to_feed(feed, current)
- if current.respond_to?(:itunes_owner=)
- _not_set_required_variables = not_set_required_variables
- if (required_variable_names - _not_set_required_variables).empty?
- return
- end
-
- unless have_required_values?
- raise NotSetError.new("maker.channel.itunes_owner",
- _not_set_required_variables)
- end
- current.itunes_owner ||= current.class::ITunesOwner.new
- current.itunes_owner.itunes_name = @itunes_name
- current.itunes_owner.itunes_email = @itunes_email
- end
- end
-
- private
- def required_variable_names
- %w(itunes_name itunes_email)
- end
- end
- end
-
- module ITunesItemModel
- extend ITunesBaseModel
-
- class << self
- def append_features(klass)
- super
-
- ::RSS::ITunesItemModel::ELEMENT_INFOS.each do |name, type, *args|
- def_class_accessor(klass, name, type, *args)
- end
- end
- end
-
- class ITunesDurationBase < Base
- attr_reader :content
- add_need_initialize_variable("content")
-
- %w(hour minute second).each do |name|
- attr_reader(name)
- add_need_initialize_variable(name, 0)
- end
-
- def content=(content)
- if content.nil?
- @hour, @minute, @second, @content = nil
- else
- @hour, @minute, @second =
- ::RSS::ITunesItemModel::ITunesDuration.parse(content)
- @content = content
- end
- end
-
- def hour=(hour)
- @hour = Integer(hour)
- update_content
- end
-
- def minute=(minute)
- @minute = Integer(minute)
- update_content
- end
-
- def second=(second)
- @second = Integer(second)
- update_content
- end
-
- def to_feed(feed, current)
- if @content and current.respond_to?(:itunes_duration=)
- current.itunes_duration ||= current.class::ITunesDuration.new
- current.itunes_duration.content = @content
- end
- end
-
- private
- def update_content
- components = [@hour, @minute, @second]
- @content =
- ::RSS::ITunesItemModel::ITunesDuration.construct(*components)
- end
- end
- end
-
- class ChannelBase
- include Maker::ITunesChannelModel
- class ITunesCategories < ITunesCategoriesBase
- class ITunesCategory < ITunesCategoryBase
- ITunesCategory = self
- end
- end
-
- class ITunesImage < ITunesImageBase; end
- class ITunesOwner < ITunesOwnerBase; end
- end
-
- class ItemsBase
- class ItemBase
- include Maker::ITunesItemModel
- class ITunesDuration < ITunesDurationBase; end
- end
- end
- end
-end
diff --git a/lib/rss/maker/slash.rb b/lib/rss/maker/slash.rb
deleted file mode 100644
index 473991903f0..00000000000
--- a/lib/rss/maker/slash.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# frozen_string_literal: false
-require_relative '../slash'
-require_relative '1.0'
-
-module RSS
- module Maker
- module SlashModel
- def self.append_features(klass)
- super
-
- ::RSS::SlashModel::ELEMENT_INFOS.each do |name, type|
- full_name = "#{RSS::SLASH_PREFIX}_#{name}"
- case type
- when :csv_integer
- klass.def_csv_element(full_name, :integer)
- else
- klass.def_other_element(full_name)
- end
- end
-
- klass.module_eval do
- alias_method(:slash_hit_parades, :slash_hit_parade)
- alias_method(:slash_hit_parades=, :slash_hit_parade=)
- end
- end
- end
-
- class ItemsBase
- class ItemBase
- include SlashModel
- end
- end
- end
-end
diff --git a/lib/rss/maker/syndication.rb b/lib/rss/maker/syndication.rb
deleted file mode 100644
index 9fd0efe99ea..00000000000
--- a/lib/rss/maker/syndication.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: false
-require_relative '../syndication'
-require_relative '1.0'
-
-module RSS
- module Maker
- module SyndicationModel
- def self.append_features(klass)
- super
-
- ::RSS::SyndicationModel::ELEMENTS.each do |name|
- klass.def_other_element(name)
- end
- end
- end
-
- class ChannelBase; include SyndicationModel; end
- end
-end
diff --git a/lib/rss/maker/taxonomy.rb b/lib/rss/maker/taxonomy.rb
deleted file mode 100644
index f9858922dad..00000000000
--- a/lib/rss/maker/taxonomy.rb
+++ /dev/null
@@ -1,119 +0,0 @@
-# frozen_string_literal: false
-require_relative '../taxonomy'
-require_relative '1.0'
-require_relative 'dublincore'
-
-module RSS
- module Maker
- module TaxonomyTopicsModel
- def self.append_features(klass)
- super
-
- klass.def_classed_element("#{RSS::TAXO_PREFIX}_topics",
- "TaxonomyTopics")
- end
-
- def self.install_taxo_topics(klass)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class TaxonomyTopics < TaxonomyTopicsBase
- def to_feed(feed, current)
- if current.respond_to?(:taxo_topics)
- topics = current.class::TaxonomyTopics.new
- bag = topics.Bag
- @resources.each do |resource|
- bag.lis << RDF::Bag::Li.new(resource)
- end
- current.taxo_topics = topics
- end
- end
- end
-EOC
- end
-
- class TaxonomyTopicsBase < Base
- attr_reader :resources
- def_array_element("resource")
- remove_method :new_resource
- end
- end
-
- module TaxonomyTopicModel
- def self.append_features(klass)
- super
-
- class_name = "TaxonomyTopics"
- klass.def_classed_elements("#{TAXO_PREFIX}_topic", "value", class_name)
- end
-
- def self.install_taxo_topic(klass)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class TaxonomyTopics < TaxonomyTopicsBase
- class TaxonomyTopic < TaxonomyTopicBase
- DublinCoreModel.install_dublin_core(self)
- TaxonomyTopicsModel.install_taxo_topics(self)
-
- def to_feed(feed, current)
- if current.respond_to?(:taxo_topics)
- topic = current.class::TaxonomyTopic.new(value)
- topic.taxo_link = value
- taxo_topics.to_feed(feed, topic) if taxo_topics
- current.taxo_topics << topic
- setup_other_elements(feed, topic)
- end
- end
- end
- end
-EOC
- end
-
- class TaxonomyTopicsBase < Base
- def_array_element("topic", nil, "TaxonomyTopic")
- alias_method(:new_taxo_topic, :new_topic) # For backward compatibility
-
- class TaxonomyTopicBase < Base
- include DublinCoreModel
- include TaxonomyTopicsModel
-
- attr_accessor :value
- add_need_initialize_variable("value")
- alias_method(:taxo_link, :value)
- alias_method(:taxo_link=, :value=)
-
- def have_required_values?
- @value
- end
- end
- end
- end
-
- class RSSBase
- include TaxonomyTopicModel
- end
-
- class ChannelBase
- include TaxonomyTopicsModel
- end
-
- class ItemsBase
- class ItemBase
- include TaxonomyTopicsModel
- end
- end
-
- makers.each do |maker|
- maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- TaxonomyTopicModel.install_taxo_topic(self)
-
- class Channel
- TaxonomyTopicsModel.install_taxo_topics(self)
- end
-
- class Items
- class Item
- TaxonomyTopicsModel.install_taxo_topics(self)
- end
- end
- EOC
- end
- end
-end
diff --git a/lib/rss/maker/trackback.rb b/lib/rss/maker/trackback.rb
deleted file mode 100644
index f78b4058f93..00000000000
--- a/lib/rss/maker/trackback.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-# frozen_string_literal: false
-require_relative '../trackback'
-require_relative '1.0'
-require_relative '2.0'
-
-module RSS
- module Maker
- module TrackBackModel
- def self.append_features(klass)
- super
-
- klass.def_other_element("#{RSS::TRACKBACK_PREFIX}_ping")
- klass.def_classed_elements("#{RSS::TRACKBACK_PREFIX}_about", "value",
- "TrackBackAbouts")
- end
-
- class TrackBackAboutsBase < Base
- def_array_element("about", nil, "TrackBackAbout")
-
- class TrackBackAboutBase < Base
- attr_accessor :value
- add_need_initialize_variable("value")
-
- alias_method(:resource, :value)
- alias_method(:resource=, :value=)
- alias_method(:content, :value)
- alias_method(:content=, :value=)
-
- def have_required_values?
- @value
- end
-
- def to_feed(feed, current)
- if current.respond_to?(:trackback_abouts) and have_required_values?
- about = current.class::TrackBackAbout.new
- setup_values(about)
- setup_other_elements(about)
- current.trackback_abouts << about
- end
- end
- end
- end
- end
-
- class ItemsBase
- class ItemBase; include TrackBackModel; end
- end
-
- makers.each do |maker|
- maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class Items
- class Item
- class TrackBackAbouts < TrackBackAboutsBase
- class TrackBackAbout < TrackBackAboutBase
- end
- end
- end
- end
- EOC
- end
- end
-end
diff --git a/lib/rss/parser.rb b/lib/rss/parser.rb
deleted file mode 100644
index e1bcfc53e34..00000000000
--- a/lib/rss/parser.rb
+++ /dev/null
@@ -1,589 +0,0 @@
-# frozen_string_literal: false
-require "forwardable"
-require "open-uri"
-
-require_relative "rss"
-require_relative "xml"
-
-module RSS
-
- class NotWellFormedError < Error
- attr_reader :line, :element
-
- # Create a new NotWellFormedError for an error at +line+
- # in +element+. If a block is given the return value of
- # the block ends up in the error message.
- 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 was not found in " <<
- "#{AVAILABLE_PARSER_LIBRARIES.inspect}.")
- end
- end
-
- class NotValidXMLParser < Error
- def initialize(parser)
- super("#{parser} is not an available XML parser. " <<
- "Available XML parser" <<
- (AVAILABLE_PARSERS.size > 1 ? "s are " : " 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
-
- # Set @@default_parser to new_value if it is one of the
- # available parsers. Else raise NotValidXMLParser error.
- 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, *args)
- if args.last.is_a?(Hash)
- options = args.pop
- else
- options = {}
- end
- do_validate = boolean_argument(args[0], options[:validate], true)
- ignore_unknown_element =
- boolean_argument(args[1], options[:ignore_unknown_element], true)
- parser_class = args[2] || options[:parser_class] || default_parser
- parser = new(rss, parser_class)
- parser.do_validate = do_validate
- parser.ignore_unknown_element = ignore_unknown_element
- parser.parse
- end
-
- private
- def boolean_argument(positioned_value, option_value, default)
- value = positioned_value
- if value.nil? and not option_value.nil?
- value = option_value
- end
- value = default if value.nil?
- value
- 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(normalize_rss(rss))
- end
-
- private
-
- # Try to get the XML associated with +rss+.
- # Return +rss+ if it already looks like XML, or treat it as a URI,
- # or a file to get the XML,
- def normalize_rss(rss)
- return rss if maybe_xml?(rss)
-
- uri = to_uri(rss)
-
- if uri.respond_to?(:read)
- uri.read
- elsif (RUBY_VERSION >= '2.7' || !rss.tainted?) and File.readable?(rss)
- File.open(rss) {|f| f.read}
- else
- rss
- end
- end
-
- # maybe_xml? tests if source is a string that looks like XML.
- def maybe_xml?(source)
- source.is_a?(String) and /</ =~ source
- end
-
- # Attempt to convert rss to a URI, but just return it if
- # there's a ::URI::Error
- def to_uri(rss)
- return rss if rss.is_a?(::URI::Generic)
-
- begin
- ::URI.parse(rss)
- rescue ::URI::Error
- rss
- end
- end
- end
-
- class BaseParser
-
- class << self
- def raise_for_undefined_entity?
- listener.raise_for_undefined_entity?
- end
- end
-
- def initialize(rss)
- @listener = self.class.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
-
- @@accessor_bases = {}
- @@registered_uris = {}
- @@class_names = {}
-
- # return the setter for the uri, tag_name pair, or nil.
- def setter(uri, tag_name)
- _getter = getter(uri, tag_name)
- if _getter
- "#{_getter}="
- else
- nil
- end
- end
-
- def getter(uri, tag_name)
- (@@accessor_bases[uri] || {})[tag_name]
- end
-
- # return the tag_names for setters associated with uri
- def available_tags(uri)
- (@@accessor_bases[uri] || {}).keys
- end
-
- # register uri against this name.
- def register_uri(uri, name)
- @@registered_uris[name] ||= {}
- @@registered_uris[name][uri] = nil
- end
-
- # test if this uri is registered against this name
- def uri_registered?(uri, name)
- @@registered_uris[name].has_key?(uri)
- end
-
- # record class_name for the supplied uri and tag_name
- def install_class_name(uri, tag_name, class_name)
- @@class_names[uri] ||= {}
- @@class_names[uri][tag_name] = class_name
- end
-
- # retrieve class_name for the supplied uri and tag_name
- # If it doesn't exist, capitalize the tag_name
- def class_name(uri, tag_name)
- name = (@@class_names[uri] || {})[tag_name]
- return name if name
-
- tag_name = tag_name.gsub(/[_\-]([a-z]?)/) {$1.upcase}
- tag_name[0, 1].upcase + tag_name[1..-1]
- end
-
- def install_get_text_element(uri, name, accessor_base)
- install_accessor_base(uri, name, accessor_base)
- def_get_text_element(uri, name, *get_file_and_line_from_caller(1))
- end
-
- def raise_for_undefined_entity?
- true
- end
-
- private
- # set the accessor for the uri, tag_name pair
- def install_accessor_base(uri, tag_name, accessor_base)
- @@accessor_bases[uri] ||= {}
- @@accessor_bases[uri][tag_name] = accessor_base.chomp("=")
- end
-
- def def_get_text_element(uri, element_name, file, line)
- register_uri(uri, element_name)
- method_name = "start_#{element_name}"
- unless private_method_defined?(method_name)
- define_method(method_name) do |name, prefix, attrs, ns|
- uri = _ns(ns, prefix)
- if self.class.uri_registered?(uri, element_name)
- start_get_text_element(name, prefix, ns, uri)
- else
- start_else_element(name, prefix, attrs, ns)
- end
- end
- private(method_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 = [{"xml" => :xml}]
- @tag_stack = [[]]
- @text_stack = ['']
- @proc_stack = []
- @last_element = nil
- @version = @encoding = @standalone = nil
- @xml_stylesheets = []
- @xml_child_mode = false
- @xml_element = nil
- @last_xml_element = nil
- end
-
- # set instance vars for version, encoding, standalone
- 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 /\Axmlns(?:\z|:)/ =~ n
- ns[$POSTMATCH] = v
- else
- attrs[n] = v
- end
- end
- @ns_stack.push(ns)
-
- prefix, local = split_name(name)
- @tag_stack.last.push([_ns(ns, prefix), local])
- @tag_stack.push([])
- if @xml_child_mode
- previous = @last_xml_element
- element_attrs = attributes.dup
- unless previous
- ns.each do |ns_prefix, value|
- next if ns_prefix == "xml"
- key = ns_prefix.empty? ? "xmlns" : "xmlns:#{ns_prefix}"
- element_attrs[key] ||= value
- end
- end
- next_element = XML::Element.new(local,
- prefix.empty? ? nil : prefix,
- _ns(ns, prefix),
- element_attrs)
- previous << next_element if previous
- @last_xml_element = next_element
- pr = Proc.new do |text, tags|
- if previous
- @last_xml_element = previous
- else
- @xml_element = @last_xml_element
- @last_xml_element = nil
- end
- end
- @proc_stack.push(pr)
- else
- if @rss.nil? and respond_to?("initial_start_#{local}", true)
- __send__("initial_start_#{local}", local, prefix, attrs, ns.dup)
- elsif respond_to?("start_#{local}", true)
- __send__("start_#{local}", local, prefix, attrs, ns.dup)
- else
- start_else_element(local, prefix, attrs, ns.dup)
- end
- 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?
- @ns_stack.pop
- end
-
- def text(data)
- if @xml_child_mode
- @last_xml_element << data if @last_xml_element
- else
- @text_stack.last << data
- end
- end
-
- private
- def _ns(ns, prefix)
- ns.fetch(prefix, "")
- end
-
- CONTENT_PATTERN = /\s*([^=]+)=(["'])([^\2]+?)\2/
- # Extract the first name="value" pair from content.
- # Works with single quotes according to the constant
- # CONTENT_PATTERN. Return a Hash.
- 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 = self.class.class_name(_ns(ns, prefix), local)
- current_class = @last_element.class
- if known_class?(current_class, class_name)
- next_class = current_class.const_get(class_name)
- start_have_something_element(local, prefix, attrs, ns, next_class)
- else
- if !@do_validate or @ignore_unknown_element
- @proc_stack.push(setup_next_element_in_unknown_element)
- else
- parent = "ROOT ELEMENT???"
- if current_class.tag_name
- parent = current_class.tag_name
- end
- raise NotExpectedTagError.new(local, _ns(ns, prefix), parent)
- end
- end
- end
-
- if Module.method(:const_defined?).arity == -1
- def known_class?(target_class, class_name)
- class_name and
- (target_class.const_defined?(class_name, false) or
- target_class.constants.include?(class_name.to_sym))
- end
- else
- def known_class?(target_class, class_name)
- class_name and
- (target_class.const_defined?(class_name) or
- target_class.constants.include?(class_name))
- end
- end
-
- NAMESPLIT = /^(?:([\w:][-\w.]*):)?([\w:][-\w.]*)/
- def split_name(name)
- name =~ NAMESPLIT
- [$1 || '', $2]
- end
-
- def check_ns(tag_name, prefix, ns, require_uri, ignore_unknown_element=nil)
- if _ns(ns, prefix) == require_uri
- true
- else
- if ignore_unknown_element.nil?
- ignore_unknown_element = @ignore_unknown_element
- end
-
- if ignore_unknown_element
- false
- elsif @do_validate
- raise NSError.new(tag_name, prefix, require_uri)
- else
- # Force bind required URI with prefix
- @ns_stack.last[prefix] = require_uri
- true
- end
- end
- end
-
- def start_get_text_element(tag_name, prefix, ns, required_uri)
- pr = Proc.new do |text, tags|
- setter = self.class.setter(required_uri, tag_name)
- if setter and @last_element.respond_to?(setter)
- if @do_validate
- getter = self.class.getter(required_uri, tag_name)
- if @last_element.__send__(getter)
- raise TooMuchTagError.new(tag_name, @last_element.tag_name)
- end
- end
- @last_element.__send__(setter, text.to_s)
- else
- if @do_validate and !@ignore_unknown_element
- raise NotExpectedTagError.new(tag_name, _ns(ns, prefix),
- @last_element.tag_name)
- end
- end
- end
- @proc_stack.push(pr)
- end
-
- def start_have_something_element(tag_name, prefix, attrs, ns, klass)
- if check_ns(tag_name, prefix, ns, klass.required_uri)
- attributes = collect_attributes(tag_name, prefix, attrs, ns, klass)
- @proc_stack.push(setup_next_element(tag_name, klass, attributes))
- else
- @proc_stack.push(setup_next_element_in_unknown_element)
- end
- end
-
- def collect_attributes(tag_name, prefix, attrs, ns, klass)
- attributes = {}
- klass.get_attributes.each do |a_name, a_uri, required, element_name|
- if a_uri.is_a?(String) or !a_uri.respond_to?(:include?)
- a_uri = [a_uri]
- end
- unless a_uri == [""]
- 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?("")
- val = attrs[a_name]
- end
-
- if @do_validate and required and val.nil?
- unless a_uri.include?("")
- for prefix, uri in ns
- if a_uri.include?(uri)
- a_name = "#{prefix}:#{a_name}"
- end
- end
- end
- raise MissingAttributeError.new(tag_name, a_name)
- end
-
- attributes[a_name] = val
- end
- attributes
- end
-
- def setup_next_element(tag_name, klass, attributes)
- previous = @last_element
- next_element = klass.new(@do_validate, attributes)
- previous.set_next_element(tag_name, next_element)
- @last_element = next_element
- @last_element.parent = previous if klass.need_parent?
- @xml_child_mode = @last_element.have_xml_content?
-
- Proc.new do |text, tags|
- p(@last_element.class) if DEBUG
- if @xml_child_mode
- @last_element.content = @xml_element.to_s
- xml_setter = @last_element.class.xml_setter
- @last_element.__send__(xml_setter, @xml_element)
- @xml_element = nil
- @xml_child_mode = false
- else
- if klass.have_content?
- if @last_element.need_base64_encode?
- text = text.lstrip.unpack("m").first
- end
- @last_element.content = text
- end
- end
- if @do_validate
- @last_element.validate_for_stream(tags, @ignore_unknown_element)
- end
- @last_element = previous
- end
- end
-
- def setup_next_element_in_unknown_element
- current_element, @last_element = @last_element, nil
- Proc.new {@last_element = current_element}
- end
- end
-
- unless const_defined? :AVAILABLE_PARSER_LIBRARIES
- # The list of all available libraries for parsing.
- AVAILABLE_PARSER_LIBRARIES = [
- ["rss/xmlparser", :XMLParserParser],
- ["rss/xmlscanner", :XMLScanParser],
- ["rss/rexmlparser", :REXMLParser],
- ]
- end
-
- # The list of all available parsers, in constant form.
- 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
deleted file mode 100644
index ef0595e447f..00000000000
--- a/lib/rss/rexmlparser.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-# frozen_string_literal: false
-require "rexml/document"
-require "rexml/streamlistener"
-
-module RSS
-
- class REXMLParser < BaseParser
-
- class << self
- def listener
- REXMLListener
- end
- end
-
- private
- 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
-
- class << self
- def raise_for_undefined_entity?
- false
- end
- end
-
- def xmldecl(version, encoding, standalone)
- super(version, encoding, standalone == "yes")
- # 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.gemspec b/lib/rss/rss.gemspec
deleted file mode 100644
index 04f2b2f42d7..00000000000
--- a/lib/rss/rss.gemspec
+++ /dev/null
@@ -1,80 +0,0 @@
-begin
- require_relative "lib/rss/version"
-rescue LoadError
- # for Ruby core repository
- require_relative "version"
-end
-
-Gem::Specification.new do |spec|
- spec.name = "rss"
- spec.version = RSS::VERSION
- spec.authors = ["Kouhei Sutou"]
- spec.email = ["kou@cozmixng.org"]
-
- spec.summary = %q{Family of libraries that support various formats of XML "feeds".}
- spec.description = %q{Family of libraries that support various formats of XML "feeds".}
- spec.homepage = "https://github.com/ruby/rss"
- spec.license = "BSD-2-Clause"
-
- spec.files = [
- ".gitignore",
- ".travis.yml",
- "Gemfile",
- "LICENSE.txt",
- "NEWS.md",
- "README.md",
- "Rakefile",
- "lib/rss.rb",
- "lib/rss/0.9.rb",
- "lib/rss/1.0.rb",
- "lib/rss/2.0.rb",
- "lib/rss/atom.rb",
- "lib/rss/content.rb",
- "lib/rss/content/1.0.rb",
- "lib/rss/content/2.0.rb",
- "lib/rss/converter.rb",
- "lib/rss/dublincore.rb",
- "lib/rss/dublincore/1.0.rb",
- "lib/rss/dublincore/2.0.rb",
- "lib/rss/dublincore/atom.rb",
- "lib/rss/image.rb",
- "lib/rss/itunes.rb",
- "lib/rss/maker.rb",
- "lib/rss/maker/0.9.rb",
- "lib/rss/maker/1.0.rb",
- "lib/rss/maker/2.0.rb",
- "lib/rss/maker/atom.rb",
- "lib/rss/maker/base.rb",
- "lib/rss/maker/content.rb",
- "lib/rss/maker/dublincore.rb",
- "lib/rss/maker/entry.rb",
- "lib/rss/maker/feed.rb",
- "lib/rss/maker/image.rb",
- "lib/rss/maker/itunes.rb",
- "lib/rss/maker/slash.rb",
- "lib/rss/maker/syndication.rb",
- "lib/rss/maker/taxonomy.rb",
- "lib/rss/maker/trackback.rb",
- "lib/rss/parser.rb",
- "lib/rss/rexmlparser.rb",
- "lib/rss/rss.rb",
- "lib/rss/slash.rb",
- "lib/rss/syndication.rb",
- "lib/rss/taxonomy.rb",
- "lib/rss/trackback.rb",
- "lib/rss/utils.rb",
- "lib/rss/version.rb",
- "lib/rss/xml-stylesheet.rb",
- "lib/rss/xml.rb",
- "lib/rss/xmlparser.rb",
- "lib/rss/xmlscanner.rb",
- "rss.gemspec",
- ]
- spec.bindir = "exe"
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
- spec.require_paths = ["lib"]
-
- spec.add_development_dependency "bundler"
- spec.add_development_dependency "rake"
- spec.add_development_dependency "test-unit"
-end
diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb
deleted file mode 100644
index daa0837e9c1..00000000000
--- a/lib/rss/rss.rb
+++ /dev/null
@@ -1,1342 +0,0 @@
-# frozen_string_literal: false
-require "time"
-
-class Time
- class << self
- unless respond_to?(:w3cdtf)
- # This method converts a W3CDTF string date/time format to Time object.
- #
- # The W3CDTF format is defined here: http://www.w3.org/TR/NOTE-datetime
- #
- # Time.w3cdtf('2003-02-15T13:50:05-05:00')
- # # => 2003-02-15 10:50:05 -0800
- # Time.w3cdtf('2003-02-15T13:50:05-05:00').class
- # # => Time
- 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]
- usec = 0
- usec = $7.to_f * 1000000 if $7
- zone = $8
- if zone
- off = zone_offset(zone, datetime[0])
- datetime = apply_offset(*(datetime + [off]))
- datetime << usec
- time = Time.utc(*datetime)
- force_zone!(time, zone, off)
- time
- else
- datetime << usec
- Time.local(*datetime)
- end
- else
- raise ArgumentError.new("invalid date: #{date.inspect}")
- end
- end
- end
- end
-
- unless method_defined?(:w3cdtf)
- # This method converts a Time object to a String. The String contains the
- # time in W3CDTF date/time format.
- #
- # The W3CDTF format is defined here: http://www.w3.org/TR/NOTE-datetime
- #
- # Time.now.w3cdtf
- # # => "2013-08-26T14:12:10.817124-07:00"
- def w3cdtf
- if usec.zero?
- fraction_digits = 0
- else
- fraction_digits = strftime('%6N').index(/0*\z/)
- end
- xmlschema(fraction_digits)
- end
- end
-end
-
-
-require "English"
-require_relative "utils"
-require_relative "converter"
-require_relative "xml-stylesheet"
-
-module RSS
- # The URI of the RSS 1.0 specification
- URI = "http://purl.org/rss/1.0/"
-
- DEBUG = false # :nodoc:
-
- # The basic error all other RSS errors stem from. Rescue this error if you
- # want to handle any given RSS error and you don't care about the details.
- class Error < StandardError; end
-
- # RSS, being an XML-based format, has namespace support. If two namespaces are
- # declared with the same name, an OverlappedPrefixError will be raised.
- class OverlappedPrefixError < Error
- attr_reader :prefix
- def initialize(prefix)
- @prefix = prefix
- end
- end
-
- # The InvalidRSSError error is the base class for a variety of errors
- # related to a poorly-formed RSS feed. Rescue this error if you only
- # care that a file could be invalid, but don't care how it is invalid.
- class InvalidRSSError < Error; end
-
- # Since RSS is based on XML, it must have opening and closing tags that
- # match. If they don't, a MissingTagError will be raised.
- 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
-
- # Some tags must only exist a specific number of times in a given RSS feed.
- # If a feed has too many occurrences of one of these tags, a TooMuchTagError
- # will be raised.
- 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
-
- # Certain attributes are required on specific tags in an RSS feed. If a feed
- # is missing one of these attributes, a MissingAttributeError is raised.
- 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
-
- # RSS does not allow for free-form tag names, so if an RSS feed contains a
- # tag that we don't know about, an UnknownTagError is raised.
- 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
-
- # Raised when an unexpected tag is encountered.
- class NotExpectedTagError < InvalidRSSError
- attr_reader :tag, :uri, :parent
- def initialize(tag, uri, parent)
- @tag, @uri, @parent = tag, uri, parent
- super("tag <{#{uri}}#{tag}> is not expected in tag <#{parent}>")
- end
- end
- # For backward compatibility :X
- NotExceptedTagError = NotExpectedTagError # :nodoc:
-
- # Attributes are in key-value form, and if there's no value provided for an
- # attribute, a NotAvailableValueError will be raised.
- class NotAvailableValueError < InvalidRSSError
- attr_reader :tag, :value, :attribute
- def initialize(tag, value, attribute=nil)
- @tag, @value, @attribute = tag, value, attribute
- message = "value <#{value}> of "
- message << "attribute <#{attribute}> of " if attribute
- message << "tag <#{tag}> is not available."
- super(message)
- end
- end
-
- # Raised when an unknown conversion error occurs.
- 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 # :nodoc:
-
- # Raised when a conversion failure occurs.
- 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
-
- # Raised when a required variable is not set.
- class NotSetError < Error
- attr_reader :name, :variables
- def initialize(name, variables)
- @name = name
- @variables = variables
- super("required variables of #{@name} are not set: #{@variables.join(', ')}")
- end
- end
-
- # Raised when a RSS::Maker attempts to use an unknown maker.
- class UnsupportedMakerVersionError < Error
- attr_reader :version
- def initialize(version)
- @version = version
- super("Maker doesn't support version: #{@version}")
- end
- end
-
- module BaseModel
- include Utils
-
- def install_have_child_element(tag_name, uri, occurs, name=nil, type=nil)
- name ||= tag_name
- add_need_initialize_variable(name)
- install_model(tag_name, uri, occurs, name)
-
- writer_type, reader_type = type
- def_corresponded_attr_writer name, writer_type
- def_corresponded_attr_reader name, reader_type
- install_element(name) do |n, elem_name|
- <<-EOC
- if @#{n}
- "\#{@#{n}.to_s(need_convert, indent)}"
- else
- ''
- end
-EOC
- end
- end
- alias_method(:install_have_attribute_element, :install_have_child_element)
-
- def install_have_children_element(tag_name, uri, occurs, name=nil, plural_name=nil)
- name ||= tag_name
- plural_name ||= "#{name}s"
- add_have_children_element(name, plural_name)
- add_plural_form(name, plural_name)
- install_model(tag_name, uri, occurs, plural_name, true)
-
- def_children_accessor(name, plural_name)
- install_element(name, "s") do |n, elem_name|
- <<-EOC
- rv = []
- @#{n}.each do |x|
- value = "\#{x.to_s(need_convert, indent)}"
- rv << value if /\\A\\s*\\z/ !~ value
- end
- rv.join("\n")
-EOC
- end
- end
-
- def install_text_element(tag_name, uri, occurs, name=nil, type=nil,
- disp_name=nil)
- name ||= tag_name
- disp_name ||= name
- self::ELEMENTS << name unless self::ELEMENTS.include?(name)
- add_need_initialize_variable(name)
- install_model(tag_name, uri, occurs, name)
-
- def_corresponded_attr_writer(name, type, disp_name)
- def_corresponded_attr_reader(name, type || :convert)
- install_element(name) do |n, elem_name|
- <<-EOC
- if respond_to?(:#{n}_content)
- content = #{n}_content
- else
- content = @#{n}
- end
- if content
- rv = "\#{indent}<#{elem_name}>"
- value = html_escape(content)
- if need_convert
- rv << convert(value)
- else
- rv << value
- end
- rv << "</#{elem_name}>"
- rv
- else
- ''
- end
-EOC
- end
- end
-
- def install_date_element(tag_name, uri, occurs, name=nil, type=nil, disp_name=nil)
- name ||= tag_name
- type ||= :w3cdtf
- disp_name ||= name
- self::ELEMENTS << name
- add_need_initialize_variable(name)
- install_model(tag_name, uri, occurs, name)
-
- # accessor
- convert_attr_reader name
- date_writer(name, type, disp_name)
-
- install_element(name) do |n, elem_name|
- <<-EOC
- if @#{n}
- rv = "\#{indent}<#{elem_name}>"
- value = html_escape(@#{n}.#{type})
- if need_convert
- rv << 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('_', ':')
- method_name = "#{name}_element#{postfix}"
- add_to_element_method(method_name)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{method_name}(need_convert=true, indent='')
- #{yield(name, elem_name)}
- end
- private :#{method_name}
-EOC
- end
-
- def inherit_convert_attr_reader(*attrs)
- attrs.each do |attr|
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{attr}_without_inherit
- convert(@#{attr})
- end
-
- def #{attr}
- if @#{attr}
- #{attr}_without_inherit
- elsif @parent
- @parent.#{attr}
- else
- nil
- end
- end
-EOC
- end
- end
-
- def uri_convert_attr_reader(*attrs)
- attrs.each do |attr|
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{attr}_without_base
- convert(@#{attr})
- end
-
- def #{attr}
- value = #{attr}_without_base
- return nil if value.nil?
- if /\\A[a-z][a-z0-9+.\\-]*:/i =~ value
- value
- else
- "\#{base}\#{value}"
- end
- end
-EOC
- end
- end
-
- def convert_attr_reader(*attrs)
- attrs.each do |attr|
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{attr}
- convert(@#{attr})
- end
-EOC
- end
- end
-
- def explicit_clean_other_attr_reader(*attrs)
- attrs.each do |attr|
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- attr_reader(:#{attr})
- def #{attr}?
- ExplicitCleanOther.parse(@#{attr})
- end
- EOC
- end
- end
-
- def yes_other_attr_reader(*attrs)
- attrs.each do |attr|
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- attr_reader(:#{attr})
- def #{attr}?
- Utils::YesOther.parse(@#{attr})
- end
- EOC
- end
- end
-
- def csv_attr_reader(*attrs)
- separator = nil
- if attrs.last.is_a?(Hash)
- options = attrs.pop
- separator = options[:separator]
- end
- separator ||= ", "
- attrs.each do |attr|
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- attr_reader(:#{attr})
- def #{attr}_content
- if @#{attr}.nil?
- @#{attr}
- else
- @#{attr}.join(#{separator.dump})
- end
- end
- EOC
- end
- end
-
- def date_writer(name, type, disp_name=name)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{name}=(new_value)
- if new_value.nil?
- @#{name} = new_value
- elsif new_value.kind_of?(Time)
- @#{name} = new_value.dup
- 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
- unless Date._parse(new_value, false).empty?
- @#{name} = Time.parse(new_value)
- end
- rescue ArgumentError
- end
- end
- end
- end
-
- # Is it need?
- if @#{name}
- class << @#{name}
- undef_method(:to_s)
- alias_method(:to_s, :#{type})
- end
- end
-
- end
-EOC
- end
-
- def integer_writer(name, disp_name=name)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{name}=(new_value)
- if new_value.nil?
- @#{name} = new_value
- else
- if @do_validate
- begin
- @#{name} = Integer(new_value)
- rescue ArgumentError
- raise NotAvailableValueError.new('#{disp_name}', new_value)
- end
- else
- @#{name} = new_value.to_i
- end
- end
- end
-EOC
- end
-
- def positive_integer_writer(name, disp_name=name)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{name}=(new_value)
- if new_value.nil?
- @#{name} = new_value
- else
- if @do_validate
- begin
- tmp = Integer(new_value)
- raise ArgumentError if tmp <= 0
- @#{name} = tmp
- rescue ArgumentError
- raise NotAvailableValueError.new('#{disp_name}', new_value)
- end
- else
- @#{name} = new_value.to_i
- end
- end
- end
-EOC
- end
-
- def boolean_writer(name, disp_name=name)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{name}=(new_value)
- if new_value.nil?
- @#{name} = new_value
- else
- if @do_validate and
- ![true, false, "true", "false"].include?(new_value)
- raise NotAvailableValueError.new('#{disp_name}', new_value)
- end
- if [true, false].include?(new_value)
- @#{name} = new_value
- else
- @#{name} = new_value == "true"
- end
- end
- end
-EOC
- end
-
- def text_type_writer(name, disp_name=name)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{name}=(new_value)
- if @do_validate and
- !["text", "html", "xhtml", nil].include?(new_value)
- raise NotAvailableValueError.new('#{disp_name}', new_value)
- end
- @#{name} = new_value
- end
-EOC
- end
-
- def content_writer(name, disp_name=name)
- klass_name = "self.class::#{Utils.to_class_name(name)}"
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{name}=(new_value)
- if new_value.is_a?(#{klass_name})
- @#{name} = new_value
- else
- @#{name} = #{klass_name}.new
- @#{name}.content = new_value
- end
- end
-EOC
- end
-
- def explicit_clean_other_writer(name, disp_name=name)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}=(value)
- value = (value ? "yes" : "no") if [true, false].include?(value)
- @#{name} = value
- end
- EOC
- end
-
- def yes_other_writer(name, disp_name=name)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}=(new_value)
- if [true, false].include?(new_value)
- new_value = new_value ? "yes" : "no"
- end
- @#{name} = new_value
- end
- EOC
- end
-
- def csv_writer(name, disp_name=name)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}=(new_value)
- @#{name} = Utils::CSV.parse(new_value)
- end
- EOC
- end
-
- def csv_integer_writer(name, disp_name=name)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}=(new_value)
- @#{name} = Utils::CSV.parse(new_value) {|v| Integer(v)}
- end
- EOC
- end
-
- def def_children_accessor(accessor_name, plural_name)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{plural_name}
- @#{accessor_name}
- end
-
- def #{accessor_name}(*args)
- if args.empty?
- @#{accessor_name}.first
- else
- @#{accessor_name}[*args]
- end
- end
-
- def #{accessor_name}=(*args)
- receiver = self.class.name
- warn("Don't use `\#{receiver}\##{accessor_name} = XXX'/" \
- "`\#{receiver}\#set_#{accessor_name}(XXX)'. " \
- "Those APIs are not sense of Ruby. " \
- "Use `\#{receiver}\##{plural_name} << XXX' instead of them.", uplevel: 1)
- 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
-
- module SetupMaker
- def setup_maker(maker)
- target = maker_target(maker)
- unless target.nil?
- setup_maker_attributes(target)
- setup_maker_element(target)
- setup_maker_elements(target)
- end
- end
-
- private
- def maker_target(maker)
- nil
- end
-
- def setup_maker_attributes(target)
- end
-
- def setup_maker_element(target)
- self.class.need_initialize_variables.each do |var|
- value = __send__(var)
- next if value.nil?
- if value.respond_to?("setup_maker") and
- !not_need_to_call_setup_maker_variables.include?(var)
- value.setup_maker(target)
- else
- setter = "#{var}="
- if target.respond_to?(setter)
- target.__send__(setter, value)
- end
- end
- end
- end
-
- def not_need_to_call_setup_maker_variables
- []
- end
-
- def setup_maker_elements(parent)
- self.class.have_children_elements.each do |name, plural_name|
- if parent.respond_to?(plural_name)
- target = parent.__send__(plural_name)
- __send__(plural_name).each do |elem|
- elem.setup_maker(target)
- end
- end
- end
- end
- end
-
- class Element
- extend BaseModel
- include Utils
- extend Utils::InheritedReader
- include SetupMaker
-
- INDENT = " "
-
- MUST_CALL_VALIDATORS = {}
- MODELS = []
- GET_ATTRIBUTES = []
- HAVE_CHILDREN_ELEMENTS = []
- TO_ELEMENT_METHODS = []
- NEED_INITIALIZE_VARIABLES = []
- PLURAL_FORMS = {}
-
- class << self
- def must_call_validators
- inherited_hash_reader("MUST_CALL_VALIDATORS")
- end
- def models
- inherited_array_reader("MODELS")
- end
- def get_attributes
- inherited_array_reader("GET_ATTRIBUTES")
- end
- def have_children_elements
- inherited_array_reader("HAVE_CHILDREN_ELEMENTS")
- end
- def to_element_methods
- inherited_array_reader("TO_ELEMENT_METHODS")
- end
- def need_initialize_variables
- inherited_array_reader("NEED_INITIALIZE_VARIABLES")
- end
- def plural_forms
- inherited_hash_reader("PLURAL_FORMS")
- end
-
- def inherited_base
- ::RSS::Element
- end
-
- def inherited(klass)
- klass.const_set(:MUST_CALL_VALIDATORS, {})
- klass.const_set(:MODELS, [])
- klass.const_set(:GET_ATTRIBUTES, [])
- klass.const_set(:HAVE_CHILDREN_ELEMENTS, [])
- klass.const_set(:TO_ELEMENT_METHODS, [])
- klass.const_set(:NEED_INITIALIZE_VARIABLES, [])
- klass.const_set(:PLURAL_FORMS, {})
-
- tag_name = klass.name.split(/::/).last
- tag_name[0, 1] = tag_name[0, 1].downcase
- klass.instance_variable_set(:@tag_name, tag_name)
- klass.instance_variable_set(:@have_content, false)
- end
-
- def install_must_call_validator(prefix, uri)
- self::MUST_CALL_VALIDATORS[uri] = prefix
- end
-
- def install_model(tag, uri, occurs=nil, getter=nil, plural=false)
- getter ||= tag
- if m = self::MODELS.find {|t, u, o, g, p| t == tag and u == uri}
- m[2] = occurs
- else
- self::MODELS << [tag, uri, occurs, getter, plural]
- end
- end
-
- def install_get_attribute(name, uri, required=true,
- type=nil, disp_name=nil,
- element_name=nil)
- disp_name ||= name
- element_name ||= name
- writer_type, reader_type = type
- def_corresponded_attr_writer name, writer_type, disp_name
- def_corresponded_attr_reader name, reader_type
- if type == :boolean and /^is/ =~ name
- alias_method "#{$POSTMATCH}?", name
- end
- self::GET_ATTRIBUTES << [name, uri, required, element_name]
- add_need_initialize_variable(disp_name)
- end
-
- def def_corresponded_attr_writer(name, type=nil, disp_name=nil)
- disp_name ||= name
- case type
- when :integer
- integer_writer name, disp_name
- when :positive_integer
- positive_integer_writer name, disp_name
- when :boolean
- boolean_writer name, disp_name
- when :w3cdtf, :rfc822, :rfc2822
- date_writer name, type, disp_name
- when :text_type
- text_type_writer name, disp_name
- when :content
- content_writer name, disp_name
- when :explicit_clean_other
- explicit_clean_other_writer name, disp_name
- when :yes_other
- yes_other_writer name, disp_name
- when :csv
- csv_writer name
- when :csv_integer
- csv_integer_writer name
- else
- attr_writer name
- end
- end
-
- def def_corresponded_attr_reader(name, type=nil)
- case type
- when :inherit
- inherit_convert_attr_reader name
- when :uri
- uri_convert_attr_reader name
- when :explicit_clean_other
- explicit_clean_other_attr_reader name
- when :yes_other
- yes_other_attr_reader name
- when :csv
- csv_attr_reader name
- when :csv_integer
- csv_attr_reader name, :separator => ","
- else
- convert_attr_reader name
- end
- end
-
- def content_setup(type=nil, disp_name=nil)
- writer_type, reader_type = type
- def_corresponded_attr_writer :content, writer_type, disp_name
- def_corresponded_attr_reader :content, reader_type
- @have_content = true
- end
-
- def have_content?
- @have_content
- end
-
- def add_have_children_element(variable_name, plural_name)
- self::HAVE_CHILDREN_ELEMENTS << [variable_name, plural_name]
- end
-
- def add_to_element_method(method_name)
- self::TO_ELEMENT_METHODS << method_name
- end
-
- def add_need_initialize_variable(variable_name)
- self::NEED_INITIALIZE_VARIABLES << variable_name
- end
-
- def add_plural_form(singular, plural)
- self::PLURAL_FORMS[singular] = plural
- end
-
- def required_prefix
- nil
- end
-
- def required_uri
- ""
- end
-
- def need_parent?
- false
- 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
- end
-
- attr_accessor :parent, :do_validate
-
- def initialize(do_validate=true, attrs=nil)
- @parent = nil
- @converter = nil
- if attrs.nil? and (do_validate.is_a?(Hash) or do_validate.is_a?(Array))
- do_validate, attrs = true, do_validate
- end
- @do_validate = do_validate
- initialize_variables(attrs || {})
- end
-
- def tag_name
- self.class.tag_name
- end
-
- def full_name
- tag_name
- end
-
- def converter=(converter)
- @converter = converter
- targets = children.dup
- self.class.have_children_elements.each do |variable_name, plural_name|
- targets.concat(__send__(plural_name))
- end
- targets.each do |target|
- target.converter = converter unless target.nil?
- end
- end
-
- def convert(value)
- if @converter
- @converter.convert(value)
- else
- value
- end
- end
-
- def valid?(ignore_unknown_element=true)
- validate(ignore_unknown_element)
- true
- rescue RSS::Error
- false
- end
-
- def validate(ignore_unknown_element=true)
- do_validate = @do_validate
- @do_validate = true
- validate_attribute
- __validate(ignore_unknown_element)
- ensure
- @do_validate = do_validate
- end
-
- def validate_for_stream(tags, ignore_unknown_element=true)
- validate_attribute
- __validate(ignore_unknown_element, tags, false)
- end
-
- def to_s(need_convert=true, indent='')
- if self.class.have_content?
- return "" if !empty_content? and !content_is_set?
- rv = tag(indent) do |next_indent|
- if empty_content?
- ""
- else
- xmled_content
- end
- end
- else
- rv = tag(indent) do |next_indent|
- self.class.to_element_methods.collect do |method_name|
- __send__(method_name, false, next_indent)
- end
- end
- end
- rv = convert(rv) if need_convert
- rv
- end
-
- def have_xml_content?
- false
- end
-
- def need_base64_encode?
- false
- end
-
- def set_next_element(tag_name, next_element)
- klass = next_element.class
- prefix = ""
- prefix << "#{klass.required_prefix}_" if klass.required_prefix
- key = "#{prefix}#{tag_name.gsub(/-/, '_')}"
- if self.class.plural_forms.has_key?(key)
- ary = __send__("#{self.class.plural_forms[key]}")
- ary << next_element
- else
- __send__("#{key}=", next_element)
- end
- end
-
- protected
- def have_required_elements?
- self.class::MODELS.all? do |tag, uri, occurs, getter|
- if occurs.nil? or occurs == "+"
- child = __send__(getter)
- if child.is_a?(Array)
- children = child
- children.any? {|c| c.have_required_elements?}
- else
- not child.nil?
- end
- else
- true
- end
- end
- end
-
- private
- def initialize_variables(attrs)
- normalized_attrs = {}
- attrs.each do |key, value|
- normalized_attrs[key.to_s] = value
- end
- self.class.need_initialize_variables.each do |variable_name|
- value = normalized_attrs[variable_name.to_s]
- if value
- __send__("#{variable_name}=", value)
- else
- instance_variable_set("@#{variable_name}", nil)
- end
- end
- initialize_have_children_elements
- @content = normalized_attrs["content"] if self.class.have_content?
- end
-
- def initialize_have_children_elements
- self.class.have_children_elements.each do |variable_name, plural_name|
- instance_variable_set("@#{variable_name}", [])
- end
- end
-
- def tag(indent, additional_attrs={}, &block)
- next_indent = indent + INDENT
-
- attrs = collect_attrs
- return "" if attrs.nil?
-
- return "" unless have_required_elements?
-
- attrs.update(additional_attrs)
- start_tag = make_start_tag(indent, next_indent, attrs.dup)
-
- if block
- content = block.call(next_indent)
- else
- content = []
- end
-
- if content.is_a?(String)
- content = [content]
- start_tag << ">"
- end_tag = "</#{full_name}>"
- else
- content = content.reject{|x| x.empty?}
- if content.empty?
- return "" if attrs.empty?
- end_tag = "/>"
- else
- start_tag << ">\n"
- end_tag = "\n#{indent}</#{full_name}>"
- end
- end
-
- start_tag + content.join("\n") + end_tag
- end
-
- def make_start_tag(indent, next_indent, attrs)
- start_tag = ["#{indent}<#{full_name}"]
- unless attrs.empty?
- start_tag << attrs.collect do |key, value|
- %Q[#{h key}="#{h value}"]
- end.join("\n#{next_indent}")
- end
- start_tag.join(" ")
- end
-
- def collect_attrs
- attrs = {}
- _attrs.each do |name, required, alias_name|
- value = __send__(alias_name || name)
- return nil if required and value.nil?
- next if value.nil?
- return nil if attrs.has_key?(name)
- attrs[name] = value
- end
- attrs
- end
-
- def tag_name_with_prefix(prefix)
- "#{prefix}:#{tag_name}"
- end
-
- # For backward compatibility
- def calc_indent
- ''
- end
-
- def children
- rv = []
- self.class.models.each do |name, uri, occurs, getter|
- value = __send__(getter)
- next if value.nil?
- value = [value] unless value.is_a?(Array)
- value.each do |v|
- rv << v if v.is_a?(Element)
- end
- end
- rv
- end
-
- def _tags
- rv = []
- self.class.models.each do |name, uri, occurs, getter, plural|
- value = __send__(getter)
- next if value.nil?
- if plural and value.is_a?(Array)
- rv.concat([[uri, name]] * value.size)
- else
- rv << [uri, name]
- end
- end
- rv
- end
-
- def _attrs
- self.class.get_attributes.collect do |name, uri, required, element_name|
- [element_name, required, name]
- end
- end
-
- def __validate(ignore_unknown_element, 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
- must_call_validators.each do |uri, prefix|
- _validate(ignore_unknown_element, tags[uri], uri)
- meth = "#{prefix}_validate"
- if !prefix.empty? and respond_to?(meth, true)
- __send__(meth, ignore_unknown_element, tags[uri], uri)
- end
- end
- end
-
- def validate_attribute
- _attrs.each do |a_name, required, alias_name|
- value = instance_variable_get("@#{alias_name || a_name}")
- if required and value.nil?
- raise MissingAttributeError.new(tag_name, a_name)
- end
- __send__("#{alias_name || a_name}=", value)
- end
- end
-
- def _validate(ignore_unknown_element, tags, uri, models=self.class.models)
- count = 1
- do_redo = false
- not_shift = false
- tag = nil
- models = models.find_all {|model| model[1] == uri}
- element_names = models.collect {|model| model[0]}
- if tags
- tags_size = tags.size
- tags = tags.sort_by {|x| element_names.index(x) || tags_size}
- end
-
- models.each_with_index do |model, i|
- name, _, occurs, = model
-
- if DEBUG
- p "before"
- p tags
- p model
- end
-
- if not_shift
- not_shift = false
- elsif tags
- tag = tags.shift
- end
-
- if DEBUG
- p "mid"
- p count
- end
-
- case occurs
- when '?'
- if count > 2
- raise TooMuchTagError.new(name, tag_name)
- else
- if name == tag
- do_redo = true
- else
- not_shift = true
- end
- end
- when '*'
- if name == tag
- do_redo = true
- else
- not_shift = true
- end
- when '+'
- if name == tag
- do_redo = true
- else
- if count > 1
- not_shift = true
- else
- raise MissingTagError.new(name, tag_name)
- end
- end
- else
- if name == tag
- if models[i+1] and models[i+1][0] != name and
- tags and tags.first == name
- raise TooMuchTagError.new(name, tag_name)
- end
- else
- raise MissingTagError.new(name, 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 !ignore_unknown_element and !tags.nil? and !tags.empty?
- raise NotExpectedTagError.new(tags.first, uri, 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
-
- def empty_content?
- false
- end
-
- def content_is_set?
- if have_xml_content?
- __send__(self.class.xml_getter)
- else
- content
- end
- end
-
- def xmled_content
- if have_xml_content?
- __send__(self.class.xml_getter).to_s
- else
- _content = content
- _content = [_content].pack("m0") if need_base64_encode?
- h(_content)
- end
- end
- end
-
- module RootElementMixin
-
- include XMLStyleSheetMixin
-
- attr_reader :output_encoding
- attr_reader :feed_type, :feed_subtype, :feed_version
- attr_accessor :version, :encoding, :standalone
- def initialize(feed_version, version=nil, encoding=nil, standalone=nil)
- super()
- @feed_type = nil
- @feed_subtype = nil
- @feed_version = feed_version
- @version = version || '1.0'
- @encoding = encoding
- @standalone = standalone
- @output_encoding = nil
- end
-
- def feed_info
- [@feed_type, @feed_version, @feed_subtype]
- end
-
- def output_encoding=(enc)
- @output_encoding = enc
- self.converter = Converter.new(@output_encoding, @encoding)
- end
-
- def setup_maker(maker)
- maker.version = version
- maker.encoding = encoding
- maker.standalone = standalone
-
- xml_stylesheets.each do |xss|
- xss.setup_maker(maker)
- end
-
- super
- end
-
- def to_feed(type, &block)
- Maker.make(type) do |maker|
- setup_maker(maker)
- block.call(maker) if block
- end
- end
-
- def to_rss(type, &block)
- to_feed("rss#{type}", &block)
- end
-
- def to_atom(type, &block)
- to_feed("atom:#{type}", &block)
- end
-
- def to_xml(type=nil, &block)
- if type.nil? or same_feed_type?(type)
- to_s
- else
- to_feed(type, &block).to_s
- end
- end
-
- private
- def same_feed_type?(type)
- if /^(atom|rss)?(\d+\.\d+)?(?::(.+))?$/i =~ type
- feed_type = ($1 || @feed_type).downcase
- feed_version = $2 || @feed_version
- feed_subtype = $3 || @feed_subtype
- [feed_type, feed_version, feed_subtype] == feed_info
- else
- false
- end
- end
-
- def tag(indent, attrs={}, &block)
- rv = super(indent, ns_declarations.merge(attrs), &block)
- return rv if rv.empty?
- "#{xmldecl}#{xml_stylesheet_pi}#{rv}"
- end
-
- def xmldecl
- rv = %Q[<?xml version="#{@version}"]
- if @output_encoding or @encoding
- rv << %Q[ encoding="#{@output_encoding or @encoding}"]
- end
- rv << %Q[ standalone="yes"] if @standalone
- rv << "?>\n"
- rv
- end
-
- def ns_declarations
- decls = {}
- self.class::NSPOOL.collect do |prefix, uri|
- prefix = ":#{prefix}" unless prefix.empty?
- decls["xmlns#{prefix}"] = uri
- end
- decls
- end
-
- def maker_target(target)
- target
- end
- end
-end
diff --git a/lib/rss/slash.rb b/lib/rss/slash.rb
deleted file mode 100644
index 0055fc9f885..00000000000
--- a/lib/rss/slash.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-# frozen_string_literal: false
-require 'rss/1.0'
-
-module RSS
- # The prefix for the Slash XML namespace.
- SLASH_PREFIX = 'slash'
- # The URI of the Slash specification.
- SLASH_URI = "http://purl.org/rss/1.0/modules/slash/"
-
- RDF.install_ns(SLASH_PREFIX, SLASH_URI)
-
- module SlashModel
- extend BaseModel
-
- ELEMENT_INFOS = \
- [
- ["section"],
- ["department"],
- ["comments", :positive_integer],
- ["hit_parade", :csv_integer],
- ]
-
- class << self
- def append_features(klass)
- super
-
- return if klass.instance_of?(Module)
- klass.install_must_call_validator(SLASH_PREFIX, SLASH_URI)
- ELEMENT_INFOS.each do |name, type, *additional_infos|
- full_name = "#{SLASH_PREFIX}_#{name}"
- klass.install_text_element(full_name, SLASH_URI, "?",
- full_name, type, name)
- end
-
- klass.module_eval do
- alias_method(:slash_hit_parades, :slash_hit_parade)
- undef_method(:slash_hit_parade)
- alias_method(:slash_hit_parade, :slash_hit_parade_content)
- end
- end
- end
- end
-
- class RDF
- class Item; include SlashModel; end
- end
-
- SlashModel::ELEMENT_INFOS.each do |name, type|
- accessor_base = "#{SLASH_PREFIX}_#{name}"
- BaseListener.install_get_text_element(SLASH_URI, name, accessor_base)
- end
-end
diff --git a/lib/rss/syndication.rb b/lib/rss/syndication.rb
deleted file mode 100644
index 8f9620f9f3f..00000000000
--- a/lib/rss/syndication.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-# frozen_string_literal: false
-require "rss/1.0"
-
-module RSS
- # The prefix for the Syndication XML namespace.
- SY_PREFIX = 'sy'
- # The URI of the Syndication specification.
- SY_URI = "http://purl.org/rss/1.0/modules/syndication/"
-
- RDF.install_ns(SY_PREFIX, SY_URI)
-
- module SyndicationModel
-
- extend BaseModel
-
- ELEMENTS = []
-
- def self.append_features(klass)
- super
-
- klass.install_must_call_validator(SY_PREFIX, SY_URI)
- klass.module_eval do
- [
- ["updatePeriod"],
- ["updateFrequency", :positive_integer]
- ].each do |name, type|
- install_text_element(name, SY_URI, "?",
- "#{SY_PREFIX}_#{name}", type,
- "#{SY_PREFIX}:#{name}")
- end
-
- %w(updateBase).each do |name|
- install_date_element(name, SY_URI, "?",
- "#{SY_PREFIX}_#{name}", 'w3cdtf',
- "#{SY_PREFIX}:#{name}")
- end
- end
-
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- 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
- EOC
- end
-
- private
- SY_UPDATEPERIOD_AVAILABLE_VALUES = %w(hourly daily weekly monthly yearly)
- def validate_sy_updatePeriod(value) # :nodoc:
- unless SY_UPDATEPERIOD_AVAILABLE_VALUES.include?(value)
- raise NotAvailableValueError.new("updatePeriod", value)
- end
- end
- end
-
- class RDF
- class Channel; include SyndicationModel; end
- end
-
- prefix_size = SY_PREFIX.size + 1
- SyndicationModel::ELEMENTS.uniq!
- SyndicationModel::ELEMENTS.each do |full_name|
- name = full_name[prefix_size..-1]
- BaseListener.install_get_text_element(SY_URI, name, full_name)
- end
-
-end
diff --git a/lib/rss/taxonomy.rb b/lib/rss/taxonomy.rb
deleted file mode 100644
index 50688ee6c1f..00000000000
--- a/lib/rss/taxonomy.rb
+++ /dev/null
@@ -1,148 +0,0 @@
-# frozen_string_literal: false
-require "rss/1.0"
-require_relative "dublincore"
-
-module RSS
- # The prefix for the Taxonomy XML namespace.
- TAXO_PREFIX = "taxo"
- # The URI for the specification of the Taxonomy XML namespace.
- TAXO_URI = "http://purl.org/rss/1.0/modules/taxonomy/"
-
- RDF.install_ns(TAXO_PREFIX, TAXO_URI)
-
- # The listing of all the taxonomy elements, with the appropriate namespace.
- TAXO_ELEMENTS = []
-
- %w(link).each do |name|
- full_name = "#{TAXO_PREFIX}_#{name}"
- BaseListener.install_get_text_element(TAXO_URI, name, full_name)
- TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
- end
-
- %w(topic topics).each do |name|
- class_name = Utils.to_class_name(name)
- BaseListener.install_class_name(TAXO_URI, name, "Taxonomy#{class_name}")
- TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
- end
-
- module TaxonomyTopicsModel
- extend BaseModel
-
- def self.append_features(klass)
- super
-
- klass.install_must_call_validator(TAXO_PREFIX, TAXO_URI)
- %w(topics).each do |name|
- klass.install_have_child_element(name, TAXO_URI, "?",
- "#{TAXO_PREFIX}_#{name}")
- end
- end
-
- class TaxonomyTopics < Element
- include RSS10
-
- Bag = ::RSS::RDF::Bag
-
- class << self
- def required_prefix
- TAXO_PREFIX
- end
-
- def required_uri
- TAXO_URI
- end
- end
-
- @tag_name = "topics"
-
- install_have_child_element("Bag", RDF::URI, nil)
- install_must_call_validator('rdf', RDF::URI)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.Bag = args[0]
- end
- self.Bag ||= Bag.new
- end
-
- def full_name
- tag_name_with_prefix(TAXO_PREFIX)
- end
-
- def maker_target(target)
- target.taxo_topics
- end
-
- def resources
- if @Bag
- @Bag.lis.collect do |li|
- li.resource
- end
- else
- []
- end
- end
- end
- end
-
- module TaxonomyTopicModel
- extend BaseModel
-
- def self.append_features(klass)
- super
- var_name = "#{TAXO_PREFIX}_topic"
- klass.install_have_children_element("topic", TAXO_URI, "*", var_name)
- end
-
- class TaxonomyTopic < Element
- include RSS10
-
- include DublinCoreModel
- include TaxonomyTopicsModel
-
- class << self
- def required_prefix
- TAXO_PREFIX
- end
-
- def required_uri
- TAXO_URI
- end
- end
-
- @tag_name = "topic"
-
- install_get_attribute("about", ::RSS::RDF::URI, true, nil, nil,
- "#{RDF::PREFIX}:about")
- install_text_element("link", TAXO_URI, "?", "#{TAXO_PREFIX}_link")
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.about = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(TAXO_PREFIX)
- end
-
- def maker_target(target)
- target.new_taxo_topic
- end
- end
- end
-
- class RDF
- include TaxonomyTopicModel
- class Channel
- include TaxonomyTopicsModel
- end
- class Item; include TaxonomyTopicsModel; end
- end
-end
diff --git a/lib/rss/trackback.rb b/lib/rss/trackback.rb
deleted file mode 100644
index 1a3c3849b57..00000000000
--- a/lib/rss/trackback.rb
+++ /dev/null
@@ -1,291 +0,0 @@
-# frozen_string_literal: false
-# This file contains the implementation of trackbacks. It is entirely internal
-# and not useful to outside developers.
-require 'rss/1.0'
-require 'rss/2.0'
-
-module RSS # :nodoc: all
-
- 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 TrackBackUtils
- private
- def trackback_validate(ignore_unknown_element, tags, uri)
- return if tags.nil?
- if tags.find {|tag| tag == "about"} and
- !tags.find {|tag| tag == "ping"}
- raise MissingTagError.new("#{TRACKBACK_PREFIX}:ping", tag_name)
- end
- end
- end
-
- module BaseTrackBackModel
-
- ELEMENTS = %w(ping about)
-
- def append_features(klass)
- super
-
- unless klass.class == Module
- klass.module_eval {include TrackBackUtils}
-
- klass.install_must_call_validator(TRACKBACK_PREFIX, TRACKBACK_URI)
- %w(ping).each do |name|
- var_name = "#{TRACKBACK_PREFIX}_#{name}"
- klass_name = "TrackBack#{Utils.to_class_name(name)}"
- klass.install_have_child_element(name, TRACKBACK_URI, "?", var_name)
- klass.module_eval(<<-EOC, __FILE__, __LINE__)
- remove_method :#{var_name}
- def #{var_name}
- @#{var_name} and @#{var_name}.value
- end
-
- remove_method :#{var_name}=
- def #{var_name}=(value)
- @#{var_name} = Utils.new_with_value_if_need(#{klass_name}, value)
- end
- EOC
- end
-
- [%w(about s)].each do |name, postfix|
- var_name = "#{TRACKBACK_PREFIX}_#{name}"
- klass_name = "TrackBack#{Utils.to_class_name(name)}"
- klass.install_have_children_element(name, TRACKBACK_URI, "*",
- var_name)
- klass.module_eval(<<-EOC, __FILE__, __LINE__)
- remove_method :#{var_name}
- def #{var_name}(*args)
- if args.empty?
- @#{var_name}.first and @#{var_name}.first.value
- else
- ret = @#{var_name}.__send__("[]", *args)
- if ret.is_a?(Array)
- ret.collect {|x| x.value}
- else
- ret.value
- end
- end
- end
-
- remove_method :#{var_name}=
- remove_method :set_#{var_name}
- def #{var_name}=(*args)
- if args.size == 1
- item = Utils.new_with_value_if_need(#{klass_name}, args[0])
- @#{var_name}.push(item)
- else
- new_val = args.last
- if new_val.is_a?(Array)
- new_val = new_value.collect do |val|
- Utils.new_with_value_if_need(#{klass_name}, val)
- end
- else
- new_val = Utils.new_with_value_if_need(#{klass_name}, new_val)
- end
- @#{var_name}.__send__("[]=", *(args[0..-2] + [new_val]))
- end
- end
- alias set_#{var_name} #{var_name}=
- EOC
- end
- end
- end
- end
-
- module TrackBackModel10
- extend BaseModel
- extend BaseTrackBackModel
-
- class TrackBackPing < Element
- include RSS10
-
- class << self
-
- def required_prefix
- TRACKBACK_PREFIX
- end
-
- def required_uri
- TRACKBACK_URI
- end
-
- end
-
- @tag_name = "ping"
-
- [
- ["resource", ::RSS::RDF::URI, true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required, nil, nil,
- "#{::RSS::RDF::PREFIX}:#{name}")
- end
-
- alias_method(:value, :resource)
- alias_method(:value=, :resource=)
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.resource = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(TRACKBACK_PREFIX)
- end
- end
-
- class TrackBackAbout < Element
- include RSS10
-
- class << self
-
- def required_prefix
- TRACKBACK_PREFIX
- end
-
- def required_uri
- TRACKBACK_URI
- end
-
- end
-
- @tag_name = "about"
-
- [
- ["resource", ::RSS::RDF::URI, true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required, nil, nil,
- "#{::RSS::RDF::PREFIX}:#{name}")
- end
-
- alias_method(:value, :resource)
- alias_method(:value=, :resource=)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.resource = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(TRACKBACK_PREFIX)
- end
-
- private
- def maker_target(abouts)
- abouts.new_about
- end
-
- def setup_maker_attributes(about)
- about.resource = self.resource
- end
-
- end
- end
-
- module TrackBackModel20
- extend BaseModel
- extend BaseTrackBackModel
-
- class TrackBackPing < Element
- include RSS09
-
- @tag_name = "ping"
-
- content_setup
-
- class << self
-
- def required_prefix
- TRACKBACK_PREFIX
- end
-
- def required_uri
- TRACKBACK_URI
- end
-
- end
-
- alias_method(:value, :content)
- alias_method(:value=, :content=)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.content = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(TRACKBACK_PREFIX)
- end
-
- end
-
- class TrackBackAbout < Element
- include RSS09
-
- @tag_name = "about"
-
- content_setup
-
- class << self
-
- def required_prefix
- TRACKBACK_PREFIX
- end
-
- def required_uri
- TRACKBACK_URI
- end
-
- end
-
- alias_method(:value, :content)
- alias_method(:value=, :content=)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.content = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(TRACKBACK_PREFIX)
- end
-
- end
- end
-
- class RDF
- class Item; include TrackBackModel10; end
- end
-
- class Rss
- class Channel
- class Item; include TrackBackModel20; end
- end
- end
-
- BaseTrackBackModel::ELEMENTS.each do |name|
- class_name = Utils.to_class_name(name)
- BaseListener.install_class_name(TRACKBACK_URI, name,
- "TrackBack#{class_name}")
- end
-
- BaseTrackBackModel::ELEMENTS.collect! {|name| "#{TRACKBACK_PREFIX}_#{name}"}
-end
diff --git a/lib/rss/utils.rb b/lib/rss/utils.rb
deleted file mode 100644
index 9203df9a9b7..00000000000
--- a/lib/rss/utils.rb
+++ /dev/null
@@ -1,200 +0,0 @@
-# frozen_string_literal: false
-module RSS
-
- ##
- # RSS::Utils is a module that holds various utility functions that are used
- # across many parts of the rest of the RSS library. Like most modules named
- # some variant of 'util', its methods are probably not particularly useful
- # to those who aren't developing the library itself.
- module Utils
- module_function
-
- # Given a +name+ in a name_with_underscores or a name-with-dashes format,
- # returns the CamelCase version of +name+.
- #
- # If the +name+ is already CamelCased, nothing happens.
- #
- # Examples:
- #
- # require 'rss/utils'
- #
- # RSS::Utils.to_class_name("sample_name")
- # # => "SampleName"
- # RSS::Utils.to_class_name("with-dashes")
- # # => "WithDashes"
- # RSS::Utils.to_class_name("CamelCase")
- # # => "CamelCase"
- def to_class_name(name)
- name.split(/[_\-]/).collect do |part|
- "#{part[0, 1].upcase}#{part[1..-1]}"
- end.join("")
- end
-
- # Returns an array of two elements: the filename where the calling method
- # is located, and the line number where it is defined.
- #
- # Takes an optional argument +i+, which specifies how many callers up the
- # stack to look.
- #
- # Examples:
- #
- # require 'rss/utils'
- #
- # def foo
- # p RSS::Utils.get_file_and_line_from_caller
- # p RSS::Utils.get_file_and_line_from_caller(1)
- # end
- #
- # def bar
- # foo
- # end
- #
- # def baz
- # bar
- # end
- #
- # baz
- # # => ["test.rb", 5]
- # # => ["test.rb", 9]
- #
- # If +i+ is not given, or is the default value of 0, it attempts to figure
- # out the correct value. This is useful when in combination with
- # instance_eval. For example:
- #
- # require 'rss/utils'
- #
- # def foo
- # p RSS::Utils.get_file_and_line_from_caller(1)
- # end
- #
- # def bar
- # foo
- # end
- #
- # instance_eval <<-RUBY, *RSS::Utils.get_file_and_line_from_caller
- # def baz
- # bar
- # end
- # RUBY
- #
- # baz
- #
- # # => ["test.rb", 8]
- def get_file_and_line_from_caller(i=0)
- file, line, = caller[i].split(':')
- line = line.to_i
- line += 1 if i.zero?
- [file, line]
- end
-
- # Takes a string +s+ with some HTML in it, and escapes '&', '"', '<' and '>', by
- # replacing them with the appropriate entities.
- #
- # This method is also aliased to h, for convenience.
- #
- # Examples:
- #
- # require 'rss/utils'
- #
- # RSS::Utils.html_escape("Dungeons & Dragons")
- # # => "Dungeons &amp; Dragons"
- # RSS::Utils.h(">_>")
- # # => "&gt;_&gt;"
- def html_escape(s)
- s.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
- end
- alias h html_escape
-
- # If +value+ is an instance of class +klass+, return it, else
- # create a new instance of +klass+ with value +value+.
- def new_with_value_if_need(klass, value)
- if value.is_a?(klass)
- value
- else
- klass.new(value)
- end
- end
-
- # This method is used inside of several different objects to determine
- # if special behavior is needed in the constructor.
- #
- # Special behavior is needed if the array passed in as +args+ has
- # +true+ or +false+ as its value, and if the second element of +args+
- # is a hash.
- def element_initialize_arguments?(args)
- [true, false].include?(args[0]) and args[1].is_a?(Hash)
- end
-
- module ExplicitCleanOther
- module_function
- def parse(value)
- if [true, false, nil].include?(value)
- value
- else
- case value.to_s
- when /\Aexplicit|yes|true\z/i
- true
- when /\Aclean|no|false\z/i
- false
- else
- nil
- end
- end
- end
- end
-
- module YesOther
- module_function
- def parse(value)
- if [true, false].include?(value)
- value
- else
- /\Ayes\z/i.match(value.to_s) ? true : false
- end
- end
- end
-
- module CSV
- module_function
- def parse(value, &block)
- if value.is_a?(String)
- value = value.strip.split(/\s*,\s*/)
- value = value.collect(&block) if block_given?
- value
- else
- value
- end
- end
- end
-
- module InheritedReader
- def inherited_reader(constant_name)
- base_class = inherited_base
- result = base_class.const_get(constant_name)
- found_base_class = false
- ancestors.reverse_each do |klass|
- if found_base_class
- if klass.const_defined?(constant_name)
- result = yield(result, klass.const_get(constant_name))
- end
- else
- found_base_class = klass == base_class
- end
- end
- result
- end
-
- def inherited_array_reader(constant_name)
- inherited_reader(constant_name) do |result, current|
- current + result
- end
- end
-
- def inherited_hash_reader(constant_name)
- inherited_reader(constant_name) do |result, current|
- result.merge(current)
- end
- end
- end
- end
-end
diff --git a/lib/rss/version.rb b/lib/rss/version.rb
deleted file mode 100644
index f0a8894e794..00000000000
--- a/lib/rss/version.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-module RSS
- # The current version of RSS
- VERSION = "0.2.8"
-end
diff --git a/lib/rss/xml-stylesheet.rb b/lib/rss/xml-stylesheet.rb
deleted file mode 100644
index 175c95fbcd7..00000000000
--- a/lib/rss/xml-stylesheet.rb
+++ /dev/null
@@ -1,106 +0,0 @@
-# frozen_string_literal: false
-require_relative "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
-
- class XMLStyleSheet
-
- include Utils
-
- ATTRIBUTES = %w(href type title media charset alternate)
-
- GUESS_TABLE = {
- "xsl" => "text/xsl",
- "css" => "text/css",
- }
-
- attr_accessor(*ATTRIBUTES)
- attr_accessor(:do_validate)
- def initialize(*attrs)
- if attrs.size == 1 and
- (attrs.first.is_a?(Hash) or attrs.first.is_a?(Array))
- attrs = attrs.first
- end
- @do_validate = true
- ATTRIBUTES.each do |attr|
- __send__("#{attr}=", nil)
- end
- vars = ATTRIBUTES.dup
- vars.unshift(:do_validate)
- attrs.each do |name, value|
- if vars.include?(name.to_s)
- __send__("#{name}=", value)
- end
- end
- end
-
- def to_s
- rv = ""
- if @href
- rv << %Q[<?xml-stylesheet]
- ATTRIBUTES.each do |name|
- if __send__(name)
- rv << %Q[ #{name}="#{h __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(: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
-
- def setup_maker(maker)
- xss = maker.xml_stylesheets.new_xml_stylesheet
- ATTRIBUTES.each do |attr|
- xss.__send__("#{attr}=", __send__(attr))
- end
- end
-
- private
- def guess_type(filename)
- /\.([^.]+)$/ =~ filename
- GUESS_TABLE[$1]
- end
-
- end
-end
diff --git a/lib/rss/xml.rb b/lib/rss/xml.rb
deleted file mode 100644
index b74630295fc..00000000000
--- a/lib/rss/xml.rb
+++ /dev/null
@@ -1,72 +0,0 @@
-# frozen_string_literal: false
-require_relative "utils"
-
-module RSS
- module XML
- class Element
- include Enumerable
-
- attr_reader :name, :prefix, :uri, :attributes, :children
- def initialize(name, prefix=nil, uri=nil, attributes={}, children=[])
- @name = name
- @prefix = prefix
- @uri = uri
- @attributes = attributes
- if children.is_a?(String) or !children.respond_to?(:each)
- @children = [children]
- else
- @children = children
- end
- end
-
- def [](name)
- @attributes[name]
- end
-
- def []=(name, value)
- @attributes[name] = value
- end
-
- def <<(child)
- @children << child
- end
-
- def each(&block)
- @children.each(&block)
- end
-
- def ==(other)
- other.kind_of?(self.class) and
- @name == other.name and
- @uri == other.uri and
- @attributes == other.attributes and
- @children == other.children
- end
-
- def to_s
- rv = "<#{full_name}"
- attributes.each do |key, value|
- rv << " #{Utils.html_escape(key)}=\"#{Utils.html_escape(value)}\""
- end
- if children.empty?
- rv << "/>"
- else
- rv << ">"
- children.each do |child|
- rv << child.to_s
- end
- rv << "</#{full_name}>"
- end
- rv
- end
-
- def full_name
- if @prefix
- "#{@prefix}:#{@name}"
- else
- @name
- end
- end
- end
- end
-end
diff --git a/lib/rss/xmlparser.rb b/lib/rss/xmlparser.rb
deleted file mode 100644
index cb2dd2afdd9..00000000000
--- a/lib/rss/xmlparser.rb
+++ /dev/null
@@ -1,95 +0,0 @@
-# frozen_string_literal: false
-begin
- require "xml/parser"
-rescue LoadError
- require "xmlparser"
-end
-
-begin
- require "xml/encoding-ja"
-rescue LoadError
- require "xmlencoding-ja"
- if defined?(Kconv)
- module XMLEncoding_ja
- class SJISHandler
- include Kconv
- end
- end
- end
-end
-
-module XML
- class Parser
- unless defined?(Error)
- # This error is legacy, so we just set it to the new one
- Error = ::XMLParserError # :nodoc:
- end
- end
-end
-
-module RSS
-
- class REXMLLikeXMLParser < ::XML::Parser
-
- include ::XML::Encoding_ja
-
- 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 character(data)
- @listener.text(data)
- end
-
- def xmlDecl(version, encoding, standalone)
- @listener.xmldecl(version, encoding, standalone == 1)
- end
-
- def processingInstruction(target, content)
- @listener.instruction(target, content)
- end
-
- end
-
- class XMLParserParser < BaseParser
-
- class << self
- def listener
- XMLParserListener
- end
- end
-
- private
- 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
-
- end
-
-end
diff --git a/lib/rss/xmlscanner.rb b/lib/rss/xmlscanner.rb
deleted file mode 100644
index 6e3b13d2f57..00000000000
--- a/lib/rss/xmlscanner.rb
+++ /dev/null
@@ -1,122 +0,0 @@
-# frozen_string_literal: false
-require 'xmlscan/scanner'
-require 'stringio'
-
-module RSS
-
- class XMLScanParser < BaseParser
-
- class << self
- def listener
- XMLScanListener
- end
- end
-
- private
- def _parse
- begin
- if @rss.is_a?(String)
- input = StringIO.new(@rss)
- else
- input = @rss
- end
- scanner = XMLScan::XMLScanner.new(@listener)
- scanner.parse(input)
- rescue XMLScan::Error => e
- lineno = e.lineno || scanner.lineno || input.lineno
- raise NotWellFormedError.new(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
- end
-
- def on_xmldecl_encoding(str)
- @encoding = str
- end
-
- def on_xmldecl_standalone(str)
- @standalone = str
- end
-
- def on_xmldecl_end
- xmldecl(@version, @encoding, @standalone == "yes")
- end
-
- 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(entity(ref))
- end
-
- def on_charref(code)
- text([code].pack('U'))
- end
-
- alias_method(:on_charref_hex, :on_charref)
-
- def on_stag(name)
- @attrs = {}
- end
-
- def on_attribute(name)
- @attrs[name] = @current_attr = ''
- end
-
- def on_attr_value(str)
- @current_attr << str
- end
-
- def on_attr_entityref(ref)
- @current_attr << entity(ref)
- end
-
- def on_attr_charref(code)
- @current_attr << [code].pack('U')
- end
-
- alias_method(:on_attr_charref_hex, :on_attr_charref)
-
- def on_stag_end(name)
- tag_start(name, @attrs)
- end
-
- def on_stag_end_empty(name)
- tag_start(name, @attrs)
- tag_end(name)
- end
-
- private
- def entity(ref)
- ent = ENTITIES[ref]
- if ent
- ent
- else
- wellformed_error("undefined entity: #{ref}")
- end
- end
- end
-
-end
diff --git a/test/rss/dot.png b/test/rss/dot.png
deleted file mode 100644
index 9c6960fa2f9..00000000000
--- a/test/rss/dot.png
+++ /dev/null
Binary files differ
diff --git a/test/rss/rss-assertions.rb b/test/rss/rss-assertions.rb
deleted file mode 100644
index 86fb91aa186..00000000000
--- a/test/rss/rss-assertions.rb
+++ /dev/null
@@ -1,2120 +0,0 @@
-# frozen_string_literal: false
-require 'erb'
-
-module RSS
- module Assertions
- def _wrap_assertion
- yield
- end
-
- 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_expected_tag(tag, uri, parent)
- _wrap_assertion do
- begin
- yield
- flunk("Not raise NotExpectedTagError")
- rescue ::RSS::NotExpectedTagError => e
- assert_equal(tag, e.tag)
- assert_equal(uri, e.uri)
- assert_equal(parent, e.parent)
- end
- end
- end
-
- def assert_not_available_value(tag, value, attribute=nil)
- _wrap_assertion do
- begin
- yield
- flunk("Not raise NotAvailableValueError")
- rescue ::RSS::NotAvailableValueError => e
- assert_equal(tag, e.tag)
- assert_equal(value, e.value)
- assert_equal(attribute, e.attribute)
- end
- end
- end
-
- def assert_not_set_error(name, variables)
- _wrap_assertion do
- begin
- yield
- flunk("Not raise NotSetError")
- rescue ::RSS::NotSetError => e
- assert_equal(name, e.name)
- assert_kind_of(Array, variables)
- assert_equal(variables.sort, e.variables.sort)
- end
- end
- end
-
- def assert_xml_declaration(version, encoding, standalone, rss)
- _wrap_assertion do
- assert_equal(version, rss.version)
- assert_equal(encoding, rss.encoding)
- assert_equal(standalone, rss.standalone)
- end
- end
-
- def assert_xml_stylesheet_attrs(attrs, xsl)
- _wrap_assertion do
- n_attrs = normalized_attrs(attrs)
- ::RSS::XMLStyleSheet::ATTRIBUTES.each do |name|
- assert_equal(n_attrs[name], xsl.__send__(name))
- end
- end
- end
-
- def assert_xml_stylesheet(target, attrs, xsl)
- _wrap_assertion do
- if attrs.has_key?(:href)
- if !attrs.has_key?(:type) and attrs.has_key?(:guess_type)
- attrs[:type] = attrs[:guess_type]
- end
- assert_equal("xml-stylesheet", target)
- assert_xml_stylesheet_attrs(attrs, xsl)
- else
- assert_nil(target)
- assert_equal("", xsl.to_s)
- end
- end
- end
-
- def assert_xml_stylesheet_pis(attrs_ary, rss=nil)
- _wrap_assertion do
- if rss.nil?
- rss = ::RSS::RDF.new
- setup_rss10(rss)
- end
- xss_strs = []
- attrs_ary.each do |attrs|
- xss = ::RSS::XMLStyleSheet.new(attrs)
- xss_strs.push(xss.to_s)
- rss.xml_stylesheets.push(xss)
- end
- pi_str = rss.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s*<[^\?].*\z/m, "")
- assert_equal(xss_strs.join("\n"), pi_str)
- end
- end
-
- def assert_xml_stylesheets(attrs, xss)
- _wrap_assertion do
- xss.each_with_index do |xs, i|
- assert_xml_stylesheet_attrs(attrs[i], xs)
- end
- end
- end
-
-
- def assert_atom_person(tag_name, generator)
- _wrap_assertion do
- name = "Mark Pilgrim"
- uri = "http://example.org/"
- email = "f8dy@example.com"
-
- assert_parse(generator.call(<<-EOA), :missing_tag, "name", tag_name)
- <#{tag_name}/>
-EOA
-
- assert_parse(generator.call(<<-EOA), :missing_tag, "name", tag_name)
- <#{tag_name}>
- <uri>#{uri}</uri>
- <email>#{email}</email>
- </#{tag_name}>
-EOA
-
- assert_parse(generator.call(<<-EOA), :nothing_raised)
- <#{tag_name}>
- <name>#{name}</name>
- </#{tag_name}>
-EOA
-
- feed = RSS::Parser.parse(generator.call(<<-EOA))
- <#{tag_name}>
- <name>#{name}</name>
- <uri>#{uri}</uri>
- <email>#{email}</email>
- </#{tag_name}>
-EOA
-
- person = yield(feed)
- assert_not_nil(person)
- assert_equal(name, person.name.content)
- assert_equal(uri, person.uri.content)
- assert_equal(email, person.email.content)
- end
- end
-
- def assert_atom_category(generator)
- _wrap_assertion do
- term = "Music"
- scheme = "http://xmlns.com/wordnet/1.6/"
- label = "music"
-
- missing_args = [:missing_attribute, "category", "term"]
- assert_parse(generator.call(<<-EOA), *missing_args)
- <category/>
-EOA
-
- assert_parse(generator.call(<<-EOA), *missing_args)
- <category scheme="#{scheme}" label="#{label}"/>
-EOA
-
- assert_parse(generator.call(<<-EOA), :nothing_raised)
- <category term="#{term}"/>
-EOA
-
- feed = RSS::Parser.parse(generator.call(<<-EOA))
- <category term="#{term}" scheme="#{scheme}" label="#{label}"/>
-EOA
-
- category = yield(feed)
- assert_not_nil(category)
- assert_equal(term, category.term)
- assert_equal(scheme, category.scheme)
- assert_equal(label, category.label)
- end
- end
-
- def assert_atom_link(generator)
- _wrap_assertion do
- href = "http://example.org/feed.atom"
- rel = "self"
- type = "application/atom+xml"
- hreflang = "en"
- title = "Atom"
- length = "1024"
-
- assert_parse(generator.call(<<-EOA), :missing_attribute, "link", "href")
- <link/>
-EOA
-
- assert_parse(generator.call(<<-EOA), :missing_attribute, "link", "href")
- <link rel="#{rel}" type="#{type}" hreflang="#{hreflang}"
- title="#{title}" length="#{length}"/>
-EOA
-
- assert_parse(generator.call(<<-EOA), :nothing_raised)
- <link href="#{href}"/>
-EOA
-
- feed = RSS::Parser.parse(generator.call(<<-EOA))
- <link href="#{href}" rel="#{rel}" type="#{type}" hreflang="#{hreflang}"
- title="#{title}" length="#{length}"/>
-EOA
-
- link = yield(feed)
- assert_not_nil(link)
- assert_equal(href, link.href)
- assert_equal(rel, link.rel)
- assert_equal(type, link.type)
- assert_equal(hreflang, link.hreflang)
- assert_equal(title, link.title)
- assert_equal(length, link.length)
-
-
- href = "http://example.org/index.html.ja"
- parent = link.parent.tag_name
- return if parent == "source"
-
- optional_attributes = %w(hreflang="ja" type="text/html")
- 0.upto(optional_attributes.size) do |i|
- combination(optional_attributes, i).each do |attributes|
- attrs = attributes.join(" ")
- assert_parse(generator.call(<<-EOA), :too_much_tag, "link", parent)
- <link rel="alternate" #{attrs} href="#{href}"/>
- <link rel="alternate" #{attrs} href="#{href}"/>
-EOA
- end
- end
- end
- end
-
- def assert_atom_generator(generator)
- _wrap_assertion do
- uri = "http://www.example.com/"
- version = "1.0"
- content = "Example Toolkit"
-
- assert_parse(generator.call(<<-EOA), :nothing_raised)
- <generator/>
-EOA
-
- assert_parse(generator.call(<<-EOA), :nothing_raised)
- <generator uri="#{uri}" version="#{version}"/>
-EOA
-
- feed = RSS::Parser.parse(generator.call(<<-EOA))
- <generator uri="#{uri}" version="#{version}">#{content}</generator>
-EOA
-
- gen = yield(feed)
- assert_not_nil(gen)
- assert_equal(uri, gen.uri)
- assert_equal(version, gen.version)
- assert_equal(content, gen.content)
- end
- end
-
- def assert_atom_icon(generator)
- _wrap_assertion do
- content = "http://www.example.com/example.png"
-
- assert_parse(generator.call(<<-EOA), :nothing_raised)
- <icon/>
-EOA
-
- feed = RSS::Parser.parse(generator.call(<<-EOA))
- <icon>#{content}</icon>
-EOA
-
- icon = yield(feed)
- assert_not_nil(icon)
- assert_equal(content, icon.content)
- end
- end
-
- def assert_atom_text_construct(tag_name, generator)
- _wrap_assertion do
- [nil, "text", "html"].each do |type|
- attr = ""
- attr = " type=\"#{type}\"" if type
- assert_parse(generator.call(<<-EOA), :nothing_raised)
- <#{tag_name}#{attr}/>
-EOA
- end
-
- assert_parse(generator.call(<<-EOA), :missing_tag, "div", tag_name)
- <#{tag_name} type="xhtml"/>
-EOA
-
- args = ["x", Atom::URI, tag_name]
- assert_parse(generator.call(<<-EOA), :not_expected_tag, *args)
- <#{tag_name} type="xhtml"><x/></#{tag_name}>
-EOA
-
- invalid_value = "invalid"
- args = ["type", invalid_value]
- assert_parse(generator.call(<<-EOA), :not_available_value, *args)
- <#{tag_name} type="#{invalid_value}"/>
-EOA
-
- [
- [nil, "A lot of effort went into making this effortless"],
- ["text", "A lot of effort went into making this effortless"],
- ["html", "A <em>lot</em> of effort went into making this effortless"],
- ].each do |type, content|
- attr = ""
- attr = " type=\"#{type}\"" if type
- feed = RSS::Parser.parse(generator.call(<<-EOA))
- <#{tag_name}#{attr}>#{h content}</#{tag_name}>
-EOA
-
- element = yield(feed)
- assert_not_nil(element)
- assert_equal(type, element.type)
- assert_equal(content, element.content)
- end
-
- [false, true].each do |with_space|
- xhtml_uri = "http://www.w3.org/1999/xhtml"
- xhtml_content = "<div xmlns=\"#{xhtml_uri}\">abc</div>"
- xhtml_element = RSS::XML::Element.new("div", nil, xhtml_uri,
- {"xmlns" => xhtml_uri},
- ["abc"])
- content = xhtml_content
- content = " #{content} " if with_space
- feed = RSS::Parser.parse(generator.call(<<-EOA))
- <#{tag_name} type="xhtml">#{content}</#{tag_name}>
-EOA
-
- element = yield(feed)
- assert_not_nil(element)
- assert_equal("xhtml", element.type)
- assert_equal(xhtml_content, element.content)
- assert_equal(xhtml_element, element.xhtml)
- end
- end
- end
-
- def assert_atom_date_construct(tag_name, generator)
- _wrap_assertion do
- args = [tag_name, ""]
- assert_parse(generator.call(<<-EOR), :not_available_value, *args)
- <#{tag_name}/>
-EOR
-
- [
- ["xxx", false],
- ["2007", false],
- ["2007/02/09", true],
- ].each do |invalid_value, can_parse|
- assert_not_available_value(tag_name, invalid_value) do
- RSS::Parser.parse(generator.call(<<-EOR))
- <#{tag_name}>#{invalid_value}</#{tag_name}>
-EOR
- end
-
- feed = RSS::Parser.parse(generator.call(<<-EOR), false)
- <#{tag_name}>#{invalid_value}</#{tag_name}>
-EOR
- value = yield(feed).content
- if can_parse
- assert_equal(Time.parse(invalid_value), value)
- else
- assert_nil(value)
- end
- end
-
- [
- "2003-12-13T18:30:02Z",
- "2003-12-13T18:30:02.25Z",
- "2003-12-13T18:30:02+01:00",
- "2003-12-13T18:30:02.25+01:00",
- ].each do |valid_value|
- assert_parse(generator.call(<<-EOR), :nothing_raised)
- <#{tag_name}>#{valid_value}</#{tag_name}>
-EOR
-
- feed = RSS::Parser.parse(generator.call(<<-EOR))
- <#{tag_name}>#{valid_value}</#{tag_name}>
-EOR
- assert_equal(Time.parse(valid_value), yield(feed).content)
- end
- end
- end
-
- def assert_atom_logo(generator)
- _wrap_assertion do
- content = "http://www.example.com/example.png"
-
- assert_parse(generator.call(<<-EOA), :nothing_raised)
- <logo/>
-EOA
-
- feed = RSS::Parser.parse(generator.call(<<-EOA))
- <logo>#{content}</logo>
-EOA
-
- logo = yield(feed)
- assert_not_nil(logo)
- assert_equal(content, logo.content)
- end
- end
-
- def assert_atom_content(generator, &getter)
- _wrap_assertion do
- assert_atom_content_inline_text(generator, &getter)
- assert_atom_content_inline_xhtml(generator, &getter)
- assert_atom_content_inline_other(generator, &getter)
- assert_atom_content_out_of_line(generator, &getter)
- end
- end
-
- def assert_atom_content_inline_text(generator)
- _wrap_assertion do
- [nil, "text", "html"].each do |type|
- content = "<content"
- content << " type='#{type}'" if type
-
- suffix = "/>"
- assert_parse(generator.call(content + suffix), :nothing_raised)
- suffix = ">xxx</content>"
- assert_parse(generator.call(content + suffix), :nothing_raised)
- end
-
- [
- ["text", "sample content"],
- ["text/plain", "sample content"],
- ["html", "<em>sample</em> content"]
- ].each do |type, content_content|
- feed = RSS::Parser.parse(generator.call(<<-EOA))
- <content type="#{type}">#{h content_content}</content>
-EOA
- content = yield(feed)
- assert_equal(type, content.type)
- if %w(text html).include?(type)
- assert(content.inline_text?)
- else
- assert(!content.inline_text?)
- end
- if type == "html"
- assert(content.inline_html?)
- else
- assert(!content.inline_html?)
- end
- assert(!content.inline_xhtml?)
- if type == "text/plain"
- assert(content.inline_other?)
- assert(content.inline_other_text?)
- else
- assert(!content.inline_other?)
- assert(!content.inline_other_text?)
- end
- assert(!content.inline_other_xml?)
- assert(!content.inline_other_base64?)
- assert(!content.out_of_line?)
- assert(!content.have_xml_content?)
- assert_equal(content_content, content.content)
- end
- end
- end
-
- def assert_atom_content_inline_xhtml(generator)
- _wrap_assertion do
- args = ["div", "content"]
- assert_parse(generator.call(<<-EOA), :missing_tag, *args)
- <content type="xhtml"/>
-EOA
-
- args = ["x", Atom::URI, "content"]
- assert_parse(generator.call(<<-EOA), :not_expected_tag, *args)
- <content type="xhtml"><x/></content>
-EOA
-
- xhtml_uri = "http://www.w3.org/1999/xhtml"
- xhtml_content = "<div xmlns=\"#{xhtml_uri}\">abc</div>"
- xhtml_element = RSS::XML::Element.new("div", nil, xhtml_uri,
- {"xmlns" => xhtml_uri},
- ["abc"])
- feed = RSS::Parser.parse(generator.call(<<-EOA))
- <content type="xhtml">#{xhtml_content}</content>
-EOA
-
- content = yield(feed)
- assert_not_nil(content)
- assert_equal("xhtml", content.type)
- assert(!content.inline_text?)
- assert(!content.inline_html?)
- assert(content.inline_xhtml?)
- assert(!content.inline_other?)
- assert(!content.inline_other_text?)
- assert(!content.inline_other_xml?)
- assert(!content.inline_other_base64?)
- assert(!content.out_of_line?)
- assert(content.have_xml_content?)
- assert_equal(xhtml_content, content.content)
- assert_equal(xhtml_element, content.xhtml)
- end
- end
-
- def assert_atom_content_inline_other(generator, &getter)
- _wrap_assertion do
- assert_atom_content_inline_other_text(generator, &getter)
- assert_atom_content_inline_other_xml(generator, &getter)
- end
- end
-
- def assert_atom_content_inline_other_text(generator)
- _wrap_assertion do
- type = "image/png"
- assert_parse(generator.call(<<-EOA), :nothing_raised)
- <content type="#{type}"/>
-EOA
-
- png_file = File.join(File.dirname(__FILE__), "dot.png")
- png = File.open(png_file, "rb") do |file|
- file.read.force_encoding("binary")
- end
- base64_content = [png].pack("m").delete("\n")
-
- [false, true].each do |with_space|
- xml_content = base64_content
- xml_content = " #{base64_content}" if with_space
- feed = RSS::Parser.parse(generator.call(<<-EOA))
- <content type="#{type}">#{xml_content}</content>
-EOA
-
- content = yield(feed)
- assert_not_nil(content)
- assert_equal(type, content.type)
- assert(!content.inline_text?)
- assert(!content.inline_html?)
- assert(!content.inline_xhtml?)
- assert(content.inline_other?)
- assert(!content.inline_other_text?)
- assert(!content.inline_other_xml?)
- assert(content.inline_other_base64?)
- assert(!content.out_of_line?)
- assert(!content.have_xml_content?)
- assert_equal(png, content.content)
-
- xml = REXML::Document.new(content.to_s).root
- assert_rexml_element([], {"type" => type}, base64_content, xml)
- end
- end
- end
-
- def assert_atom_content_inline_other_xml(generator)
- _wrap_assertion do
- type = "image/svg+xml"
-
- assert_parse(generator.call(<<-EOA), :nothing_raised)
- <content type="#{type}"/>
-EOA
-
- svg_uri = "http://www.w3.org/2000/svg"
- svg_width = "50pt"
- svg_height = "20pt"
- svg_version = "1.0"
- text_x = "15"
- text_y = "15"
- text = "text"
- svg_content = <<-EOS
-<svg
- xmlns="#{svg_uri}"
- width="#{svg_width}"
- height="#{svg_height}"
- version="#{svg_version}"
-><text x="#{text_x}" y="#{text_y}">#{text}</text
-></svg>
-EOS
-
- text_element = RSS::XML::Element.new("text", nil, svg_uri,
- {
- "x" => text_x,
- "y" => text_y,
- },
- [text])
- svg_element = RSS::XML::Element.new("svg", nil, svg_uri,
- {
- "xmlns" => svg_uri,
- "width" => svg_width,
- "height" => svg_height,
- "version" => svg_version,
- },
- [text_element])
- feed = RSS::Parser.parse(generator.call(<<-EOA))
- <content type="#{type}">#{svg_content}</content>
-EOA
-
- content = yield(feed)
- assert_not_nil(content)
- assert_equal(type, content.type)
- assert(!content.inline_text?)
- assert(!content.inline_html?)
- assert(!content.inline_xhtml?)
- assert(content.inline_other?)
- assert(!content.inline_other_text?)
- assert(content.inline_other_xml?)
- assert(!content.inline_other_base64?)
- assert(!content.out_of_line?)
- assert(content.have_xml_content?)
- assert_equal(REXML::Document.new(svg_content).to_s.chomp,
- REXML::Document.new(content.content).to_s.chomp)
- assert_equal(svg_element, content.xml)
- assert_nil(content.xhtml)
- end
- end
-
- def assert_atom_content_out_of_line(generator)
- _wrap_assertion do
- text_type = "text/plain"
- text_src = "http://example.com/README.txt"
-
- missing_args = [:missing_attribute, "content", "type"]
- # RSS Parser raises error even if this is "should" not "must".
- assert_parse(generator.call(<<-EOA), *missing_args)
- <content src="#{text_src}"/>
-EOA
-
- content_content = "xxx"
- not_available_value_args = [:not_available_value,
- "content", content_content]
- assert_parse(generator.call(<<-EOA), *not_available_value_args)
- <content type="#{text_type}" src="#{text_src}">#{content_content}</content>
-EOA
-
- feed = RSS::Parser.parse(generator.call(<<-EOA))
- <content type="#{text_type}" src="#{text_src}"/>
-EOA
- content = yield(feed)
- assert_not_nil(content)
- assert_equal(text_type, content.type)
- assert_equal(text_src, content.src)
- assert(!content.inline_text?)
- assert(!content.inline_html?)
- assert(!content.inline_xhtml?)
- assert(!content.inline_other?)
- assert(!content.inline_other_text?)
- assert(!content.inline_other_xml?)
- assert(!content.inline_other_base64?)
- assert(content.out_of_line?)
- assert(!content.have_xml_content?)
- assert_nil(content.xml)
- assert_nil(content.xhtml)
- assert_equal("", content.content)
- end
- end
-
- def assert_atom_source(generator, &getter)
- _wrap_assertion do
- assert_atom_source_author(generator, &getter)
- assert_atom_source_category(generator, &getter)
- assert_atom_source_contributor(generator, &getter)
- assert_atom_source_generator(generator, &getter)
- assert_atom_source_icon(generator, &getter)
- assert_atom_source_id(generator, &getter)
- assert_atom_source_link(generator, &getter)
- assert_atom_source_logo(generator, &getter)
- assert_atom_source_rights(generator, &getter)
- assert_atom_source_subtitle(generator, &getter)
- assert_atom_source_title(generator, &getter)
- assert_atom_source_updated(generator, &getter)
- end
- end
-
- def assert_atom_source_author(generator)
- assert_atom_person("author", generator) do |feed|
- source = yield(feed)
- assert_equal(1, source.authors.size)
- source.author
- end
- end
-
- def assert_atom_source_category(generator)
- assert_atom_category(generator) do |feed|
- source = yield(feed)
- assert_equal(1, source.categories.size)
- source.category
- end
- end
-
- def assert_atom_source_contributor(generator)
- assert_atom_person("contributor", generator) do |feed|
- source = yield(feed)
- assert_equal(1, source.contributors.size)
- source.contributor
- end
- end
-
- def assert_atom_source_generator(generator)
- assert_atom_generator(generator) do |feed|
- yield(feed).generator
- end
- end
-
- def assert_atom_source_icon(generator)
- assert_atom_icon(generator) do |feed|
- yield(feed).icon
- end
- end
-
- def assert_atom_source_id(generator)
- id_content = "urn:uuid:a2fb588b-5674-4898-b420-265a734fea69"
- id = "<id>#{id_content}</id>"
- feed = RSS::Parser.parse(generator.call(id))
- assert_equal(id_content, yield(feed).id.content)
- end
-
- def assert_atom_source_link(generator)
- assert_atom_link(generator) do |feed|
- source = yield(feed)
- assert_equal(1, source.links.size)
- source.link
- end
- end
-
- def assert_atom_source_logo(generator)
- assert_atom_logo(generator) do |feed|
- yield(feed).logo
- end
- end
-
- def assert_atom_source_rights(generator)
- assert_atom_text_construct("rights", generator) do |feed|
- yield(feed).rights
- end
- end
-
- def assert_atom_source_subtitle(generator)
- assert_atom_text_construct("subtitle", generator) do |feed|
- yield(feed).subtitle
- end
- end
-
- def assert_atom_source_title(generator)
- assert_atom_text_construct("title", generator) do |feed|
- yield(feed).title
- end
- end
-
- def assert_atom_source_updated(generator)
- assert_atom_date_construct("updated", generator) do |feed|
- yield(feed).updated
- end
- end
-
- def assert_dublin_core(elems, target)
- _wrap_assertion do
- elems.each do |name, value|
- assert_equal(value, target.__send__("dc_#{name}"))
- end
- end
- end
-
- def assert_multiple_dublin_core(elems, target)
- _wrap_assertion do
- elems.each do |name, values, plural|
- plural ||= "#{name}s"
- actual = target.__send__("dc_#{plural}").collect{|x| x.value}
- assert_equal(values, actual)
- end
- end
- end
-
- def assert_syndication(elems, target)
- _wrap_assertion do
- elems.each do |name, value|
- meth = "sy_#{name}"
- value = value.to_i if meth == "sy_updateFrequency"
- assert_equal(value, target.__send__(meth ))
- end
- end
- end
-
- def assert_content(elems, target)
- _wrap_assertion do
- elems.each do |name, value|
- assert_equal(value, target.__send__("content_#{name}"))
- end
- end
- end
-
- def assert_trackback(attrs, target)
- _wrap_assertion do
- n_attrs = normalized_attrs(attrs)
- if n_attrs["ping"]
- assert_equal(n_attrs["ping"], target.trackback_ping)
- end
- if n_attrs["abouts"]
- n_attrs["abouts"].each_with_index do |about, i|
- assert_equal(about, target.trackback_abouts[i].value)
- end
- end
- end
- end
-
- def assert_taxo_topic(topics, target)
- _wrap_assertion do
- topics.each_with_index do |topic, i|
- taxo_topic = target.taxo_topics[i]
- topic.each do |name, value|
- case name
- when :link
- assert_equal(value, taxo_topic.about)
- assert_equal(value, taxo_topic.taxo_link)
- when :topics
- assert_equal(value, taxo_topic.taxo_topics.resources)
- else
- assert_equal(value, taxo_topic.__send__("dc_#{name}"))
- end
- end
- end
- end
- end
-
-
- def assert_attributes(attrs, names, target)
- _wrap_assertion do
- n_attrs = normalized_attrs(attrs)
- names.each do |info|
- if info.is_a?(String)
- name = info
- type = nil
- else
- name, type = info
- end
- value = n_attrs[name]
- if value.is_a?(Time)
- actual = target.__send__(name)
- assert_instance_of(Time, actual)
- assert_equal(value.to_i, actual.to_i)
- elsif value
- case type
- when :integer
- value = value.to_i
- when :boolean
- value = value == "true" if value.is_a?(String)
- end
- assert_equal(value, target.__send__(name))
- end
- end
- end
- end
-
- def assert_rexml_element(children, attrs, text, element, text_type=nil)
- _wrap_assertion do
- if children
- children_info = element.elements.collect {|e| [e.namespace, e.name]}
- assert_equal(children.collect {|uri, name| [uri, name]}.sort,
- children_info.sort)
- end
- if attrs
- assert_equal(attrs.collect {|k, v| [k, v]}.sort,
- element.attributes.collect {|k, v| [k, v]}.sort)
- end
- case text_type
- when :time
- assert_not_nil(element.text)
- assert_equal(Time.parse(text).to_s, Time.parse(element.text).to_s)
- else
- assert_equal(text, element.text)
- end
- end
- end
-
- def _assert_maker_atom_persons(feed_type, maker_readers, feed_readers)
- _wrap_assertion do
- persons = []
- feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
- yield maker
- targets = chain_reader(maker, maker_readers)
- targets.each do |target|
- person = {
- :name => target.name,
- :uri => target.uri,
- :email => target.email,
- }
- persons << person if person[:name]
- end
- end
-
- actual_persons = chain_reader(feed, feed_readers) || []
- actual_persons = actual_persons.collect do |person|
- {
- :name => person.name ? person.name.content : nil,
- :uri => person.uri ? person.uri.content : nil,
- :email => person.email ? person.email.content : nil,
- }
- end
- assert_equal(persons, actual_persons)
- end
- end
-
- def assert_maker_atom_persons(feed_type, maker_readers, feed_readers,
- not_set_error_name=nil,
- parent_not_set_error_name=nil,
- parent_not_set_variable=nil)
- _wrap_assertion do
- not_set_error_name ||= "maker.#{maker_readers.join('.')}"
-
- args = [feed_type, maker_readers, feed_readers]
- if parent_not_set_error_name or parent_not_set_variable
- assert_not_set_error(parent_not_set_error_name,
- parent_not_set_variable) do
- _assert_maker_atom_persons(*args) do |maker|
- yield maker
- end
- end
- else
- _assert_maker_atom_persons(*args) do |maker|
- yield maker
- end
- end
-
- assert_not_set_error(not_set_error_name, %w(name)) do
- _assert_maker_atom_persons(feed_type, maker_readers,
- feed_readers) do |maker|
- yield maker
- targets = chain_reader(maker, maker_readers)
- targets.new_child
- end
- end
-
- assert_not_set_error(not_set_error_name, %w(name)) do
- _assert_maker_atom_persons(feed_type, maker_readers,
- feed_readers) do |maker|
- yield maker
- targets = chain_reader(maker, maker_readers)
- target = targets.new_child
- target.uri = "http://example.com/~me/"
- end
- end
-
- assert_not_set_error(not_set_error_name, %w(name)) do
- _assert_maker_atom_persons(feed_type, maker_readers,
- feed_readers) do |maker|
- yield maker
- targets = chain_reader(maker, maker_readers)
- target = targets.new_child
- target.email = "me@example.com"
- end
- end
-
- assert_not_set_error(not_set_error_name, %w(name)) do
- _assert_maker_atom_persons(feed_type, maker_readers,
- feed_readers) do |maker|
- yield maker
- targets = chain_reader(maker, maker_readers)
- target = targets.new_child
- target.uri = "http://example.com/~me/"
- target.email = "me@example.com"
- end
- end
-
- _assert_maker_atom_persons(feed_type, maker_readers,
- feed_readers) do |maker|
- yield maker
- targets = chain_reader(maker, maker_readers)
- target = targets.new_child
- target.name = "me"
- end
-
- _assert_maker_atom_persons(feed_type, maker_readers,
- feed_readers) do |maker|
- yield maker
- targets = chain_reader(maker, maker_readers)
- target = targets.new_child
- target.name = "me"
- target.uri = "http://example.com/~me/"
- end
-
- _assert_maker_atom_persons(feed_type, maker_readers,
- feed_readers) do |maker|
- yield maker
- targets = chain_reader(maker, maker_readers)
- target = targets.new_child
- target.name = "me"
- target.email = "me@example.com"
- end
-
- _assert_maker_atom_persons(feed_type, maker_readers,
- feed_readers) do |maker|
- yield maker
- targets = chain_reader(maker, maker_readers)
- target = targets.new_child
- target.name = "me"
- target.uri = "http://example.com/~me/"
- target.email = "me@example.com"
- end
-
- _assert_maker_atom_persons(feed_type, maker_readers,
- feed_readers) do |maker|
- yield maker
- targets = chain_reader(maker, maker_readers)
-
- target = targets.new_child
- target.name = "me"
- target.uri = "http://example.com/~me/"
- target.email = "me@example.com"
-
- target = targets.new_child
- target.name = "you"
- target.uri = "http://example.com/~you/"
- target.email = "you@example.com"
- end
-
- assert_not_set_error(not_set_error_name, %w(name)) do
- _assert_maker_atom_persons(feed_type, maker_readers,
- feed_readers) do |maker|
- yield maker
- targets = chain_reader(maker, maker_readers)
-
- target = targets.new_child
- target.name = "me"
- target.uri = "http://example.com/~me/"
- target.email = "me@example.com"
-
- targets.new_child
- end
- end
- end
- end
-
- def _assert_maker_atom_text_construct(feed_type, maker_readers,
- feed_readers, &block)
- maker_extractor = Proc.new do |target|
- text = {
- :type => target.type,
- :content => target.content,
- :xml_content => target.xml_content,
- }
- if text[:type] == "xhtml"
- if text[:xml_content]
- xml_content = text[:xml_content]
- xhtml_uri = "http://www.w3.org/1999/xhtml"
- unless xml_content.is_a?(RSS::XML::Element) and
- ["div", xhtml_uri] == [xml_content.name, xml_content.uri]
- children = xml_content
- children = [children] unless children.is_a?(Array)
- xml_content = RSS::XML::Element.new("div", nil, xhtml_uri,
- {"xmlns" => xhtml_uri},
- children)
- text[:xml_content] = xml_content
- end
- text
- else
- nil
- end
- else
- text[:content] ? text : nil
- end
- end
- feed_extractor = Proc.new do |target|
- {
- :type => target.type,
- :content => target.content,
- :xml_content => target.xhtml,
- }
- end
- _assert_maker_atom_element(feed_type,
- maker_readers, true,
- feed_readers,
- maker_extractor,
- feed_extractor,
- &block)
- end
-
- def assert_maker_atom_text_construct(feed_type, maker_readers, feed_readers,
- parent_not_set_error_name=nil,
- parent_not_set_variable=nil,
- not_set_error_name=nil)
- _wrap_assertion do
- not_set_error_name ||= "maker.#{maker_readers.join('.')}"
-
- args = [feed_type, maker_readers, feed_readers]
- if parent_not_set_error_name or parent_not_set_variable
- assert_not_set_error(parent_not_set_error_name,
- parent_not_set_variable) do
- _assert_maker_atom_text_construct(*args) do |maker|
- yield maker
- end
- end
- else
- _assert_maker_atom_text_construct(*args) do |maker|
- yield maker
- end
- end
-
- assert_not_set_error(not_set_error_name, %w(content)) do
- _assert_maker_atom_text_construct(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers) {|x| x}
- target.type = "text"
- end
- end
-
- assert_not_set_error(not_set_error_name, %w(content)) do
- _assert_maker_atom_text_construct(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers) {|x| x}
- target.type = "html"
- end
- end
-
- assert_not_set_error(not_set_error_name, %w(xml_content)) do
- _assert_maker_atom_text_construct(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers) {|x| x}
- target.type = "xhtml"
- end
- end
-
- assert_not_set_error(not_set_error_name, %w(xml_content)) do
- _assert_maker_atom_text_construct(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers) {|x| x}
- target.type = "xhtml"
- target.content = "Content"
- end
- end
-
- _assert_maker_atom_text_construct(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers) {|x| x}
- target.type = "text"
- target.content = "Content"
- end
-
- _assert_maker_atom_text_construct(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers) {|x| x}
- target.type = "html"
- target.content = "<em>Content</em>"
- end
-
- _assert_maker_atom_text_construct(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers) {|x| x}
- target.type = "xhtml"
- target.xml_content = "text only"
- end
-
- _assert_maker_atom_text_construct(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers) {|x| x}
- target.type = "xhtml"
- target.xml_content = RSS::XML::Element.new("unknown")
- end
- end
- end
-
- def _assert_maker_atom_date_construct(feed_type, maker_readers,
- feed_readers, &block)
- maker_extractor = Proc.new do |target|
- date = {
- :content => target,
- }
- date[:content] ? date : nil
- end
- feed_extractor = Proc.new do |target|
- {
- :content => target.content,
- }
- end
- _assert_maker_atom_element(feed_type,
- maker_readers, false,
- feed_readers,
- maker_extractor,
- feed_extractor,
- &block)
- end
-
- def assert_maker_atom_date_construct(feed_type, maker_readers, feed_readers,
- parent_not_set_error_name=nil,
- parent_not_set_variable=nil)
- _wrap_assertion do
- args = [feed_type, maker_readers, feed_readers]
- if parent_not_set_error_name or parent_not_set_variable
- assert_not_set_error(parent_not_set_error_name,
- parent_not_set_variable) do
- _assert_maker_atom_date_construct(*args) do |maker|
- yield maker
- end
- end
- else
- _assert_maker_atom_date_construct(*args) do |maker|
- yield maker
- end
- end
-
- maker_readers = maker_readers.dup
- writer = "#{maker_readers.pop}="
- _assert_maker_atom_date_construct(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.__send__(writer, Time.now)
- end
- end
- end
-
- def _assert_maker_atom_element(feed_type,
- maker_readers,
- maker_readers_need_block,
- feed_readers,
- maker_extractor,
- feed_extractor)
- _wrap_assertion do
- element = nil
- feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
- yield maker
- if maker_readers_need_block
- target = chain_reader(maker, maker_readers) {|x| x}
- else
- target = chain_reader(maker, maker_readers)
- end
- element = maker_extractor.call(target)
- end
-
- target = chain_reader(feed, feed_readers)
- if target
- actual_element = feed_extractor.call(target)
- else
- actual_element = nil
- end
- assert_equal(element, actual_element)
- end
- end
-
- def _assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
- maker_extractor, feed_extractor,
- invalid_feed_checker=nil)
- _wrap_assertion do
- elements = []
- invalid_feed_exception = nil
- feed = nil
- begin
- feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
- yield maker
- targets = chain_reader(maker, maker_readers)
- targets.each do |target|
- element = maker_extractor.call(target)
- elements << element if element
- end
- if invalid_feed_checker
- invalid_feed_exception = invalid_feed_checker.call(targets)
- end
- end
- rescue RSS::Error
- if invalid_feed_exception.is_a?(RSS::TooMuchTagError)
- assert_too_much_tag(invalid_feed_exception.tag,
- invalid_feed_exception.parent) do
- raise
- end
- else
- raise
- end
- end
-
- if invalid_feed_exception.nil?
- actual_elements = chain_reader(feed, feed_readers) || []
- actual_elements = actual_elements.collect do |target|
- feed_extractor.call(target)
- end
- assert_equal(elements, actual_elements)
- end
- end
- end
-
- def assert_maker_atom_element(feed_type, maker_readers, feed_readers,
- setup_target, optional_variables,
- required_variable, assert_method_name,
- not_set_error_name=nil,
- *additional_args)
- _wrap_assertion do
- not_set_error_name ||= "maker.#{maker_readers.join('.')}"
-
- 0.upto(optional_variables.size) do |i|
- combination(optional_variables, i).each do |names|
- have = {}
- names.each do |name|
- have[name.intern] = true
- end
- have_required_variable_too =
- have.merge({required_variable.intern => true})
-
- assert_not_set_error(not_set_error_name, [required_variable]) do
- __send__(assert_method_name, feed_type, maker_readers,
- feed_readers, *additional_args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers) {|x| x}
- setup_target.call(target, have)
- end
- end
-
- __send__(assert_method_name, feed_type, maker_readers, feed_readers,
- *additional_args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers) {|x| x}
- setup_target.call(target, have_required_variable_too)
- end
- end
- end
- end
- end
-
- def assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
- setup_target, optional_variables,
- required_variable, assert_method_name,
- not_set_error_name=nil,
- *additional_args)
- _wrap_assertion do
- not_set_error_name ||= "maker.#{maker_readers.join('.')}"
-
- 0.upto(optional_variables.size) do |i|
- combination(optional_variables, i).each do |names|
- have = {}
- names.each do |name|
- have[name.intern] = true
- end
- have_required_variable_too =
- have.merge({required_variable.intern => true})
-
- assert_not_set_error(not_set_error_name, [required_variable]) do
- __send__(assert_method_name, feed_type, maker_readers,
- feed_readers, *additional_args) do |maker|
- yield maker
- targets = chain_reader(maker, maker_readers)
- setup_target.call(targets, have)
- end
- end
-
- __send__(assert_method_name, feed_type, maker_readers, feed_readers,
- *additional_args) do |maker|
- yield maker
- targets = chain_reader(maker, maker_readers)
- setup_target.call(targets, have_required_variable_too)
- end
-
- __send__(assert_method_name, feed_type, maker_readers, feed_readers,
- *additional_args) do |maker|
- yield maker
- targets = chain_reader(maker, maker_readers)
- setup_target.call(targets, have_required_variable_too)
- setup_target.call(targets, have_required_variable_too)
- end
-
- assert_not_set_error(not_set_error_name, [required_variable]) do
- __send__(assert_method_name, feed_type, maker_readers, feed_readers,
- *additional_args) do |maker|
- yield maker
- targets = chain_reader(maker, maker_readers)
- setup_target.call(targets, have_required_variable_too)
- setup_target.call(targets, have)
- end
- end
- end
- end
- end
- end
-
- def _assert_maker_atom_categories(feed_type, maker_readers,
- feed_readers, &block)
- maker_extractor = Proc.new do |target|
- category = {
- :term => target.term,
- :scheme => target.scheme,
- :label => target.label,
- }
- category[:term] ? category : nil
- end
- feed_extractor = Proc.new do |target|
- {
- :term => target.term,
- :scheme => target.scheme,
- :label => target.label,
- }
- end
- _assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
- maker_extractor, feed_extractor, &block)
- end
-
- def assert_maker_atom_categories(feed_type, maker_readers, feed_readers,
- not_set_error_name=nil, &block)
- _wrap_assertion do
- _assert_maker_atom_categories(feed_type, maker_readers,
- feed_readers) do |maker|
- yield maker
- end
-
- setup_target = Proc.new do |targets, have|
- target = targets.new_child
- target.term = "music" if have[:term]
- target.scheme = "http://example.com/category/music" if have[:scheme]
- target.label = "Music" if have[:label]
- end
-
- optional_variables = %w(scheme label)
-
- assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
- setup_target, optional_variables,
- "term", :_assert_maker_atom_categories,
- not_set_error_name, &block)
- end
- end
-
- def _assert_maker_atom_generator(feed_type, maker_readers,
- feed_readers, &block)
- maker_extractor = Proc.new do |target|
- generator = {
- :uri => target.uri,
- :version => target.version,
- :content => target.content,
- }
- generator[:content] ? generator : nil
- end
- feed_extractor = Proc.new do |target|
- {
- :uri => target.uri,
- :version => target.version,
- :content => target.content,
- }
- end
- _assert_maker_atom_element(feed_type,
- maker_readers, true,
- feed_readers,
- maker_extractor,
- feed_extractor,
- &block)
- end
-
- def assert_maker_atom_generator(feed_type, maker_readers, feed_readers,
- not_set_error_name=nil, &block)
- _wrap_assertion do
- not_set_error_name ||= "maker.#{maker_readers.join('.')}"
-
- _assert_maker_atom_generator(feed_type, maker_readers,
- feed_readers) do |maker|
- yield maker
- end
-
- setup_target = Proc.new do |target, have|
- target.content = "RSS Maker" if have[:content]
- target.uri = "http://example.com/rss/maker" if have[:uri]
- target.version = "0.0.1" if have[:version]
- end
-
- optional_variables = %w(uri version)
-
- assert_maker_atom_element(feed_type, maker_readers, feed_readers,
- setup_target, optional_variables,
- "content", :_assert_maker_atom_generator,
- not_set_error_name, &block)
- end
- end
-
- def _assert_maker_atom_icon(feed_type, maker_readers, feed_readers,
- accessor_base, &block)
- maker_extractor = Proc.new do |target|
- icon = {
- :content => target.__send__(accessor_base),
- }
- icon[:content] ? icon : nil
- end
- feed_extractor = Proc.new do |target|
- {
- :content => target.content,
- }
- end
- _assert_maker_atom_element(feed_type,
- maker_readers, true,
- feed_readers,
- maker_extractor,
- feed_extractor,
- &block)
- end
-
- def assert_maker_atom_icon(feed_type, maker_readers, feed_readers,
- accessor_base=nil, not_set_error_name=nil)
- _wrap_assertion do
- accessor_base ||= "url"
- not_set_error_name ||= "maker.#{maker_readers.join('.')}"
-
- _assert_maker_atom_icon(feed_type, maker_readers, feed_readers,
- accessor_base) do |maker|
- yield maker
- end
-
- _assert_maker_atom_icon(feed_type, maker_readers, feed_readers,
- accessor_base) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.__send__("#{accessor_base}=", "http://example.com/icon.png")
- end
- end
- end
-
- def _assert_maker_atom_links(feed_type, maker_readers, feed_readers,
- allow_duplication=false, &block)
- maker_extractor = Proc.new do |target|
- link = {
- :href => target.href,
- :rel => target.rel,
- :type => target.type,
- :hreflang => target.hreflang,
- :title => target.title,
- :length => target.length,
- }
- link[:href] ? link : nil
- end
- feed_extractor = Proc.new do |target|
- {
- :href => target.href,
- :rel => target.rel,
- :type => target.type,
- :hreflang => target.hreflang,
- :title => target.title,
- :length => target.length,
- }
- end
-
- if feed_readers.first == "entries"
- parent = "entry"
- else
- parent = feed_type
- end
- invalid_feed_checker = Proc.new do |targets|
- infos = {}
- invalid_exception = nil
- targets.each do |target|
- key = [target.hreflang, target.type]
- if infos.has_key?(key)
- invalid_exception = RSS::TooMuchTagError.new("link", parent)
- break
- end
- infos[key] = true if target.rel.nil? or target.rel == "alternate"
- end
- invalid_exception
- end
- invalid_feed_checker = nil if allow_duplication
- _assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
- maker_extractor, feed_extractor,
- invalid_feed_checker,
- &block)
- end
-
- def assert_maker_atom_links(feed_type, maker_readers, feed_readers,
- not_set_error_name=nil, allow_duplication=false,
- &block)
- _wrap_assertion do
- _assert_maker_atom_links(feed_type, maker_readers,
- feed_readers) do |maker|
- yield maker
- end
-
- langs = %(ja en fr zh po)
- setup_target = Proc.new do |targets, have|
- target = targets.new_child
- lang = langs[targets.size % langs.size]
- target.href = "http://example.com/index.html.#{lang}" if have[:href]
- target.rel = "alternate" if have[:rel]
- target.type = "text/xhtml" if have[:type]
- target.hreflang = lang if have[:hreflang]
- target.title = "FrontPage(#{lang})" if have[:title]
- target.length = 1024 if have[:length]
- end
-
- optional_variables = %w(rel type hreflang title length)
-
- assert_maker_atom_elements(feed_type, maker_readers, feed_readers,
- setup_target, optional_variables,
- "href", :_assert_maker_atom_links,
- not_set_error_name, allow_duplication,
- &block)
- end
- end
-
- def _assert_maker_atom_logo(feed_type, maker_readers, feed_readers,
- accessor_base, &block)
- maker_extractor = Proc.new do |target|
- logo = {
- :uri => target.__send__(accessor_base),
- }
- logo[:uri] ? logo : nil
- end
- feed_extractor = Proc.new do |target|
- {
- :uri => target.content,
- }
- end
- _assert_maker_atom_element(feed_type,
- maker_readers, true,
- feed_readers,
- maker_extractor,
- feed_extractor,
- &block)
- end
-
- def assert_maker_atom_logo(feed_type, maker_readers, feed_readers,
- accessor_base=nil, not_set_error_name=nil)
- _wrap_assertion do
- accessor_base ||= "uri"
- not_set_error_name ||= "maker.#{maker_readers.join('.')}"
-
- _assert_maker_atom_logo(feed_type, maker_readers, feed_readers,
- accessor_base) do |maker|
- yield maker
- end
-
- _assert_maker_atom_logo(feed_type, maker_readers, feed_readers,
- accessor_base) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.__send__("#{accessor_base}=", "http://example.com/logo.png")
- end
- end
- end
-
- def _assert_maker_atom_id(feed_type, maker_readers, feed_readers, &block)
- maker_extractor = Proc.new do |target|
- id = {
- :uri => target.id,
- }
- id[:uri] ? id : nil
- end
- feed_extractor = Proc.new do |target|
- if target.id
- {
- :uri => target.id.content,
- }
- else
- nil
- end
- end
- _assert_maker_atom_element(feed_type,
- maker_readers, true,
- feed_readers,
- maker_extractor,
- feed_extractor,
- &block)
- end
-
- def assert_maker_atom_id(feed_type, maker_readers, feed_readers,
- not_set_error_name=nil)
- _wrap_assertion do
- not_set_error_name ||= "maker.#{maker_readers.join('.')}"
-
- args = [feed_type, maker_readers, feed_readers]
- _assert_maker_atom_id(*args) do |maker|
- yield maker
- end
-
- _assert_maker_atom_id(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.id = "http://example.com/id/1"
- end
- end
- end
-
- def _assert_maker_atom_content(feed_type, maker_readers,
- feed_readers, &block)
- maker_extractor = Proc.new do |target|
- content = {
- :type => target.type,
- :src => target.src,
- :content => target.content,
- :xml => target.xml,
- :inline_text => target.inline_text?,
- :inline_html => target.inline_html?,
- :inline_xhtml => target.inline_xhtml?,
- :inline_other => target.inline_other?,
- :inline_other_text => target.inline_other_text?,
- :inline_other_xml => target.inline_other_xml?,
- :inline_other_base64 => target.inline_other_base64?,
- :out_of_line => target.out_of_line?,
- }
- content[:src] = nil if content[:src] and content[:content]
- if content[:type] or content[:content]
- content
- else
- nil
- end
- end
- feed_extractor = Proc.new do |target|
- {
- :type => target.type,
- :src => target.src,
- :content => target.content,
- :xml => target.xml,
- :inline_text => target.inline_text?,
- :inline_html => target.inline_html?,
- :inline_xhtml => target.inline_xhtml?,
- :inline_other => target.inline_other?,
- :inline_other_text => target.inline_other_text?,
- :inline_other_xml => target.inline_other_xml?,
- :inline_other_base64 => target.inline_other_base64?,
- :out_of_line => target.out_of_line?,
- }
- end
- _assert_maker_atom_element(feed_type,
- maker_readers, true,
- feed_readers,
- maker_extractor,
- feed_extractor,
- &block)
- end
-
- def assert_maker_atom_content(feed_type, maker_readers, feed_readers,
- not_set_error_name=nil, &block)
- _wrap_assertion do
- not_set_error_name ||= "maker.#{maker_readers.join('.')}"
- args = [feed_type, maker_readers, feed_readers, not_set_error_name]
- assert_maker_atom_content_inline_text(*args, &block)
- assert_maker_atom_content_inline_xhtml(*args, &block)
- assert_maker_atom_content_inline_other(*args, &block)
- assert_maker_atom_content_out_of_line(*args, &block)
- end
- end
-
- def assert_maker_atom_content_inline_text(feed_type, maker_readers,
- feed_readers, not_set_error_name)
- _wrap_assertion do
- args = [feed_type, maker_readers, feed_readers]
- _assert_maker_atom_content(*args) do |maker|
- yield maker
- end
-
- assert_not_set_error(not_set_error_name, %w(content)) do
- RSS::Maker.make("atom:#{feed_type}") do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "text"
- end
- end
-
- assert_not_set_error(not_set_error_name, %w(content)) do
- RSS::Maker.make("atom:#{feed_type}") do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "html"
- end
- end
-
- _assert_maker_atom_content(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.content = ""
- end
-
- _assert_maker_atom_content(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "text"
- target.content = "example content"
- end
-
- _assert_maker_atom_content(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "html"
- target.content = "<em>text</em>"
- end
- end
- end
-
- def assert_maker_atom_content_inline_xhtml(feed_type, maker_readers,
- feed_readers, not_set_error_name)
- _wrap_assertion do
- args = [feed_type, maker_readers, feed_readers]
- assert_not_set_error(not_set_error_name, %w(xml_content)) do
- RSS::Maker.make("atom:#{feed_type}") do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "xhtml"
- end
- end
-
- assert_not_set_error(not_set_error_name, %w(xml_content)) do
- RSS::Maker.make("atom:#{feed_type}") do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "xhtml"
- target.content = "dummy"
- end
- end
-
- _assert_maker_atom_content(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "xhtml"
- target.xml_content = "text"
- end
-
- _assert_maker_atom_content(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "xhtml"
- target.xml = "text"
- end
-
- _assert_maker_atom_content(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "xhtml"
- target.xml_content =
- RSS::XML::Element.new("em", nil, nil, {}, ["text"])
- end
-
- _assert_maker_atom_content(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "xhtml"
- target.xml = RSS::XML::Element.new("em", nil, nil, {}, ["text"])
- end
-
-
- xhtml_uri = "http://www.w3.org/1999/xhtml"
- em = RSS::XML::Element.new("em", nil, nil, {}, ["text"])
- em_with_xhtml_uri =
- RSS::XML::Element.new("em", nil, xhtml_uri, {}, ["text"])
- feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "xhtml"
- target.xml = em
- end
- assert_equal(RSS::XML::Element.new("div", nil, xhtml_uri,
- {"xmlns" => xhtml_uri},
- [em_with_xhtml_uri]),
- chain_reader(feed, feed_readers).xml)
-
- div = RSS::XML::Element.new("div", nil, xhtml_uri,
- {"xmlns" => xhtml_uri,
- "class" => "sample"},
- ["text"])
- feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "xhtml"
- target.xml = div
- end
- assert_equal(div, chain_reader(feed, feed_readers).xml)
- end
- end
-
- def assert_maker_atom_content_inline_other(*args, &block)
- _wrap_assertion do
- assert_maker_atom_content_inline_other_xml(*args, &block)
- assert_maker_atom_content_inline_other_text(*args, &block)
- assert_maker_atom_content_inline_other_base64(*args, &block)
- end
- end
-
- def assert_maker_atom_content_inline_other_xml(feed_type, maker_readers,
- feed_readers,
- not_set_error_name)
- _wrap_assertion do
- args = [feed_type, maker_readers, feed_readers]
- assert_not_set_error(not_set_error_name, %w(xml_content)) do
- RSS::Maker.make("atom:#{feed_type}") do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "application/xml"
- end
- end
-
- assert_not_set_error(not_set_error_name, %w(xml_content)) do
- RSS::Maker.make("atom:#{feed_type}") do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "svg/image+xml"
- end
- end
-
- svg_uri = "http://www.w3.org/2000/svg"
- rect = RSS::XML::Element.new("rect", nil, svg_uri,
- {"x" => "0.5cm",
- "y" => "0.5cm",
- "width" => "2cm",
- "height" => "1cm"})
- svg = RSS::XML::Element.new("svg", nil, svg_uri,
- {"xmlns" => svg_uri,
- "version" => "1.1",
- "width" => "5cm",
- "height" => "4cm"},
- [rect])
- _assert_maker_atom_content(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "image/svg+xml"
- target.xml = svg
- end
-
- feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "image/svg+xml"
- target.xml = svg
- end
- assert_equal(svg, chain_reader(feed, feed_readers).xml)
- end
- end
-
- def assert_maker_atom_content_inline_other_text(feed_type, maker_readers,
- feed_readers,
- not_set_error_name)
- _wrap_assertion do
- args = [feed_type, maker_readers, feed_readers]
- assert_not_set_error(not_set_error_name, %w(content)) do
- RSS::Maker.make("atom:#{feed_type}") do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "text/plain"
- end
- end
-
- _assert_maker_atom_content(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "text/plain"
- target.content = "text"
- end
- end
- end
-
- def assert_maker_atom_content_inline_other_base64(feed_type, maker_readers,
- feed_readers,
- not_set_error_name)
- _wrap_assertion do
- args = [feed_type, maker_readers, feed_readers]
- content = "\211PNG\r\n\032\n"
- _assert_maker_atom_content(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "image/png"
- target.content = content
- end
-
- _assert_maker_atom_content(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "image/png"
- target.src = "http://example.com/logo.png"
- target.content = content
- end
-
- feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "image/png"
- target.src = "http://example.com/logo.png"
- target.content = content
- end
- target = chain_reader(feed, feed_readers)
- assert_nil(target.src)
- assert_equal(content, target.content)
- end
- end
-
- def assert_maker_atom_content_out_of_line(feed_type, maker_readers,
- feed_readers, not_set_error_name)
- _wrap_assertion do
- args = [feed_type, maker_readers, feed_readers]
- assert_not_set_error(not_set_error_name, %w(content)) do
- RSS::Maker.make("atom:#{feed_type}") do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "image/png"
- end
- end
-
- assert_not_set_error(not_set_error_name, %w(type)) do
- RSS::Maker.make("atom:#{feed_type}") do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.src = "http://example.com/logo.png"
- end
- end
-
- _assert_maker_atom_content(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "image/png"
- target.src = "http://example.com/logo.png"
- end
-
- _assert_maker_atom_content(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "image/png"
- target.content = "\211PNG\r\n\032\n"
- end
-
- _assert_maker_atom_content(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "application/xml"
- target.src = "http://example.com/sample.xml"
- end
-
-
- _assert_maker_atom_content(*args) do |maker|
- yield maker
- target = chain_reader(maker, maker_readers)
- target.type = "text/plain"
- target.src = "http://example.com/README.txt"
- end
- end
- end
-
- def assert_slash_elements(expected, target)
- assert_equal(expected,
- {
- "section" => target.slash_section,
- "department" => target.slash_department,
- "comments" => target.slash_comments,
- "hit_parades" => target.slash_hit_parades,
- })
- assert_equal(expected["hit_parades"].join(","),
- target.slash_hit_parade)
- end
-
- def chain_reader(target, readers, &block)
- readers.inject(target) do |result, reader|
- return nil if result.nil?
- result.__send__(reader, &block)
- end
- end
-
- def normalized_attrs(attrs)
- n_attrs = {}
- attrs.each do |name, value|
- n_attrs[name.to_s] = value
- end
- n_attrs
- end
-
- def combination(elements, n)
- if n <= 0 or elements.size < n
- []
- elsif n == 1
- elements.collect {|element| [element]}
- else
- first, *rest = elements
- combination(rest, n - 1).collect do |sub_elements|
- [first, *sub_elements]
- end + combination(rest, n)
- end
- end
-
- def tag(name, content=nil, attributes={})
- attributes = attributes.collect do |key, value|
- "#{ERB::Util.h(key)}=\"#{ERB::Util.h(value)}\""
- end.join(" ")
- begin_tag = "<#{name}"
- begin_tag << " #{attributes}" unless attributes.empty?
- if content
- "#{begin_tag}>#{content}</#{name}>\n"
- else
- "#{begin_tag}/>\n"
- end
- end
- end
-end
diff --git a/test/rss/rss-testcase.rb b/test/rss/rss-testcase.rb
deleted file mode 100644
index 30067d43b2d..00000000000
--- a/test/rss/rss-testcase.rb
+++ /dev/null
@@ -1,479 +0,0 @@
-# frozen_string_literal: false
-require "erb"
-
-require "test/unit"
-require_relative 'rss-assertions'
-
-require "rss"
-
-module RSS
- class TestCase < Test::Unit::TestCase
- include ERB::Util
-
- 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/"
-
- FEED_TITLE = "dive into mark"
- FEED_UPDATED = "2003-12-13T18:30:02Z"
- FEED_AUTHOR_NAME = "John Doe"
- FEED_ID = "urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"
-
- ENTRY_TITLE = "Atom-Powered Robots Run Amok"
- ENTRY_LINK = "http://example.org/2003/12/13/atom03"
- ENTRY_ID = "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"
- ENTRY_UPDATED = "2003-12-13T18:30:02Z"
- ENTRY_SUMMARY = "Some text."
-
- t = Time.iso8601("2000-01-01T12:00:05+00:00")
- class << t
- alias_method(:to_s, :iso8601)
- end
-
- DC_ELEMENTS = {
- :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 = DC_ELEMENTS.collect do |name, value|
- "<#{DC_PREFIX}:#{name}>#{value}</#{DC_PREFIX}:#{name}>"
- end.join("\n")
-
- 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
-
- def make_channel(content=nil)
- <<-EOC
-<channel rdf:about="#{RDF_ABOUT}">
- <title>#{TITLE_VALUE}</title>
- <link>#{LINK_VALUE}</link>
- <description>#{DESCRIPTION_VALUE}</description>
-
- <image rdf:resource="#{RDF_RESOURCE}" />
-
- <items>
- <rdf:Seq>
-#{RESOURCES.collect do |res| '<rdf:li resource="' + res + '" />' end.join("\n")}
- </rdf:Seq>
- </items>
-
- <textinput rdf:resource="#{RDF_RESOURCE}" />
-
-#{block_given? ? yield : content}
-</channel>
-EOC
- end
-
- def make_image(content=nil)
- <<-EOI
-<image rdf:about="#{RDF_ABOUT}">
- <title>#{TITLE_VALUE}</title>
- <url>#{URL_VALUE}</url>
- <link>#{LINK_VALUE}</link>
-#{block_given? ? yield : content}
-</image>
-EOI
- end
-
- def make_item(content=nil)
- <<-EOI
-<item rdf:about="#{RDF_ABOUT}">
- <title>#{TITLE_VALUE}</title>
- <link>#{LINK_VALUE}</link>
- <description>#{DESCRIPTION_VALUE}</description>
-#{block_given? ? yield : content}
-</item>
-EOI
- end
-
- 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>
-#{block_given? ? yield : content}
-</textinput>
-EOT
- end
-
- def make_sample_RDF
- make_RDF(<<-EOR)
-#{make_channel}
-#{make_image}
-#{make_item}
-#{make_textinput}
-EOR
- end
-
- 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
-
- def make_sample_items20
- RESOURCES.collect do |res|
- elems = ["<link>#{res}</link>"]
- elems << "<title>title of #{res}</title>"
- elems = elems.join("\n")
- "<item>\n#{elems}\n</item>"
- end.join("\n")
- end
-
- def make_channel20(content=nil)
- <<-EOC
-<channel>
- <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>
-
-#{make_sample_items20}
-
- <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
-
- def make_item20(content=nil)
- <<-EOI
-<item>
- <title>#{TITLE_VALUE}</title>
- <link>#{LINK_VALUE}</link>
- <description>#{DESCRIPTION_VALUE}</description>
-#{block_given? ? yield : content}
-</item>
-EOI
- end
-
- def make_cloud20
- <<-EOC
-<cloud
- domain="#{CLOUD_DOMAIN}"
- port="#{CLOUD_PORT}"
- path="#{CLOUD_PATH}"
- registerProcedure="#{CLOUD_REGISTER_PROCEDURE}"
- protocol="#{CLOUD_PROTOCOL}" />
-EOC
- end
-
- def make_sample_rss20
- make_rss20(<<-EOR)
-#{make_channel20}
-EOR
- end
-
- def make_feed_without_entry(content=nil, xmlns=[])
- <<-EOA
-<feed xmlns="#{Atom::URI}"
-#{xmlns.collect {|pre, uri| "xmlns:#{pre}='#{uri}'"}.join(' ')}>
- <id>#{FEED_ID}</id>
- <title>#{FEED_TITLE}</title>
- <updated>#{FEED_UPDATED}</updated>
- <author>
- <name>#{FEED_AUTHOR_NAME}</name>
- </author>
-#{block_given? ? yield : content}
-</feed>
-EOA
- end
-
- def make_entry(content=nil)
- <<-EOA
- <entry>
- <title>#{ENTRY_TITLE}</title>
- <id>#{ENTRY_ID}</id>
- <updated>#{ENTRY_UPDATED}</updated>
-#{block_given? ? yield : content}
- </entry>
-EOA
- end
-
- def make_feed_with_open_entry(content=nil, xmlns=[], &block)
- make_feed_without_entry(<<-EOA, xmlns)
-#{make_entry(content, &block)}
-EOA
- end
-
- def make_feed_with_open_entry_source(content=nil, xmlns=[])
- make_feed_with_open_entry(<<-EOA, xmlns)
- <source>
-#{block_given? ? yield : content}
- </source>
-EOA
- end
-
- def make_feed(content=nil, xmlns=[])
- make_feed_without_entry(<<-EOA, xmlns)
- <entry>
- <title>#{ENTRY_TITLE}</title>
- <link href="#{ENTRY_LINK}"/>
- <id>#{ENTRY_ID}</id>
- <updated>#{ENTRY_UPDATED}</updated>
- <summary>#{ENTRY_SUMMARY}</summary>
- </entry>
-#{block_given? ? yield : content}
-EOA
- end
-
- def make_entry_document(content=nil, xmlns=[])
- <<-EOA
-<entry xmlns="#{Atom::URI}"
-#{xmlns.collect {|pre, uri| "xmlns:#{pre}='#{uri}'"}.join(' ')}>
- <id>#{ENTRY_ID}</id>
- <title>#{ENTRY_TITLE}</title>
- <updated>#{ENTRY_UPDATED}</updated>
- <author>
- <name>#{FEED_AUTHOR_NAME}</name>
- </author>
-#{block_given? ? yield : content}
-</entry>
-EOA
- end
-
- def make_entry_document_with_open_source(content=nil, xmlns=[])
- make_entry_document(<<-EOA, xmlns)
- <source>
-#{block_given? ? yield : content}
- </source>
-EOA
- end
-
- def make_element(elem_name, attrs, contents)
- attrs_str = attrs.collect do |name, value|
- "#{h name}='#{h value}'"
- end.join(" ")
- attrs_str = " #{attrs_str}" unless attrs_str.empty?
-
- if contents.is_a?(String)
- contents_str = h(contents)
- else
- contents_str = contents.collect do |name, value|
- "#{Element::INDENT}<#{h name}>#{h value}</#{h name}>"
- end.join("\n")
- contents_str = "\n#{contents_str}\n"
- end
-
- "<#{h elem_name}#{attrs_str}>#{contents_str}</#{h elem_name}>"
- end
-
- def xmlns_container(xmlns_decls, content)
- attributes = xmlns_decls.collect do |prefix, uri|
- "xmlns:#{h prefix}=\"#{h uri}\""
- end.join(" ")
- "<dummy #{attributes}>#{content}</dummy>"
- end
-
- private
- def setup_rss10(rdf)
- assert_equal("", rdf.to_s)
-
- channel = RDF::Channel.new
- assert_equal("", channel.to_s)
- channel.about = "http://example.com/index.rdf"
- channel.title = "title"
- channel.link = "http://example.com/"
- channel.description = "description"
- assert_equal("", channel.to_s)
-
- item_title = "item title"
- item_link = "http://example.com/item"
- channel.items = RDF::Channel::Items.new
- channel.items.Seq.lis << RDF::Channel::Items::Seq::Li.new(item_link)
- assert_not_equal("", channel.to_s)
-
- rdf.channel = channel
- assert_equal("", rdf.to_s)
-
- item = RDF::Item.new
- item.title = item_title
- item.link = item_link
- item.about = item_link
- rdf.items << item
- assert_not_equal("", rdf.to_s)
- end
-
- def setup_rss20(rss)
- assert_equal("", rss.to_s)
-
- channel = Rss::Channel.new
- assert_equal("", channel.to_s)
- channel.title = "title"
- channel.link = "http://example.com/"
- channel.description = "description"
- assert_not_equal("", channel.to_s)
-
- rss.channel = channel
- assert_not_equal("", rss.to_s)
- end
-
- def setup_dummy_channel(maker)
- about = "http://hoge.com"
- title = "fugafuga"
- link = "http://hoge.com/feed.xml"
- description = "fugafugafugafuga"
- language = "ja"
-
- maker.channel.about = about
- maker.channel.title = title
- maker.channel.link = link
- maker.channel.description = description
- maker.channel.language = language
- end
-
- def setup_dummy_channel_atom(maker)
- updated = Time.now
- author = "Foo"
-
- setup_dummy_channel(maker)
- maker.channel.links.first.rel = "self"
- maker.channel.links.first.type = "application/atom+xml"
- maker.channel.updated = updated
- maker.channel.author = author
- end
-
- def setup_dummy_image(maker)
- title = "fugafuga"
- link = "http://hoge.com"
- url = "http://hoge.com/hoge.png"
-
- maker.channel.link = link if maker.channel.link.nil?
-
- maker.image.title = title
- maker.image.url = url
- end
-
- def setup_dummy_textinput(maker)
- title = "fugafuga"
- description = "text hoge fuga"
- name = "hoge"
- link = "http://hoge.com/search.cgi"
-
- maker.textinput.title = title
- maker.textinput.description = description
- maker.textinput.name = name
- maker.textinput.link = link
- end
-
- def setup_dummy_item(maker)
- title = "TITLE"
- link = "http://hoge.com/"
-
- item = maker.items.new_item
- item.title = title
- item.link = link
- end
-
- def setup_dummy_item_atom(maker)
- setup_dummy_item(maker)
-
- item = maker.items.first
- item.id = "http://example.net/xxx"
- item.updated = Time.now
- end
-
- def setup_taxo_topic(target, topics)
- topics.each do |topic|
- taxo_topic = target.taxo_topics.new_taxo_topic
- topic.each do |name, value|
- case name
- when :link
- taxo_topic.taxo_link = value
- when :topics
- value.each do |t|
- taxo_topic.taxo_topics << t
- end
- else
- dc_elems = taxo_topic.__send__("dc_#{name}s")
- dc_elem = dc_elems.__send__("new_#{name}")
- dc_elem.value = value
- end
- end
- end
- end
- end
-end
diff --git a/test/rss/test_1.0.rb b/test/rss/test_1.0.rb
deleted file mode 100644
index 33ae29141bd..00000000000
--- a/test/rss/test_1.0.rb
+++ /dev/null
@@ -1,308 +0,0 @@
-# frozen_string_literal: false
-require "rexml/document"
-
-require_relative "rss-testcase"
-
-require "rss/1.0"
-
-module RSS
- class TestRSS10Core < 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 = false
-
- rdf = RDF.new(version, encoding, standalone)
- setup_rss10(rdf)
- doc = REXML::Document.new(rdf.to_s)
-
- xmldecl = doc.xml_decl
-
- assert_equal(version, xmldecl.version)
- assert_equal(encoding, xmldecl.encoding.to_s)
- assert_equal(standalone, !xmldecl.standalone.nil?)
-
- 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"
- resource = "http://hoge.com/hoge.png"
-
- item_title = "item title"
- item_link = "http://hoge.com/item"
-
- image = RDF::Channel::Image.new(resource)
- items = RDF::Channel::Items.new
- items.Seq.lis << items.class::Seq::Li.new(item_link)
- textinput = RDF::Channel::Textinput.new(resource)
-
- rss_item = RDF::Item.new
- rss_item.title = item_title
- rss_item.link = item_link
- rss_item.about = item_link
-
- h = {
- 'title' => "fugafuga",
- 'link' => "http://hoge.com",
- 'description' => "fugafugafugafuga",
- 'image' => image,
- 'items' => items,
- 'textinput' => textinput,
- }
-
- channel = RDF::Channel.new(about)
- %w(title link description image items textinput).each do |x|
- channel.__send__("#{x}=", h[x])
- end
-
- doc = REXML::Document.new(make_RDF(<<-EOR))
-#{channel}
-<items>
-#{rss_item}
-</items>
-EOR
- 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 = h[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_channel_items
- item_link = "http://example.com/item"
-
- items = RDF::Channel::Items.new
- li = items.Seq.class::Li.new(item_link)
- items.Seq.lis << li
-
- 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)
- seq = i.elements[1]
- assert_equal("Seq", seq.name)
- assert_equal(@rdf_uri, seq.namespace)
-
- assert_equal(1, seq.elements.size)
- l = seq.elements[1]
- assert_equal("li", l.name)
- assert_equal(@rdf_uri, l.namespace)
- assert_equal(item_link, l.attributes["resource"])
- end
-
- def test_seq
- item_link = "http://example.com/item"
- seq = RDF::Seq.new
- li = seq.class::Li.new(item_link)
- seq.lis << li
-
- 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)
-
- assert_equal(1, s.elements.size)
- l = s.elements[1]
- assert_equal("li", l.name)
- assert_equal(@rdf_uri, l.namespace)
- assert_equal(item_link, l.attributes["resource"])
- 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"
- h = {
- '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}=", h[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(h[x], elem.text)
- end
- end
-
- def test_item
- about = "http://hoge.com"
- h = {
- 'title' => "fugafuga",
- 'link' => "http://hoge.com/fuga",
- 'description' => "hogehogehoge",
- }
-
- item = RDF::Item.new(about)
- %w(title link description).each do |x|
- item.__send__("#{x}=", h[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(h[x], elem.text)
- end
- end
-
- def test_textinput
- about = "http://hoge.com"
- h = {
- '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}=", h[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(h[x], elem.text)
- end
- end
-
- def test_to_xml
- rss = RSS::Parser.parse(make_sample_RDF)
- assert_equal(rss.to_s, rss.to_xml)
- assert_equal(rss.to_s, rss.to_xml("1.0"))
- rss09 = rss.to_xml("0.91") do |maker|
- maker.channel.language = "en-us"
- end
- rss09 = RSS::Parser.parse(rss09)
- assert_equal("0.91", rss09.rss_version)
- assert_equal(["rss", "0.91", nil], rss09.feed_info)
- rss20 = RSS::Parser.parse(rss.to_xml("2.0"))
- assert_equal("2.0", rss20.rss_version)
- assert_equal(["rss", "2.0", nil], rss20.feed_info)
-
- atom_xml = rss.to_xml("atom") do |maker|
- maker.channel.author = "Alice"
- maker.channel.updated ||= Time.now
- maker.items.each do |item|
- item.updated ||= Time.now
- end
- end
- atom = RSS::Parser.parse(atom_xml)
- assert_equal(["atom", "1.0", "feed"], atom.feed_info)
- end
- end
-end
diff --git a/test/rss/test_2.0.rb b/test/rss/test_2.0.rb
deleted file mode 100644
index 650f8350105..00000000000
--- a/test/rss/test_2.0.rb
+++ /dev/null
@@ -1,412 +0,0 @@
-# frozen_string_literal: false
-require "rexml/document"
-
-require_relative "rss-testcase"
-
-module RSS
- class TestRSS20Core < TestCase
-
- def setup
- @rss_version = "2.0"
- end
-
- def test_Rss
- version = "1.0"
- encoding = "UTF-8"
- standalone = false
-
- rss = Rss.new(@rss_version, version, encoding, standalone)
- setup_rss20(rss)
-
- doc = REXML::Document.new(rss.to_s(false))
-
- xmldecl = doc.xml_decl
-
- assert_equal(version, xmldecl.version)
- assert_equal(encoding, xmldecl.encoding.to_s)
- assert_equal(standalone, !xmldecl.standalone.nil?)
-
- assert_equal("", doc.root.namespace)
- assert_equal(@rss_version, doc.root.attributes["version"])
- end
-
- def test_not_displayed_xml_stylesheets
- rss = Rss.new(@rss_version)
- plain_rss = rss.to_s
- 3.times do
- rss.xml_stylesheets.push(XMLStyleSheet.new)
- assert_equal(plain_rss, rss.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|
- rss = Rss.new(@rss_version)
- setup_rss20(rss)
- assert_xml_stylesheet_pis(attrs_ary, rss)
- end
- end
-
- def test_channel
- h = {
- 'title' => "fugafuga",
- 'link' => "http://hoge.com",
- 'description' => "fugafugafugafuga",
-
- 'language' => "en-us",
- 'copyright' => "Copyright 2002, Spartanburg Herald-Journal",
- 'managingEditor' => "geo@herald.com (George Matesky)",
- 'webMaster' => "betty@herald.com (Betty Guernsey)",
- 'pubDate' => Time.parse("Sat, 07 Sep 2002 00:00:01 GMT"),
- 'lastBuildDate' => Time.parse("Sat, 07 Sep 2002 09:42:31 GMT"),
- 'generator' => "MightyInHouse Content System v2.3",
- 'docs' => "http://blogs.law.harvard.edu/tech/rss",
- 'ttl' => "60",
- 'rating' => '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))',
- }
- categories = [
- {
- :content => "Newspapers",
- },
- {
- :domain => "Syndic8",
- :content => "1765",
- }
- ]
-
- channel = Rss::Channel.new
-
- elems = %w(title link description language copyright
- managingEditor webMaster pubDate lastBuildDate
- generator docs ttl rating)
- elems.each do |x|
- value = h[x]
- value = value.rfc822 if %w(pubDate lastBuildDate).include?(x)
- channel.__send__("#{x}=", value)
- end
- categories.each do |cat|
- channel.categories << Rss::Channel::Category.new(cat[:domain],
- cat[:content])
- end
-
- doc = REXML::Document.new(make_rss20(channel.to_s))
- c = doc.root.elements[1]
-
- elems.each do |x|
- elem = c.elements[x]
- assert_equal(x, elem.name)
- assert_equal("", elem.namespace)
- expected = h[x]
- case x
- when "pubDate", "lastBuildDate"
- assert_equal(expected, Time.parse(elem.text))
- when "ttl"
- expected = channel.__send__(x)
- assert_equal(expected, elem.text.to_i)
- else
- assert_equal(expected, elem.text)
- end
- end
- categories.each_with_index do |cat, i|
- cat = cat.dup
- cat[:domain] ||= nil
- category = c.elements["category[#{i+1}]"]
- actual = {
- :domain => category.attributes["domain"],
- :content => category.text,
- }
- assert_equal(cat, actual)
- end
- end
-
- def test_channel_cloud
- cloud_params = {
- :domain => "rpc.sys.com",
- :port => "80",
- :path => "/RPC2",
- :registerProcedure => "myCloud.rssPleaseNotify",
- :protocol => "xml-rpc",
- }
- cloud = Rss::Channel::Cloud.new(cloud_params[:domain],
- cloud_params[:port],
- cloud_params[:path],
- cloud_params[:registerProcedure],
- cloud_params[:protocol])
- cloud_params[:port] = cloud.port
-
- doc = REXML::Document.new(cloud.to_s)
- cloud_elem = doc.root
-
- actual = {}
- cloud_elem.attributes.each do |name, value|
- value = value.to_i if name == "port"
- actual[name.intern] = value
- end
- assert_equal(cloud_params, actual)
- end
-
- def test_channel_image
- image_params = {
- :url => "http://hoge.com/hoge.png",
- :title => "fugafuga",
- :link => "http://hoge.com",
- :width => "144",
- :height => "400",
- :description => "an image",
- }
- image = Rss::Channel::Image.new(image_params[:url],
- image_params[:title],
- image_params[:link],
- image_params[:width],
- image_params[:height],
- image_params[:description])
-
- doc = REXML::Document.new(image.to_s)
- image_elem = doc.root
-
- image_params.each do |name, value|
- value = image.__send__(name)
- actual = image_elem.elements[name.to_s].text
- actual = actual.to_i if [:width, :height].include?(name)
- assert_equal(value, actual)
- end
- end
-
- def test_channel_textInput
- textInput_params = {
- :title => "fugafuga",
- :description => "text hoge fuga",
- :name => "hoge",
- :link => "http://hoge.com",
- }
- textInput = Rss::Channel::TextInput.new(textInput_params[:title],
- textInput_params[:description],
- textInput_params[:name],
- textInput_params[:link])
-
- doc = REXML::Document.new(textInput.to_s)
- input_elem = doc.root
-
- textInput_params.each do |name, value|
- actual = input_elem.elements[name.to_s].text
- assert_equal(value, actual)
- end
- end
-
- def test_channel_skip_days
- skipDays_values = [
- "Sunday",
- "Monday",
- ]
- skipDays = Rss::Channel::SkipDays.new
- skipDays_values.each do |value|
- skipDays.days << Rss::Channel::SkipDays::Day.new(value)
- end
-
- doc = REXML::Document.new(skipDays.to_s)
- days_elem = doc.root
-
- skipDays_values.each_with_index do |value, i|
- assert_equal(value, days_elem.elements[i + 1].text)
- end
- end
-
- def test_channel_skip_hours
- skipHours_values = [
- "0",
- "13",
- ]
- skipHours = Rss::Channel::SkipHours.new
- skipHours_values.each do |value|
- skipHours.hours << Rss::Channel::SkipHours::Hour.new(value)
- end
-
- doc = REXML::Document.new(skipHours.to_s)
- hours_elem = doc.root
-
- skipHours_values.each_with_index do |value, i|
- expected = skipHours.hours[i].content
- assert_equal(expected, hours_elem.elements[i + 1].text.to_i)
- end
- end
-
- def test_item
- h = {
- 'title' => "fugafuga",
- 'link' => "http://hoge.com/",
- 'description' => "text hoge fuga",
- 'author' => "oprah@oxygen.net",
- 'comments' => "http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290",
- 'pubDate' => Time.parse("Sat, 07 Sep 2002 00:00:01 GMT"),
- }
- categories = [
- {
- :content => "Newspapers",
- },
- {
- :domain => "Syndic8",
- :content => "1765",
- }
- ]
-
- channel = Rss::Channel.new
- channel.title = "title"
- channel.link = "http://example.com/"
- channel.description = "description"
-
- item = Rss::Channel::Item.new
- channel.items << item
-
- elems = %w(title link description author comments pubDate)
- elems.each do |x|
- value = h[x]
- value = value.rfc822 if x == "pubDate"
- item.__send__("#{x}=", value)
- end
- categories.each do |cat|
- item.categories << Rss::Channel::Category.new(cat[:domain],
- cat[:content])
- end
-
- doc = REXML::Document.new(channel.to_s)
- channel_elem = doc.root
-
- item_elem = channel_elem.elements["item[1]"]
- elems.each do |x|
- elem = item_elem.elements[x]
- assert_equal(x, elem.name)
- assert_equal("", elem.namespace)
- expected = h[x]
- case x
- when "pubDate"
- assert_equal(expected, Time.parse(elem.text))
- else
- assert_equal(expected, elem.text)
- end
- end
- categories.each_with_index do |cat, i|
- cat = cat.dup
- cat[:domain] ||= nil
- category = item_elem.elements["category[#{i+1}]"]
- actual = {
- :domain => category.attributes["domain"],
- :content => category.text,
- }
- assert_equal(cat, actual)
- end
- end
-
- def test_item_enclosure
- enclosure_params = {
- :url => "http://www.scripting.com/mp3s/weatherReportSuite.mp3",
- :length => "12216320",
- :type => "audio/mpeg",
- }
-
- enclosure = Rss::Channel::Item::Enclosure.new(enclosure_params[:url],
- enclosure_params[:length],
- enclosure_params[:type])
- enclosure_params[:length] = enclosure.length
-
- doc = REXML::Document.new(enclosure.to_s)
- enclosure_elem = doc.root
-
- actual = {}
- enclosure_elem.attributes.each do |name, value|
- value = value.to_i if name == "length"
- actual[name.intern] = value
- end
- assert_equal(enclosure_params, actual)
- end
-
- def test_item_guid
- test_params = [
- {
- :content => "http://some.server.com/weblogItem3207",
- },
- {
- :isPermaLink => "true",
- :content => "http://inessential.com/2002/09/01.php#a2",
- },
- ]
-
- test_params.each do |guid_params|
- guid = Rss::Channel::Item::Guid.new(guid_params[:isPermaLink],
- guid_params[:content])
- if guid_params.has_key?(:isPermaLink)
- guid_params[:isPermaLink] = guid.isPermaLink
- end
- if guid.isPermaLink.nil?
- assert_equal(true, guid.PermaLink?)
- else
- assert_equal(guid.isPermaLink, guid.PermaLink?)
- end
-
- doc = REXML::Document.new(guid.to_s)
- guid_elem = doc.root
-
- actual = {}
- actual[:content] = guid_elem.text if guid_elem.text
- guid_elem.attributes.each do |name, value|
- value = value == "true" if name == "isPermaLink"
- actual[name.intern] = value
- end
- assert_equal(guid_params, actual)
- end
- end
-
- def test_item_source
- source_params = {
- :url => "http://www.tomalak.org/links2.xml",
- :content => "Tomalak's Realm",
- }
-
- source = Rss::Channel::Item::Source.new(source_params[:url],
- source_params[:content])
-
- doc = REXML::Document.new(source.to_s)
- source_elem = doc.root
-
- actual = {}
- actual[:content] = source_elem.text
- source_elem.attributes.each do |name, value|
- actual[name.intern] = value
- end
- assert_equal(source_params, actual)
- end
-
- def test_to_xml
- rss = RSS::Parser.parse(make_sample_rss20)
- assert_equal(rss.to_s, rss.to_xml)
- assert_equal(rss.to_s, rss.to_xml("2.0"))
- rss09_xml = rss.to_xml("0.91") do |maker|
- setup_dummy_image(maker)
- end
- rss09 = RSS::Parser.parse(rss09_xml)
- assert_equal("0.91", rss09.rss_version)
- rss10 = rss.to_xml("1.0") do |maker|
- maker.channel.about = "http://www.example.com/index.rdf"
- end
- rss10 = RSS::Parser.parse(rss10)
- assert_equal("1.0", rss10.rss_version)
-
- atom_xml = rss.to_xml("atom1.0") do |maker|
- maker.channel.id = "http://www.example.com/atom.xml"
- maker.channel.author = "Alice"
- maker.channel.updated = Time.now
- maker.items.each do |item|
- item.author = "Bob"
- item.updated = Time.now
- end
- end
- atom = RSS::Parser.parse(atom_xml)
- assert_equal(["atom", "1.0", "feed"], atom.feed_info)
- end
- end
-end
diff --git a/test/rss/test_accessor.rb b/test/rss/test_accessor.rb
deleted file mode 100644
index 7d4424dbbdc..00000000000
--- a/test/rss/test_accessor.rb
+++ /dev/null
@@ -1,104 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss-testcase"
-
-require "rss/1.0"
-require "rss/2.0"
-require "rss/syndication"
-require "rss/image"
-
-module RSS
- class TestAccessor < TestCase
- def test_date
- channel = Rss::Channel.new
- channel.pubDate = nil
- assert_nil(channel.pubDate)
-
- time = Time.now
- channel.pubDate = time
- assert_equal(time, channel.pubDate)
-
- time = Time.parse(Time.now.rfc822)
- channel.pubDate = time.rfc822
- assert_equal(time, channel.pubDate)
-
- time = Time.parse(Time.now.iso8601)
- value = time.iso8601
- assert_not_available_value("pubDate", value) do
- channel.pubDate = value
- end
-
- channel.do_validate = false
- time = Time.parse(Time.now.iso8601)
- value = time.iso8601
- channel.pubDate = value
- assert_equal(time, channel.pubDate)
-
- channel.pubDate = nil
- assert_nil(channel.pubDate)
- end
-
- def test_integer
- image_item = RDF::Item::ImageItem.new
-
- image_item.width = nil
- assert_nil(image_item.width)
-
- width = 10
- image_item.width = width
- assert_equal(width, image_item.width)
-
- width = 10.0
- image_item.width = width
- assert_equal(width, image_item.width)
-
- width = "10"
- image_item.width = width
- assert_equal(width.to_i, image_item.width)
-
- width = "10.0"
- assert_not_available_value("image:width", width) do
- image_item.width = width
- end
-
- image_item.do_validate = false
- width = "10.0"
- image_item.width = width
- assert_equal(width.to_i, image_item.width)
-
- image_item.width = nil
- assert_nil(image_item.width)
- end
-
- def test_positive_integer
- channel = RDF::Channel.new
-
- channel.sy_updateFrequency = nil
- assert_nil(channel.sy_updateFrequency)
-
- freq = 10
- channel.sy_updateFrequency = freq
- assert_equal(freq, channel.sy_updateFrequency)
-
- freq = 10.0
- channel.sy_updateFrequency = freq
- assert_equal(freq, channel.sy_updateFrequency)
-
- freq = "10"
- channel.sy_updateFrequency = freq
- assert_equal(freq.to_i, channel.sy_updateFrequency)
-
- freq = "10.0"
- assert_not_available_value("sy:updateFrequency", freq) do
- channel.sy_updateFrequency = freq
- end
-
- channel.do_validate = false
- freq = "10.0"
- channel.sy_updateFrequency = freq
- assert_equal(freq.to_i, channel.sy_updateFrequency)
-
- channel.sy_updateFrequency = nil
- assert_nil(channel.sy_updateFrequency)
- end
- end
-end
diff --git a/test/rss/test_atom.rb b/test/rss/test_atom.rb
deleted file mode 100644
index 774064eff76..00000000000
--- a/test/rss/test_atom.rb
+++ /dev/null
@@ -1,684 +0,0 @@
-# frozen_string_literal: false
-require "rexml/document"
-
-require_relative "rss-testcase"
-
-require "rss/atom"
-
-module RSS
- class TestAtomCore < TestCase
- def setup
- @uri = "http://www.w3.org/2005/Atom"
- @xhtml_uri = "http://www.w3.org/1999/xhtml"
- end
-
- def test_feed
- version = "1.0"
- encoding = "UTF-8"
- standalone = false
-
- feed = Atom::Feed.new(version, encoding, standalone)
- assert_equal("", feed.to_s)
-
- author = feed.class::Author.new
- name = feed.class::Author::Name.new
- name.content = "an author"
- author.name = name
- assert_not_equal("", author.to_s)
- feed.authors << author
- assert_equal("", feed.to_s)
-
- id = feed.class::Id.new
- id.content = "http://example.com/atom.xml"
- assert_not_equal("", id.to_s)
- feed.id = id
- assert_equal("", feed.to_s)
-
- title = feed.class::Title.new
- title.content = "a title"
- assert_not_equal("", title.to_s)
- feed.title = title
- assert_equal("", feed.to_s)
-
- updated = feed.class::Updated.new
- updated.content = Time.now
- assert_not_equal("", updated.to_s)
- feed.updated = updated
- assert_not_equal("", feed.to_s)
-
-
- feed.authors.clear
- assert_equal("", feed.to_s)
- entry = Atom::Feed::Entry.new
- setup_entry(entry)
- assert_not_equal("", entry.to_s)
-
- author = entry.authors.first
- entry.authors.clear
- assert_equal("", entry.to_s)
- entry.parent = feed
- assert_equal("", entry.to_s)
- feed.authors << author
- assert_not_equal("", entry.to_s)
- feed.authors.clear
- feed.entries << entry
- assert_equal("", feed.to_s)
- entry.authors << author
- assert_not_equal("", entry.to_s)
- assert_not_equal("", feed.to_s)
-
- doc = REXML::Document.new(feed.to_s)
- xmldecl = doc.xml_decl
-
- assert_equal(version, xmldecl.version)
- assert_equal(encoding, xmldecl.encoding.to_s)
- assert_equal(standalone, !xmldecl.standalone.nil?)
-
- assert_equal(@uri, doc.root.namespace)
- end
-
- def test_entry
- version = "1.0"
- encoding = "UTF-8"
- standalone = false
-
- entry = Atom::Entry.new(version, encoding, standalone)
- setup_entry(entry)
-
- author = entry.authors.first
- entry.authors.clear
- assert_equal("", entry.to_s)
- source = Atom::Entry::Source.new
- source.authors << author
- entry.source = source
- assert_not_equal("", entry.to_s)
-
- doc = REXML::Document.new(entry.to_s)
- xmldecl = doc.xml_decl
-
- assert_equal(version, xmldecl.version)
- assert_equal(encoding, xmldecl.encoding.to_s)
- assert_equal(standalone, !xmldecl.standalone.nil?)
-
- assert_equal(@uri, doc.root.namespace)
- end
-
- def test_not_displayed_xml_stylesheets
- feed = Atom::Feed.new
- plain_feed = feed.to_s
- 3.times do
- feed.xml_stylesheets.push(XMLStyleSheet.new)
- assert_equal(plain_feed, feed.to_s)
- end
- end
-
- def test_atom_author
- assert_atom_person_to_s(Atom::Feed::Author)
- assert_atom_person_to_s(Atom::Feed::Entry::Author)
- assert_atom_person_to_s(Atom::Entry::Author)
- assert_atom_person_to_s(Atom::Feed::Entry::Source::Author)
- assert_atom_person_to_s(Atom::Entry::Source::Author)
- end
-
- def test_atom_category
- assert_atom_category_to_s(Atom::Feed::Category)
- assert_atom_category_to_s(Atom::Feed::Entry::Category)
- assert_atom_category_to_s(Atom::Entry::Category)
- assert_atom_category_to_s(Atom::Feed::Entry::Source::Category)
- assert_atom_category_to_s(Atom::Entry::Source::Category)
- end
-
- def test_atom_contributor
- assert_atom_person_to_s(Atom::Feed::Contributor)
- assert_atom_person_to_s(Atom::Feed::Entry::Contributor)
- assert_atom_person_to_s(Atom::Entry::Contributor)
- assert_atom_person_to_s(Atom::Feed::Entry::Source::Contributor)
- assert_atom_person_to_s(Atom::Entry::Source::Contributor)
- end
-
- def test_atom_generator
- assert_atom_generator_to_s(Atom::Feed::Generator)
- assert_atom_generator_to_s(Atom::Feed::Entry::Source::Generator)
- assert_atom_generator_to_s(Atom::Entry::Source::Generator)
- end
-
- def test_atom_icon
- assert_atom_icon_to_s(Atom::Feed::Icon)
- assert_atom_icon_to_s(Atom::Feed::Entry::Source::Icon)
- assert_atom_icon_to_s(Atom::Entry::Source::Icon)
- end
-
- def test_atom_id
- assert_atom_id_to_s(Atom::Feed::Id)
- assert_atom_id_to_s(Atom::Feed::Entry::Id)
- assert_atom_id_to_s(Atom::Entry::Id)
- assert_atom_id_to_s(Atom::Feed::Entry::Source::Id)
- assert_atom_id_to_s(Atom::Entry::Source::Id)
- end
-
- def test_atom_link
- assert_atom_link_to_s(Atom::Feed::Link)
- assert_atom_link_to_s(Atom::Feed::Entry::Link)
- assert_atom_link_to_s(Atom::Entry::Link)
- assert_atom_link_to_s(Atom::Feed::Entry::Source::Link)
- assert_atom_link_to_s(Atom::Entry::Source::Link)
- end
-
- def test_atom_logo
- assert_atom_logo_to_s(Atom::Feed::Logo)
- assert_atom_logo_to_s(Atom::Feed::Entry::Source::Logo)
- assert_atom_logo_to_s(Atom::Entry::Source::Logo)
- end
-
- def test_atom_rights
- assert_atom_text_construct_to_s(Atom::Feed::Rights)
- assert_atom_text_construct_to_s(Atom::Feed::Entry::Rights)
- assert_atom_text_construct_to_s(Atom::Entry::Rights)
- assert_atom_text_construct_to_s(Atom::Feed::Entry::Source::Rights)
- assert_atom_text_construct_to_s(Atom::Entry::Source::Rights)
- end
-
- def test_atom_subtitle
- assert_atom_text_construct_to_s(Atom::Feed::Subtitle)
- assert_atom_text_construct_to_s(Atom::Feed::Entry::Source::Subtitle)
- assert_atom_text_construct_to_s(Atom::Entry::Source::Subtitle)
- end
-
- def test_atom_title
- assert_atom_text_construct_to_s(Atom::Feed::Title)
- assert_atom_text_construct_to_s(Atom::Feed::Entry::Title)
- assert_atom_text_construct_to_s(Atom::Entry::Title)
- assert_atom_text_construct_to_s(Atom::Feed::Entry::Source::Title)
- assert_atom_text_construct_to_s(Atom::Entry::Source::Title)
- end
-
- def test_atom_updated
- assert_atom_date_construct_to_s(Atom::Feed::Updated)
- assert_atom_date_construct_to_s(Atom::Feed::Entry::Updated)
- assert_atom_date_construct_to_s(Atom::Entry::Updated)
- assert_atom_date_construct_to_s(Atom::Feed::Entry::Source::Updated)
- assert_atom_date_construct_to_s(Atom::Entry::Source::Updated)
- end
-
- def test_atom_content
- assert_atom_content_to_s(Atom::Feed::Entry::Content)
- assert_atom_content_to_s(Atom::Entry::Content)
- end
-
- def test_atom_published
- assert_atom_date_construct_to_s(Atom::Feed::Entry::Published)
- assert_atom_date_construct_to_s(Atom::Entry::Published)
- end
-
- def test_atom_summary
- assert_atom_text_construct_to_s(Atom::Feed::Entry::Summary)
- assert_atom_text_construct_to_s(Atom::Entry::Summary)
- end
-
-
- def test_to_xml(with_convenience_way=true)
- atom = RSS::Parser.parse(make_feed)
- assert_equal(atom.to_s, atom.to_xml)
- assert_equal(atom.to_s, atom.to_xml("atom"))
- assert_equal(atom.to_s, atom.to_xml("atom1.0"))
- assert_equal(atom.to_s, atom.to_xml("atom1.0:feed"))
- assert_equal(atom.to_s, atom.to_xml("atom:feed"))
-
- rss09_xml = atom.to_xml("0.91") do |maker|
- maker.channel.language = "en-us"
- maker.channel.link = "http://example.com/"
- if with_convenience_way
- maker.channel.description = atom.title.content
- else
- maker.channel.description {|d| d.content = atom.title.content}
- end
-
- maker.image.url = "http://example.com/logo.png"
- maker.image.title = "Logo"
- end
- rss09 = RSS::Parser.parse(rss09_xml)
- assert_equal(["rss", "0.91", nil], rss09.feed_info)
-
- rss20_xml = atom.to_xml("2.0") do |maker|
- maker.channel.link = "http://example.com/"
- if with_convenience_way
- maker.channel.description = atom.title.content
- else
- maker.channel.description {|d| d.content = atom.title.content}
- end
- end
- rss20 = RSS::Parser.parse(rss20_xml)
- assert_equal("2.0", rss20.rss_version)
- assert_equal(["rss", "2.0", nil], rss20.feed_info)
- end
-
- def test_to_xml_with_new_api_since_018
- test_to_xml(false)
- end
-
- private
- def setup_entry(entry)
- _wrap_assertion do
- assert_equal("", entry.to_s)
-
- author = entry.class::Author.new
- name = entry.class::Author::Name.new
- name.content = "an author"
- author.name = name
- assert_not_equal("", author.to_s)
- entry.authors << author
- assert_equal("", entry.to_s)
-
- id = entry.class::Id.new
- id.content = "http://example.com/atom.xml"
- assert_not_equal("", id.to_s)
- entry.id = id
- assert_equal("", entry.to_s)
-
- title = entry.class::Title.new
- title.content = "a title"
- assert_not_equal("", title.to_s)
- entry.title = title
- assert_equal("", entry.to_s)
-
- updated = entry.class::Updated.new
- updated.content = Time.now
- assert_not_equal("", updated.to_s)
- entry.updated = updated
- assert_not_equal("", entry.to_s)
- end
- end
-
-
- def assert_atom_person_to_s(target_class)
- _wrap_assertion do
- name = "A person"
- uri = "http://example.com/person/"
- email = "person@example.com"
-
- target = target_class.new
- assert_equal("", target.to_s)
-
- target = target_class.new
- person_name = target_class::Name.new
- person_name.content = name
- target.name = person_name
- xml_target = REXML::Document.new(target.to_s).root
- assert_equal(["name"], xml_target.elements.collect {|e| e.name})
- assert_equal([name], xml_target.elements.collect {|e| e.text})
-
- person_uri = target_class::Uri.new
- person_uri.content = uri
- target.uri = person_uri
- xml_target = REXML::Document.new(target.to_s).root
- assert_equal(["name", "uri"], xml_target.elements.collect {|e| e.name})
- assert_equal([name, uri], xml_target.elements.collect {|e| e.text})
-
- person_email = target_class::Email.new
- person_email.content = email
- target.email = person_email
- xml_target = REXML::Document.new(target.to_s).root
- assert_equal(["name", "uri", "email"],
- xml_target.elements.collect {|e| e.name})
- assert_equal([name, uri, email],
- xml_target.elements.collect {|e| e.text})
- end
- end
-
- def assert_atom_category_to_s(target_class)
- _wrap_assertion do
- term = "music"
- scheme = "http://example.com/music"
- label = "Music"
-
- category = target_class.new
- assert_equal("", category.to_s)
-
- category = target_class.new
- category.scheme = scheme
- assert_equal("", category.to_s)
-
- category = target_class.new
- category.label = label
- assert_equal("", category.to_s)
-
- category = target_class.new
- category.scheme = scheme
- category.label = label
- assert_equal("", category.to_s)
-
- category = target_class.new
- category.term = term
- xml = REXML::Document.new(category.to_s).root
- assert_rexml_element([], {"term" => term}, nil, xml)
-
- category = target_class.new
- category.term = term
- category.scheme = scheme
- xml = REXML::Document.new(category.to_s).root
- assert_rexml_element([], {"term" => term, "scheme" => scheme}, nil, xml)
-
- category = target_class.new
- category.term = term
- category.label = label
- xml = REXML::Document.new(category.to_s).root
- assert_rexml_element([], {"term" => term, "label" => label}, nil, xml)
-
- category = target_class.new
- category.term = term
- category.scheme = scheme
- category.label = label
- xml = REXML::Document.new(category.to_s).root
- attrs = {"term" => term, "scheme" => scheme, "label" => label}
- assert_rexml_element([], attrs, nil, xml)
- end
- end
-
- def assert_atom_generator_to_s(target_class)
- _wrap_assertion do
- content = "Feed generator"
- uri = "http://example.com/generator"
- version = "0.0.1"
-
- generator = target_class.new
- assert_equal("", generator.to_s)
-
- generator = target_class.new
- generator.uri = uri
- assert_equal("", generator.to_s)
-
- generator = target_class.new
- generator.version = version
- assert_equal("", generator.to_s)
-
- generator = target_class.new
- generator.uri = uri
- generator.version = version
- assert_equal("", generator.to_s)
-
- generator = target_class.new
- generator.content = content
- xml = REXML::Document.new(generator.to_s).root
- assert_rexml_element([], {}, content, xml)
-
- generator = target_class.new
- generator.content = content
- generator.uri = uri
- xml = REXML::Document.new(generator.to_s).root
- assert_rexml_element([], {"uri" => uri}, content, xml)
-
- generator = target_class.new
- generator.content = content
- generator.version = version
- xml = REXML::Document.new(generator.to_s).root
- assert_rexml_element([], {"version" => version}, content, xml)
-
- generator = target_class.new
- generator.content = content
- generator.uri = uri
- generator.version = version
- xml = REXML::Document.new(generator.to_s).root
- assert_rexml_element([], {"uri" => uri, "version" => version},
- content, xml)
- end
- end
-
- def assert_atom_icon_to_s(target_class)
- _wrap_assertion do
- content = "http://example.com/icon.png"
-
- icon = target_class.new
- assert_equal("", icon.to_s)
-
- icon = target_class.new
- icon.content = content
- xml = REXML::Document.new(icon.to_s).root
- assert_rexml_element([], {}, content, xml)
- end
- end
-
- def assert_atom_id_to_s(target_class)
- _wrap_assertion do
- content = "http://example.com/1"
-
- id = target_class.new
- assert_equal("", id.to_s)
-
- id = target_class.new
- id.content = content
- xml = REXML::Document.new(id.to_s).root
- assert_rexml_element([], {}, content, xml)
- end
- end
-
- def assert_atom_link_to_s(target_class)
- _wrap_assertion do
- href = "http://example.com/atom.xml"
- optvs = {
- 'rel' => "self",
- 'type' => "application/atom+xml",
- 'hreflang' => "ja",
- 'title' => "Atom Feed",
- 'length' => "801",
- }
-
- link = target_class.new
- assert_equal("", link.to_s)
-
- link = target_class.new
- link.href = href
- xml = REXML::Document.new(link.to_s).root
- assert_rexml_element([], {"href" => href}, nil, xml)
-
- optional_arguments = %w(rel type hreflang title length)
- optional_arguments.each do |name|
- rest = optional_arguments.reject {|x| x == name}
-
- link = target_class.new
- link.__send__("#{name}=", optvs[name])
- assert_equal("", link.to_s)
-
- rest.each do |n|
- link.__send__("#{n}=", optvs[n])
- assert_equal("", link.to_s)
- end
-
- link = target_class.new
- link.href = href
- link.__send__("#{name}=", optvs[name])
- attrs = [["href", href], [name, optvs[name]]]
- xml = REXML::Document.new(link.to_s).root
- assert_rexml_element([], attrs, nil, xml)
-
- rest.each do |n|
- link.__send__("#{n}=", optvs[n])
- attrs << [n, optvs[n]]
- xml = REXML::Document.new(link.to_s).root
- assert_rexml_element([], attrs, nil, xml)
- end
- end
- end
- end
-
- def assert_atom_logo_to_s(target_class)
- _wrap_assertion do
- content = "http://example.com/logo.png"
-
- logo = target_class.new
- assert_equal("", logo.to_s)
-
- logo = target_class.new
- logo.content = content
- xml = REXML::Document.new(logo.to_s).root
- assert_rexml_element([], {}, content, xml)
- end
- end
-
- def assert_atom_text_construct_to_s(target_class)
- _wrap_assertion do
- text_content = "plain text"
- html_content = "<em>#{text_content}</em>"
- xhtml_uri = "http://www.w3.org/1999/xhtml"
- xhtml_em = RSS::XML::Element.new("em", nil, xhtml_uri, {}, text_content)
- xhtml_content = RSS::XML::Element.new("div", nil, xhtml_uri,
- {"xmlns" => xhtml_uri},
- [xhtml_em])
-
- text = target_class.new
- assert_equal("", text.to_s)
-
- text = target_class.new
- text.type = "text"
- assert_equal("", text.to_s)
-
- text = target_class.new
- text.content = text_content
- xml = REXML::Document.new(text.to_s).root
- assert_rexml_element([], {}, text_content, xml)
-
- text = target_class.new
- text.type = "text"
- text.content = text_content
- xml = REXML::Document.new(text.to_s).root
- assert_rexml_element([], {"type" => "text"}, text_content, xml)
-
- text = target_class.new
- text.type = "html"
- text.content = html_content
- xml = REXML::Document.new(text.to_s).root
- assert_rexml_element([], {"type" => "html"}, html_content, xml)
-
- text = target_class.new
- text.type = "xhtml"
- text.content = xhtml_content
- assert_equal("", text.to_s)
-
- text = target_class.new
- text.type = "xhtml"
- text.__send__(target_class.xml_setter, xhtml_content)
- xml = REXML::Document.new(text.to_s).root
- assert_rexml_element([[xhtml_uri, "div"]], {"type" => "xhtml"},
- nil, xml)
- assert_rexml_element([[xhtml_uri, "em"]], nil, nil, xml.elements[1])
- assert_rexml_element([], {}, text_content, xml.elements[1].elements[1])
-
- text = target_class.new
- text.type = "xhtml"
- text.__send__(target_class.xml_setter, xhtml_em)
- xml = REXML::Document.new(text.to_s).root
- assert_rexml_element([[xhtml_uri, "div"]], {"type" => "xhtml"},
- nil, xml)
- assert_rexml_element([[xhtml_uri, "em"]], nil, nil, xml.elements[1])
- assert_rexml_element([], {}, text_content, xml.elements[1].elements[1])
- end
- end
-
- def assert_atom_date_construct_to_s(target_class)
- _wrap_assertion do
- date = target_class.new
- assert_equal("", date.to_s)
-
- [
- "2003-12-13T18:30:02Z",
- "2003-12-13T18:30:02.25Z",
- "2003-12-13T18:30:02+01:00",
- "2003-12-13T18:30:02.25+01:00",
- ].each do |content|
- date = target_class.new
- date.content = content
- xml = REXML::Document.new(date.to_s).root
- assert_rexml_element([], {}, content, xml, :time)
-
- date = target_class.new
- date.content = Time.parse(content)
- xml = REXML::Document.new(date.to_s).root
- assert_rexml_element([], {}, content, xml, :time)
- end
- end
- end
-
- def assert_atom_content_to_s(target_class)
- _wrap_assertion do
- assert_atom_text_construct_to_s(target_class)
- assert_atom_content_inline_other_xml_to_s(target_class)
- assert_atom_content_inline_other_text_to_s(target_class)
- assert_atom_content_inline_other_base64_to_s(target_class)
- assert_atom_content_out_of_line_to_s(target_class)
- end
- end
-
- def assert_atom_content_inline_other_xml_to_s(target_class)
- _wrap_assertion do
- content = target_class.new
- content.type = "text/xml"
- assert_equal("", content.to_s)
-
- content = target_class.new
- content.type = "text/xml"
- content.xml = RSS::XML::Element.new("em")
- xml = REXML::Document.new(content.to_s).root
- assert_rexml_element([["", "em"]], {"type" => "text/xml"}, nil, xml)
- end
- end
-
- def assert_atom_content_inline_other_text_to_s(target_class)
- _wrap_assertion do
- content = target_class.new
- content.type = "text/plain"
- assert_equal("", content.to_s)
-
- content = target_class.new
- content.type = "text/plain"
- content.xml = RSS::XML::Element.new("em")
- assert_equal("", content.to_s)
-
- content = target_class.new
- content.type = "text/plain"
- content.content = "content"
- xml = REXML::Document.new(content.to_s).root
- assert_rexml_element([], {"type" => "text/plain"}, "content", xml)
- end
- end
-
- def assert_atom_content_inline_other_base64_to_s(target_class)
- _wrap_assertion do
- type = "image/png"
- png_file = File.join(File.dirname(__FILE__), "dot.png")
- original_content = File.open(png_file, "rb") do |file|
- file.read.force_encoding("binary")
- end
-
- content = target_class.new
- content.type = type
- content.content = original_content
- xml = REXML::Document.new(content.to_s).root
- assert_rexml_element([], {"type" => type},
- [original_content].pack("m").delete("\n"),
- xml)
- end
- end
-
- def assert_atom_content_out_of_line_to_s(target_class)
- _wrap_assertion do
- type = "application/zip"
- src = "http://example.com/xxx.zip"
-
- content = target_class.new
- assert(!content.out_of_line?)
- content.src = src
- assert(content.out_of_line?)
- xml = REXML::Document.new(content.to_s).root
- assert_rexml_element([], {"src" => src}, nil, xml)
-
- content = target_class.new
- assert(!content.out_of_line?)
- content.type = type
- assert(!content.out_of_line?)
- content.src = src
- assert(content.out_of_line?)
- xml = REXML::Document.new(content.to_s).root
- assert_rexml_element([], {"type" => type, "src" => src}, nil, xml)
- end
- end
- end
-end
diff --git a/test/rss/test_content.rb b/test/rss/test_content.rb
deleted file mode 100644
index fc8269df129..00000000000
--- a/test/rss/test_content.rb
+++ /dev/null
@@ -1,105 +0,0 @@
-# frozen_string_literal: false
-require "cgi"
-require "rexml/document"
-
-require_relative "rss-testcase"
-
-require "rss/content"
-
-module RSS
- class TestContent < TestCase
- def setup
- @prefix = "content"
- @uri = "http://purl.org/rss/1.0/modules/content/"
-
- @elems = {
- :encoded => "<em>ATTENTION</em>",
- }
-
- @content_nodes = @elems.collect do |name, value|
- "<#{@prefix}:#{name}>#{CGI.escapeHTML(value.to_s)}</#{@prefix}:#{name}>"
- end.join("\n")
-
- @rss10_source = make_RDF(<<-EOR, {@prefix => @uri})
-#{make_channel()}
-#{make_image()}
-#{make_item(@content_nodes)}
-#{make_textinput()}
-EOR
-
- @rss10 = Parser.parse(@rss10_source)
-
-
- @rss20_source = make_rss20(<<-EOR, {@prefix => @uri})
-#{make_channel20(make_item20(@content_nodes))}
-EOR
-
- @rss20 = Parser.parse(@rss20_source)
- end
-
- def test_parser
- assert_nothing_raised do
- Parser.parse(@rss10_source)
- end
-
- assert_nothing_raised do
- Parser.parse(@rss20_source)
- end
-
- @elems.each do |tag, value|
- tag_name = "#{@prefix}:#{tag}"
- content_encodes = make_element(tag_name, {}, value) * 2
-
- assert_too_much_tag(tag.to_s, "item") do
- Parser.parse(make_RDF(<<-EOR, {@prefix => @uri}))
-#{make_channel}
-#{make_item(content_encodes)}
-EOR
- end
-
- assert_too_much_tag(tag.to_s, "item") do
- Parser.parse(make_rss20(<<-EOR, {@prefix => @uri}))
-#{make_channel20(make_item20(content_encodes))}
-EOR
- end
- end
- end
-
- def test_accessor
- new_value = {
- :encoded => "<![CDATA[<it>hoge</it>]]>",
- }
-
- @elems.each do |name, value|
- [@rss10, @rss20].each do |rss|
- meth = "#{RSS::CONTENT_PREFIX}_#{name}"
- parent = rss.items.last
- assert_equal(value, parent.__send__(meth))
- parent.__send__("#{meth}=", new_value[name].to_s)
- assert_equal(new_value[name], parent.__send__(meth))
- end
- end
- end
-
- def test_to_s
- @elems.each do |name, value|
- excepted = make_element("#{@prefix}:#{name}", {}, value)
- meth = "#{RSS::CONTENT_PREFIX}_#{name}_element"
- [@rss10, @rss20].each do |rss|
- assert_equal(excepted, rss.items.last.__send__(meth))
- end
- end
-
- [@rss10_source, @rss20_source].each do |source|
- REXML::Document.new(source).root.each_element do |parent|
- next unless parent.name != "item"
- 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
deleted file mode 100644
index 37ef1771993..00000000000
--- a/test/rss/test_dublincore.rb
+++ /dev/null
@@ -1,270 +0,0 @@
-# frozen_string_literal: false
-require "cgi"
-require "rexml/document"
-
-require_relative "rss-testcase"
-
-require "rss/1.0"
-require "rss/dublincore"
-
-module RSS
- class TestDublinCore < TestCase
- def setup
- @rss10_parents = [%w(channel), %w(image), %w(item), %w(textinput)]
-
- @rss10_source = make_RDF(<<-EOR, {DC_PREFIX => DC_URI})
-#{make_channel(DC_NODES)}
-#{make_image(DC_NODES)}
-#{make_item(DC_NODES)}
-#{make_textinput(DC_NODES)}
-EOR
-
- @rss20_parents = [%w(channel), %w(items last)]
-
- @rss20_source = make_rss20(<<-EOR, {DC_PREFIX => DC_URI})
-#{make_channel20(DC_NODES + make_item20(DC_NODES))}
-EOR
-
- @atom_feed_parents = [[], %w(entries last)]
-
- @atom_feed_source = make_feed(<<-EOR, {DC_PREFIX => DC_URI})
-#{DC_NODES}
-#{make_entry(DC_NODES)}
-EOR
-
- @atom_entry_parents = [[]]
-
- @atom_entry_source = make_entry_document(<<-EOR, {DC_PREFIX => DC_URI})
-#{DC_NODES}
-EOR
- end
-
- def test_parser
- rss10_maker = Proc.new do |content, xmlns|
- make_RDF(<<-EOR, xmlns)
-#{make_channel(content)}
-#{make_image(content)}
-#{make_item(content)}
-#{make_textinput(content)}
-EOR
- end
- assert_dc_parse(@rss10_source, @rss10_parents, false, &rss10_maker)
- assert_dc_parse(@rss10_source, @rss10_parents, true, &rss10_maker)
-
- rss20_maker = Proc.new do |content, xmlns|
- make_rss20(<<-EOR, xmlns)
-#{make_channel20(content + make_item20(content))}
-EOR
- end
- assert_dc_parse(@rss20_source, @rss20_parents, false, &rss20_maker)
- assert_dc_parse(@rss20_source, @rss20_parents, true, &rss20_maker)
-
- atom_feed_maker = Proc.new do |content, xmlns|
- make_feed(<<-EOR, xmlns)
-#{content}
-#{make_entry(content)}
-EOR
- end
- assert_dc_parse(@atom_feed_source, @atom_feed_parents, false,
- &atom_feed_maker)
- assert_dc_parse(@atom_feed_source, @atom_feed_parents, true,
- &atom_feed_maker)
-
- atom_entry_maker = Proc.new do |content, xmlns|
- make_entry_document(<<-EOR, xmlns)
-#{content}
-EOR
- end
- assert_dc_parse(@atom_entry_source, @atom_entry_parents, false,
- &atom_entry_maker)
- assert_dc_parse(@atom_entry_source, @atom_entry_parents, true,
- &atom_entry_maker)
- end
-
- def test_singular_accessor
- assert_dc_singular_accessor(@rss10_source, @rss10_parents)
- assert_dc_singular_accessor(@rss20_source, @rss20_parents)
- assert_dc_singular_accessor(@atom_feed_source, @atom_feed_parents)
- assert_dc_singular_accessor(@atom_entry_source, @atom_entry_parents)
- end
-
- def test_plural_accessor
- assert_dc_plural_accessor(@rss10_source, @rss10_parents, false)
- assert_dc_plural_accessor(@rss10_source, @rss10_parents, true)
-
- assert_dc_plural_accessor(@rss20_source, @rss20_parents, false)
- assert_dc_plural_accessor(@rss20_source, @rss20_parents, true)
-
- assert_dc_plural_accessor(@atom_feed_source, @atom_feed_parents, false)
- assert_dc_plural_accessor(@atom_feed_source, @atom_feed_parents, true)
-
- assert_dc_plural_accessor(@atom_entry_source, @atom_entry_parents, false)
- assert_dc_plural_accessor(@atom_entry_source, @atom_entry_parents, true)
- end
-
- def test_to_s
- assert_dc_to_s(@rss10_source, @rss10_parents, false)
- assert_dc_to_s(@rss10_source, @rss10_parents, true)
-
- targets = ["channel", "channel/item[3]"]
- assert_dc_to_s(@rss20_source, @rss20_parents, false, targets)
- assert_dc_to_s(@rss20_source, @rss20_parents, true, targets)
-
- targets = [".", "entry"]
- assert_dc_to_s(@atom_feed_source, @atom_feed_parents, false, targets)
- assert_dc_to_s(@atom_feed_source, @atom_feed_parents, true, targets)
-
- targets = ["."]
- assert_dc_to_s(@atom_entry_source, @atom_entry_parents, false, targets)
- assert_dc_to_s(@atom_entry_source, @atom_entry_parents, true, targets)
- end
-
- private
- def dc_plural_suffix(name, check_backward_compatibility)
- if name == :rights
- if check_backward_compatibility
- "es"
- else
- "_list"
- end
- else
- "s"
- end
- end
-
- def assert_dc_parse(source, parents, check_backward_compatibility, &maker)
- assert_nothing_raised do
- Parser.parse(source)
- end
-
- DC_ELEMENTS.each do |name, value|
- parents.each do |parent_readers|
- feed = nil
- assert_nothing_raised do
- tag = "#{DC_PREFIX}:#{name}"
- dc_content = "<#{tag}>#{value}</#{tag}>\n"
- dc_content *= 2
- feed = Parser.parse(maker.call(dc_content, {DC_PREFIX => DC_URI}))
- end
- parent = chain_reader(feed, parent_readers)
-
- plural_suffix = dc_plural_suffix(name, check_backward_compatibility)
- plural_reader = "dc_#{name}#{plural_suffix}"
- values = parent.__send__(plural_reader).collect(&:value)
- value = CGI.unescapeHTML(value) if value.kind_of?(String)
- assert_equal([value, value], values)
- end
- end
- end
-
- def assert_dc_singular_accessor(source, parents)
- feed = Parser.parse(source)
- new_value = "hoge"
-
- parents.each do |parent_readers|
- parent = chain_reader(feed, parent_readers)
- DC_ELEMENTS.each do |name, value|
- parsed_value = parent.__send__("dc_#{name}")
- value = CGI.unescapeHTML(value) if value.kind_of?(String)
- 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
- parent.__send__("dc_#{name}=", t.iso8601)
- assert_equal(t, parent.__send__("dc_#{name}"))
- if parent.class.method_defined?(:date_without_dc_date=)
- assert_nil(parent.date)
- else
- assert_equal(t, parent.date)
- end
-
- parent.date = value
- assert_equal(value, parent.date)
- assert_equal(value, parent.__send__("dc_#{name}"))
- else
- parent.__send__("dc_#{name}=", new_value)
- assert_equal(new_value, parent.__send__("dc_#{name}"))
- end
- end
- end
- end
-
- def assert_dc_plural_accessor(source, parents, check_backward_compatibility)
- feed = Parser.parse(source)
- new_value = "hoge"
-
- DC_ELEMENTS.each do |name, value|
- parents.each do |parent_readers|
- parent = chain_reader(feed, parent_readers)
- parsed_value = parent.__send__("dc_#{name}")
- value = CGI.unescapeHTML(value) if value.kind_of?(String)
- assert_equal(value, parsed_value)
-
- plural_suffix = dc_plural_suffix(name, check_backward_compatibility)
- plural_reader = "dc_#{name}#{plural_suffix}"
- klass_name = "DublinCore#{Utils.to_class_name(name.to_s)}"
- klass = DublinCoreModel.const_get(klass_name)
- if name == :date
- t = Time.iso8601("2003-01-01T02:30:23+09:00")
- class << t
- alias_method(:to_s, :iso8601)
- end
- elems = parent.__send__(plural_reader)
- elems << klass.new(t.iso8601)
- new_elems = parent.__send__(plural_reader)
- values = new_elems.collect{|x| x.value}
- assert_equal([parent.__send__("dc_#{name}"), t], values)
- else
- elems = parent.__send__(plural_reader)
- elems << klass.new(new_value)
- new_elems = parent.__send__(plural_reader)
- values = new_elems.collect{|x| x.value}
- assert_equal([parent.__send__("dc_#{name}"), new_value],
- values)
- end
- end
- end
- end
-
- def assert_dc_to_s(source, parents, check_backward_compatibility,
- targets=nil)
- feed = Parser.parse(source)
-
- DC_ELEMENTS.each do |name, value|
- excepted = "<#{DC_PREFIX}:#{name}>#{value}</#{DC_PREFIX}:#{name}>"
- parents.each do |parent_readers|
- parent = chain_reader(feed, parent_readers)
- assert_equal(excepted, parent.__send__("dc_#{name}_elements"))
- end
-
- plural_suffix = dc_plural_suffix(name, check_backward_compatibility)
- reader = "dc_#{name}#{plural_suffix}"
- excepted = Array.new(2, excepted).join("\n")
- parents.each do |parent_readers|
- parent = chain_reader(feed, parent_readers)
- elems = parent.__send__(reader)
- klass_name = "DublinCore#{Utils.to_class_name(name.to_s)}"
- klass = DublinCoreModel.const_get(klass_name)
- elems << klass.new(parent.__send__("dc_#{name}"))
- assert_equal(excepted, parent.__send__("dc_#{name}_elements"))
- end
- end
-
- targets ||= parents.collect do |parent_readers|
- parent_readers.first
- end
- feed_root = REXML::Document.new(source).root
- targets.each do |target_xpath|
- parent = feed_root.elements[target_xpath]
- parent.each_element do |elem|
- if elem.namespace == DC_URI
- assert_equal(elem.text,
- CGI.unescapeHTML(DC_ELEMENTS[elem.name.intern].to_s))
- end
- end
- end
- end
- end
-end
diff --git a/test/rss/test_image.rb b/test/rss/test_image.rb
deleted file mode 100644
index 0f1cd8c9e28..00000000000
--- a/test/rss/test_image.rb
+++ /dev/null
@@ -1,215 +0,0 @@
-# frozen_string_literal: false
-require "cgi"
-require "rexml/document"
-
-require_relative "rss-testcase"
-
-require "rss/1.0"
-require "rss/image"
-
-module RSS
- class TestImage < TestCase
-
- def setup
- @prefix = "image"
- @uri = "http://purl.org/rss/1.0/modules/image/"
-
- @favicon_attrs = {
- "rdf:about" => "http://www.kuro5hin.org/favicon.ico",
- "#{@prefix}:size" => "small",
- }
- @favicon_contents = {"dc:title" => "Kuro5hin",}
- @items = [
- [
- {
- "rdf:about" => "http://www.example.org/item.png",
- "rdf:resource" => "http://www.example.org/item",
- },
- {
- "dc:title" => "Example Image",
- "#{@prefix}:width" => "100",
- "#{@prefix}:height" => "65",
- },
- ],
- [
- {
- "rdf:about" => "http://www.kuro5hin.org/images/topics/culture.jpg",
- },
- {
- "dc:title" => "Culture",
- "#{@prefix}:width" => "80",
- "#{@prefix}:height" => "50",
- },
- ]
- ]
-
-
- @channel_nodes = make_element("#{@prefix}:favicon",
- @favicon_attrs,
- @favicon_contents)
- items = ""
- @items.each do |attrs, contents|
- image_item = make_element("#{@prefix}:item", attrs, contents)
- items << make_item(image_item)
- end
-
- @ns = {
- @prefix => @uri,
- DC_PREFIX => DC_URI,
- }
- @rss_source = make_RDF(<<-EOR, @ns)
-#{make_channel(@channel_nodes)}
-#{make_image}
-#{items}
-#{make_textinput}
-EOR
-
- @rss = Parser.parse(@rss_source)
- end
-
- def test_parser
- assert_nothing_raised do
- Parser.parse(@rss_source)
- end
-
- assert_too_much_tag("favicon", "channel") do
- Parser.parse(make_RDF(<<-EOR, @ns))
-#{make_channel(@channel_nodes * 2)}
-#{make_item}
-EOR
- end
-
- attrs = {"rdf:about" => "http://www.example.org/item.png"}
- contents = [["#{@prefix}:width", "80"]] * 5
- image_item = make_element("#{@prefix}:item", attrs, contents)
- assert_too_much_tag("width", "item") do
- Parser.parse(make_RDF(<<-EOR, @ns))
-#{make_channel}
-#{make_item(image_item)}
-EOR
- end
- end
-
- def test_favicon_accessor
- favicon = @rss.channel.image_favicon
- [
- %w(about rdf:about http://example.com/favicon.ico),
- %w(size image:size large),
- %w(image_size image:size medium),
- ].each do |name, full_name, new_value|
- assert_equal(@favicon_attrs[full_name], favicon.__send__(name))
- favicon.__send__("#{name}=", new_value)
- assert_equal(new_value, favicon.__send__(name))
- favicon.__send__("#{name}=", @favicon_attrs[full_name])
- assert_equal(@favicon_attrs[full_name], favicon.__send__(name))
- end
-
- %w(small medium large).each do |value|
- assert_nothing_raised do
- favicon.size = value
- favicon.image_size = value
- end
- end
-
- %w(aaa AAA SMALL MEDIUM LARGE).each do |value|
- args = ["#{@prefix}:favicon", value, "#{@prefix}:size"]
- assert_not_available_value(*args) do
- favicon.size = value
- end
- assert_not_available_value(*args) do
- favicon.image_size = value
- end
- end
-
- [
- %w(dc_title dc:title sample-favicon),
- ].each do |name, full_name, new_value|
- assert_equal(@favicon_contents[full_name], favicon.__send__(name))
- favicon.__send__("#{name}=", new_value)
- assert_equal(new_value, favicon.__send__(name))
- favicon.__send__("#{name}=", @favicon_contents[full_name])
- assert_equal(@favicon_contents[full_name], favicon.__send__(name))
- end
- end
-
- def test_item_accessor
- @rss.items.each_with_index do |item, i|
- image_item = item.image_item
- attrs, contents = @items[i]
- [
- %w(about rdf:about http://example.com/image.png),
- %w(resource rdf:resource http://example.com/),
- ].each do |name, full_name, new_value|
- assert_equal(attrs[full_name], image_item.__send__(name))
- image_item.__send__("#{name}=", new_value)
- assert_equal(new_value, image_item.__send__(name))
- image_item.__send__("#{name}=", attrs[full_name])
- assert_equal(attrs[full_name], image_item.__send__(name))
- end
-
- [
- ["width", "image:width", "111"],
- ["image_width", "image:width", "44"],
- ["height", "image:height", "222"],
- ["image_height", "image:height", "88"],
- ].each do |name, full_name, new_value|
- assert_equal(contents[full_name].to_i, image_item.__send__(name))
- image_item.__send__("#{name}=", new_value)
- assert_equal(new_value.to_i, image_item.__send__(name))
- image_item.__send__("#{name}=", contents[full_name])
- assert_equal(contents[full_name].to_i, image_item.__send__(name))
- end
-
- [
- ["dc_title", "dc:title", "sample-image"],
- ].each do |name, full_name, new_value|
- assert_equal(contents[full_name], image_item.__send__(name))
- image_item.__send__("#{name}=", new_value)
- assert_equal(new_value, image_item.__send__(name))
- image_item.__send__("#{name}=", contents[full_name])
- assert_equal(contents[full_name], image_item.__send__(name))
- end
- end
- end
-
- def test_favicon_to_s
- favicon = @rss.channel.image_favicon
- expected_xml = image_xmlns_container(make_element("#{@prefix}:favicon",
- @favicon_attrs,
- @favicon_contents))
- expected = REXML::Document.new(expected_xml)
- actual_xml = image_xmlns_container(favicon.to_s(false, ""))
- actual = REXML::Document.new(actual_xml)
- assert_equal(expected.to_s, actual.to_s)
- end
-
- def test_item_to_s
- @rss.items.each_with_index do |item, i|
- attrs, contents = @items[i]
- expected_xml = make_element("#{@prefix}:item", attrs, contents)
- expected_xml = image_xmlns_container(expected_xml)
- expected = REXML::Document.new(expected_xml)
- actual_xml = image_xmlns_container(item.image_item.to_s(false, ""))
- actual = REXML::Document.new(actual_xml)
-
- assert_equal(expected[0].attributes, actual[0].attributes)
-
- %w(image:height image:width dc:title).each do |name|
- actual_target = actual.elements["//#{name}"]
- expected_target = expected.elements["//#{name}"]
- assert_equal(expected_target.to_s, actual_target.to_s)
- end
- end
- end
-
- private
- def image_xmlns_container(content)
- xmlns_container({
- @prefix => @uri,
- "dc" => "http://purl.org/dc/elements/1.1/",
- "rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
- },
- content)
- end
- end
-end
diff --git a/test/rss/test_inherit.rb b/test/rss/test_inherit.rb
deleted file mode 100644
index 020f066c5f8..00000000000
--- a/test/rss/test_inherit.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss-testcase"
-
-require "rss/1.0"
-
-module RSS
- class TestInherit < TestCase
-
- class InheritedImage < RSS::RDF::Image
- def self.indent_size; 1; end
- def self.tag_name; 'image'; end
- end
-
- def setup
- @rss = make_RDF(<<-EOR)
-#{make_channel}
-#{make_image}
-#{make_item}
-#{make_textinput}
-EOR
- end
-
- def test_inherit
- rss = RSS::Parser.parse(@rss)
- orig_image = rss.image
- prefix = "[INHERIT]"
- image = InheritedImage.new("#{prefix} #{orig_image.about}")
- image.title = "#{prefix} #{orig_image.title}"
- image.url = "#{prefix} #{orig_image.url}"
- image.link = "#{prefix} #{orig_image.link}"
- rss.image = image
-
- new_rss = RSS::Parser.parse(rss.to_s)
- new_image = new_rss.image
- assert_equal("#{prefix} #{orig_image.about}", new_image.about)
- assert_equal("#{prefix} #{orig_image.title}", new_image.title)
- assert_equal("#{prefix} #{orig_image.url}", new_image.url)
- assert_equal("#{prefix} #{orig_image.link}", new_image.link)
- end
- end
-end
diff --git a/test/rss/test_itunes.rb b/test/rss/test_itunes.rb
deleted file mode 100644
index 4459d8bfc74..00000000000
--- a/test/rss/test_itunes.rb
+++ /dev/null
@@ -1,356 +0,0 @@
-# frozen_string_literal: false
-require "cgi"
-require "rexml/document"
-
-require_relative "rss-testcase"
-
-require "rss/2.0"
-require "rss/itunes"
-
-module RSS
- class TestITunes < TestCase
- def test_author
- assert_itunes_author(%w(channel)) do |content, xmlns|
- make_rss20(make_channel20(content), xmlns)
- end
-
- assert_itunes_author(%w(items last)) do |content, xmlns|
- make_rss20(make_channel20(make_item20(content)), xmlns)
- end
- end
-
- def test_block
- assert_itunes_block(%w(items last)) do |content, xmlns|
- make_rss20(make_channel20(make_item20(content)), xmlns)
- end
- end
-
- def test_category
- assert_itunes_category(%w(channel)) do |content, xmlns|
- make_rss20(make_channel20(content), xmlns)
- end
- end
-
- def test_image
- assert_itunes_image(%w(channel)) do |content, xmlns|
- make_rss20(make_channel20(content), xmlns)
- end
- end
-
- def test_duration
- assert_itunes_duration(%w(items last)) do |content, xmlns|
- make_rss20(make_channel20(make_item20(content)), xmlns)
- end
- end
-
- def test_explicit
- assert_itunes_explicit(%w(channel)) do |content, xmlns|
- make_rss20(make_channel20(content), xmlns)
- end
-
- assert_itunes_explicit(%w(items last)) do |content, xmlns|
- make_rss20(make_channel20(make_item20(content)), xmlns)
- end
- end
-
- def test_keywords
- assert_itunes_keywords(%w(channel)) do |content, xmlns|
- make_rss20(make_channel20(content), xmlns)
- end
-
- assert_itunes_keywords(%w(items last)) do |content, xmlns|
- make_rss20(make_channel20(make_item20(content)), xmlns)
- end
- end
-
- def test_new_feed_url
- assert_itunes_new_feed_url(%w(channel)) do |content, xmlns|
- make_rss20(make_channel20(content), xmlns)
- end
- end
-
- def test_owner
- assert_itunes_owner(%w(channel)) do |content, xmlns|
- make_rss20(make_channel20(content), xmlns)
- end
- end
-
- def test_subtitle
- assert_itunes_subtitle(%w(channel)) do |content, xmlns|
- make_rss20(make_channel20(content), xmlns)
- end
-
- assert_itunes_subtitle(%w(items last)) do |content, xmlns|
- make_rss20(make_channel20(make_item20(content)), xmlns)
- end
- end
-
- def test_summary
- assert_itunes_summary(%w(channel)) do |content, xmlns|
- make_rss20(make_channel20(content), xmlns)
- end
-
- assert_itunes_summary(%w(items last)) do |content, xmlns|
- make_rss20(make_channel20(make_item20(content)), xmlns)
- end
- end
-
- private
- def itunes_rss20_parse(content, &maker)
- xmlns = {"itunes" => "http://www.itunes.com/dtds/podcast-1.0.dtd"}
- rss20_xml = maker.call(content, xmlns)
- ::RSS::Parser.parse(rss20_xml)
- end
-
- def assert_itunes_author(readers, &rss20_maker)
- _wrap_assertion do
- author = "John Lennon"
- rss20 = itunes_rss20_parse(tag("itunes:author", author), &rss20_maker)
- target = chain_reader(rss20, readers)
- assert_equal(author, target.itunes_author)
- end
- end
-
- def _assert_itunes_block(value, boolean_value, readers, &rss20_maker)
- rss20 = itunes_rss20_parse(tag("itunes:block", value), &rss20_maker)
- target = chain_reader(rss20, readers)
- assert_equal(value, target.itunes_block)
- assert_equal(boolean_value, target.itunes_block?)
- end
-
- def assert_itunes_block(readers, &rss20_maker)
- _wrap_assertion do
- _assert_itunes_block("yes", true, readers, &rss20_maker)
- _assert_itunes_block("Yes", true, readers, &rss20_maker)
- _assert_itunes_block("no", false, readers, &rss20_maker)
- _assert_itunes_block("", false, readers, &rss20_maker)
- end
- end
-
- def _assert_itunes_category(categories, readers, &rss20_maker)
- cats = categories.collect do |category|
- if category.is_a?(Array)
- category, sub_category = category
- tag("itunes:category",
- tag("itunes:category", nil, {"text" => sub_category}),
- {"text" => category})
- else
- tag("itunes:category", nil, {"text" => category})
- end
- end.join
- rss20 = itunes_rss20_parse(cats, &rss20_maker)
- target = chain_reader(rss20, readers)
- actual_categories = target.itunes_categories.collect do |category|
- cat = category.text
- if category.itunes_categories.empty?
- cat
- else
- [cat, *category.itunes_categories.collect {|c| c.text}]
- end
- end
- assert_equal(categories, actual_categories)
- end
-
- def assert_itunes_category(readers, &rss20_maker)
- _wrap_assertion do
- _assert_itunes_category(["Audio Blogs"], readers, &rss20_maker)
- _assert_itunes_category([["Arts & Entertainment", "Games"]],
- readers, &rss20_maker)
- _assert_itunes_category([["Arts & Entertainment", "Games"],
- ["Technology", "Computers"],
- "Audio Blogs"],
- readers, &rss20_maker)
- end
- end
-
- def assert_itunes_image(readers, &rss20_maker)
- _wrap_assertion do
- url = "http://example.com/podcasts/everything/AllAboutEverything.jpg"
- content = tag("itunes:image", nil, {"href" => url})
- rss20 = itunes_rss20_parse(content, &rss20_maker)
- target = chain_reader(rss20, readers)
- assert_not_nil(target.itunes_image)
- assert_equal(url, target.itunes_image.href)
-
- assert_missing_attribute("image", "href") do
- content = tag("itunes:image")
- itunes_rss20_parse(content, &rss20_maker)
- end
- end
- end
-
- def _assert_itunes_duration(hour, minute, second, value,
- readers, &rss20_maker)
- content = tag("itunes:duration", value)
- rss20 = itunes_rss20_parse(content, &rss20_maker)
- duration = chain_reader(rss20, readers).itunes_duration
- assert_equal(value, duration.content)
- assert_equal(hour, duration.hour)
- assert_equal(minute, duration.minute)
- assert_equal(second, duration.second)
- end
-
- def _assert_itunes_duration_not_available_value(value, &rss20_maker)
- assert_not_available_value("duration", value) do
- content = tag("itunes:duration", value)
- itunes_rss20_parse(content, &rss20_maker)
- end
- end
-
- def assert_itunes_duration(readers, &rss20_maker)
- _wrap_assertion do
- _assert_itunes_duration(7, 14, 5, "07:14:05", readers, &rss20_maker)
- _assert_itunes_duration(7, 14, 5, "7:14:05", readers, &rss20_maker)
- _assert_itunes_duration(0, 4, 55, "04:55", readers, &rss20_maker)
- _assert_itunes_duration(0, 4, 5, "4:05", readers, &rss20_maker)
- _assert_itunes_duration(0, 0, 5, "5", readers, &rss20_maker)
- _assert_itunes_duration(0, 3, 15, "195", readers, &rss20_maker)
- _assert_itunes_duration(1, 0, 1, "3601", readers, &rss20_maker)
-
- _assert_itunes_duration_not_available_value("09:07:14:05", &rss20_maker)
- _assert_itunes_duration_not_available_value("10:5", &rss20_maker)
- _assert_itunes_duration_not_available_value("10:03:5", &rss20_maker)
- _assert_itunes_duration_not_available_value("10:3:05", &rss20_maker)
-
- _assert_itunes_duration_not_available_value("xx:xx:xx", &rss20_maker)
-
- _assert_itunes_duration_not_available_value("", &rss20_maker)
- end
- end
-
- def _assert_itunes_explicit(explicit, value, readers, &rss20_maker)
- content = tag("itunes:explicit", value)
- rss20 = itunes_rss20_parse(content, &rss20_maker)
- target = chain_reader(rss20, readers)
- assert_equal(value, target.itunes_explicit)
- assert_equal(explicit, target.itunes_explicit?)
- end
-
- def assert_itunes_explicit(readers, &rss20_maker)
- _wrap_assertion do
- _assert_itunes_explicit(true, "explicit", readers, &rss20_maker)
- _assert_itunes_explicit(true, "yes", readers, &rss20_maker)
- _assert_itunes_explicit(true, "true", readers, &rss20_maker)
- _assert_itunes_explicit(false, "clean", readers, &rss20_maker)
- _assert_itunes_explicit(false, "no", readers, &rss20_maker)
- _assert_itunes_explicit(false, "false", readers, &rss20_maker)
- _assert_itunes_explicit(nil, "invalid", readers, &rss20_maker)
- end
- end
-
- def _assert_itunes_keywords(keywords, value, readers, &rss20_maker)
- content = tag("itunes:keywords", value)
- rss20 = itunes_rss20_parse(content, &rss20_maker)
- target = chain_reader(rss20, readers)
- assert_equal(keywords, target.itunes_keywords)
- end
-
- def assert_itunes_keywords(readers, &rss20_maker)
- _wrap_assertion do
- _assert_itunes_keywords(["salt"], "salt", readers, &rss20_maker)
- _assert_itunes_keywords(["salt"], " salt ", readers, &rss20_maker)
- _assert_itunes_keywords(["salt", "pepper", "shaker", "exciting"],
- "salt, pepper, shaker, exciting",
- readers, &rss20_maker)
- _assert_itunes_keywords(["metric", "socket", "wrenches", "toolsalt"],
- "metric, socket, wrenches, toolsalt",
- readers, &rss20_maker)
- _assert_itunes_keywords(["olitics", "red", "blue", "state"],
- "olitics, red, blue, state",
- readers, &rss20_maker)
- end
- end
-
- def assert_itunes_new_feed_url(readers, &rss20_maker)
- _wrap_assertion do
- url = "http://newlocation.com/example.rss"
- content = tag("itunes:new-feed-url", url)
- rss20 = itunes_rss20_parse(content, &rss20_maker)
- target = chain_reader(rss20, readers)
- assert_equal(url, target.itunes_new_feed_url)
- end
- end
-
- def _assert_itunes_owner(name, email, readers, &rss20_maker)
- content = tag("itunes:owner",
- tag("itunes:name", name) + tag("itunes:email", email))
- rss20 = itunes_rss20_parse(content, &rss20_maker)
- owner = chain_reader(rss20, readers).itunes_owner
- assert_equal(name, owner.itunes_name)
- assert_equal(email, owner.itunes_email)
- end
-
- def assert_itunes_owner(readers, &rss20_maker)
- _wrap_assertion do
- _assert_itunes_owner("John Doe", "john.doe@example.com",
- readers, &rss20_maker)
-
- assert_missing_tag("name", "owner") do
- content = tag("itunes:owner")
- itunes_rss20_parse(content, &rss20_maker)
- end
-
- assert_missing_tag("name", "owner") do
- content = tag("itunes:owner",
- tag("itunes:email", "john.doe@example.com"))
- itunes_rss20_parse(content, &rss20_maker)
- end
-
- assert_missing_tag("email", "owner") do
- content = tag("itunes:owner", tag("itunes:name", "John Doe"))
- itunes_rss20_parse(content, &rss20_maker)
- end
- end
- end
-
- def _assert_itunes_subtitle(value, readers, &rss20_maker)
- content = tag("itunes:subtitle", value)
- rss20 = itunes_rss20_parse(content, &rss20_maker)
- target = chain_reader(rss20, readers)
- assert_equal(value, target.itunes_subtitle)
- end
-
- def assert_itunes_subtitle(readers, &rss20_maker)
- _wrap_assertion do
- _assert_itunes_subtitle("A show about everything", readers, &rss20_maker)
- _assert_itunes_subtitle("A short primer on table spices",
- readers, &rss20_maker)
- _assert_itunes_subtitle("Comparing socket wrenches is fun!",
- readers, &rss20_maker)
- _assert_itunes_subtitle("Red + Blue != Purple", readers, &rss20_maker)
- end
- end
-
- def _assert_itunes_summary(value, readers, &rss20_maker)
- content = tag("itunes:summary", value)
- rss20 = itunes_rss20_parse(content, &rss20_maker)
- target = chain_reader(rss20, readers)
- assert_equal(value, target.itunes_summary)
- end
-
- def assert_itunes_summary(readers, &rss20_maker)
- _wrap_assertion do
- _assert_itunes_summary("All About Everything is a show about " +
- "everything. Each week we dive into any " +
- "subject known to man and talk about it as " +
- "much as we can. Look for our Podcast in " +
- "the iTunes Music Store",
- readers, &rss20_maker)
- _assert_itunes_summary("This week we talk about salt and pepper " +
- "shakers, comparing and contrasting pour " +
- "rates, construction materials, and overall " +
- "aesthetics. Come and join the party!",
- readers, &rss20_maker)
- _assert_itunes_summary("This week we talk about metric vs. old " +
- "english socket wrenches. Which one is " +
- "better? Do you really need both? Get all " +
- "of your answers here.",
- readers, &rss20_maker)
- _assert_itunes_summary("This week we talk about surviving in a " +
- "Red state if you're a Blue person. Or " +
- "vice versa.",
- readers, &rss20_maker)
- end
- end
- end
-end
diff --git a/test/rss/test_maker_0.9.rb b/test/rss/test_maker_0.9.rb
deleted file mode 100644
index d07a724ab16..00000000000
--- a/test/rss/test_maker_0.9.rb
+++ /dev/null
@@ -1,477 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss-testcase"
-
-require "rss/maker"
-
-module RSS
- class TestMaker09 < TestCase
- def test_supported?
- assert(RSS::Maker.supported?("0.9"))
- assert(RSS::Maker.supported?("rss0.9"))
- assert(RSS::Maker.supported?("0.91"))
- assert(RSS::Maker.supported?("rss0.91"))
- assert(RSS::Maker.supported?("0.92"))
- assert(RSS::Maker.supported?("rss0.92"))
- assert(!RSS::Maker.supported?("0.93"))
- assert(!RSS::Maker.supported?("rss0.93"))
- end
-
- def test_find_class
- assert_equal(RSS::Maker::RSS091, RSS::Maker["0.91"])
- assert_equal(RSS::Maker::RSS091, RSS::Maker["rss0.91"])
- assert_equal(RSS::Maker::RSS092, RSS::Maker["0.9"])
- assert_equal(RSS::Maker::RSS092, RSS::Maker["0.92"])
- assert_equal(RSS::Maker::RSS092, RSS::Maker["rss0.92"])
- end
-
- def test_rss
- assert_raise(LocalJumpError) do
- RSS::Maker.make("0.91")
- end
-
- rss = RSS::Maker.make("0.9") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_image(maker)
- end
- assert_equal("0.92", rss.rss_version)
-
- rss = RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_image(maker)
- end
- assert_equal("0.91", rss.rss_version)
-
-
- rss = RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_image(maker)
-
- maker.encoding = "EUC-JP"
- end
- assert_equal("0.91", rss.rss_version)
- assert_equal("EUC-JP", rss.encoding)
-
- rss = RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_image(maker)
-
- maker.standalone = "yes"
- end
- assert_equal("0.91", rss.rss_version)
- assert_equal("yes", rss.standalone)
-
- rss = RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_image(maker)
-
- maker.encoding = "EUC-JP"
- maker.standalone = "yes"
- end
- assert_equal("0.91", rss.rss_version)
- assert_equal("EUC-JP", rss.encoding)
- assert_equal("yes", rss.standalone)
- end
-
- def test_channel
- title = "fugafuga"
- link = "http://hoge.com"
- description = "fugafugafugafuga"
- language = "ja"
- copyright = "foo"
- managingEditor = "bar"
- webMaster = "web master"
- rating = '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))'
- docs = "http://foo.com/doc"
- skipDays = [
- "Sunday",
- "Monday",
- ]
- skipHours = [
- "0",
- "13",
- ]
- pubDate = Time.now
- lastBuildDate = Time.now
-
- image_url = "http://example.com/logo.png"
- image_title = "Logo"
-
- rss = RSS::Maker.make("0.91") do |maker|
- maker.channel.title = title
- maker.channel.link = link
- maker.channel.description = description
- maker.channel.language = language
- maker.channel.copyright = copyright
- maker.channel.managingEditor = managingEditor
- maker.channel.webMaster = webMaster
- maker.channel.rating = rating
- maker.channel.docs = docs
- maker.channel.pubDate = pubDate
- maker.channel.lastBuildDate = lastBuildDate
-
- skipDays.each do |day|
- maker.channel.skipDays.new_day do |new_day|
- new_day.content = day
- end
- end
- skipHours.each do |hour|
- maker.channel.skipHours.new_hour do |new_hour|
- new_hour.content = hour
- end
- end
-
- maker.image.url = image_url
- maker.image.title = image_title
- end
- channel = rss.channel
-
- assert_equal(title, channel.title)
- assert_equal(link, channel.link)
- assert_equal(description, channel.description)
- assert_equal(language, channel.language)
- assert_equal(copyright, channel.copyright)
- assert_equal(managingEditor, channel.managingEditor)
- assert_equal(webMaster, channel.webMaster)
- assert_equal(rating, channel.rating)
- assert_equal(docs, channel.docs)
- assert_equal(pubDate, channel.pubDate)
- assert_equal(pubDate, channel.date)
- assert_equal(lastBuildDate, channel.lastBuildDate)
-
- skipDays.each_with_index do |day, i|
- assert_equal(day, channel.skipDays.days[i].content)
- end
- skipHours.each_with_index do |hour, i|
- assert_equal(hour.to_i, channel.skipHours.hours[i].content)
- end
-
- assert(channel.items.empty?)
-
- assert_equal(image_url, channel.image.url)
- assert_equal(image_title, channel.image.title)
- assert_equal(link, channel.image.link)
-
- assert_nil(channel.textInput)
- end
-
- def test_not_valid_channel
- title = "fugafuga"
- link = "http://hoge.com"
- description = "fugafugafugafuga"
- language = "ja"
-
- assert_not_set_error("maker.channel", %w(title)) do
- RSS::Maker.make("0.91") do |maker|
- # maker.channel.title = title
- maker.channel.link = link
- maker.channel.description = description
- maker.channel.language = language
- end
- end
-
- assert_not_set_error("maker.channel", %w(link)) do
- RSS::Maker.make("0.91") do |maker|
- maker.channel.title = title
- # maker.channel.link = link
- maker.channel.link = nil
- maker.channel.description = description
- maker.channel.language = language
- end
- end
-
- assert_not_set_error("maker.channel", %w(description)) do
- RSS::Maker.make("0.91") do |maker|
- maker.channel.title = title
- maker.channel.link = link
- # maker.channel.description = description
- maker.channel.language = language
- end
- end
-
- assert_not_set_error("maker.channel", %w(language)) do
- RSS::Maker.make("0.91") do |maker|
- maker.channel.title = title
- maker.channel.link = link
- maker.channel.description = description
- # maker.channel.language = language
- end
- end
- end
-
- def test_image
- title = "fugafuga"
- link = "http://hoge.com"
- url = "http://hoge.com/hoge.png"
- width = "144"
- height = "400"
- description = "an image"
-
- rss = RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
- maker.channel.link = link
-
- maker.image.title = title
- maker.image.url = url
- maker.image.width = width
- maker.image.height = height
- maker.image.description = description
- end
- image = rss.image
- assert_equal(title, image.title)
- assert_equal(link, image.link)
- assert_equal(url, image.url)
- assert_equal(width.to_i, image.width)
- assert_equal(height.to_i, image.height)
- assert_equal(description, image.description)
-
- assert_not_set_error("maker.channel", %w(description title language)) do
- RSS::Maker.make("0.91") do |maker|
- # setup_dummy_channel(maker)
- maker.channel.link = link
-
- maker.image.title = title
- maker.image.url = url
- maker.image.width = width
- maker.image.height = height
- maker.image.description = description
- end
- end
- end
-
- def test_not_valid_image
- title = "fugafuga"
- link = "http://hoge.com"
- url = "http://hoge.com/hoge.png"
- width = "144"
- height = "400"
- description = "an image"
-
- assert_not_set_error("maker.image", %w(title)) do
- RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
- maker.channel.link = link
-
- # maker.image.title = title
- maker.image.url = url
- maker.image.width = width
- maker.image.height = height
- maker.image.description = description
- end
- end
-
- assert_not_set_error("maker.channel", %w(link)) do
- RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
- # maker.channel.link = link
- maker.channel.link = nil
-
- maker.image.title = title
- maker.image.url = url
- maker.image.width = width
- maker.image.height = height
- maker.image.description = description
- end
- end
-
- assert_not_set_error("maker.image", %w(url)) do
- RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
- maker.channel.link = link
-
- maker.image.title = title
- # maker.image.url = url
- maker.image.width = width
- maker.image.height = height
- maker.image.description = description
- end
- end
- end
-
- def test_items(with_convenience_way=true)
- title = "TITLE"
- link = "http://hoge.com/"
- description = "text hoge fuga"
-
- rss = RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_image(maker)
- end
- assert(rss.channel.items.empty?)
-
- rss = RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
-
- maker.items.new_item do |item|
- item.title = title
- item.link = link
- # item.description = description
- end
-
- setup_dummy_image(maker)
- end
- assert_equal(1, rss.channel.items.size)
- item = rss.channel.items.first
- assert_equal(title, item.title)
- assert_equal(link, item.link)
- assert_nil(item.description)
-
- pubDate = Time.now
-
- item_size = 5
- rss = RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
-
- item_size.times do |i|
- maker.items.new_item do |_item|
- _item.title = "#{title}#{i}"
- _item.link = "#{link}#{i}"
- _item.description = "#{description}#{i}"
- _item.date = pubDate - i
- end
- end
- maker.items.do_sort = true
-
- setup_dummy_image(maker)
- end
- assert_equal(item_size, rss.items.size)
- rss.channel.items.each_with_index do |_item, i|
- assert_equal("#{title}#{i}", _item.title)
- assert_equal("#{link}#{i}", _item.link)
- assert_equal("#{description}#{i}", _item.description)
- end
-
- rss = RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
-
- item_size.times do |i|
- maker.items.new_item do |_item|
- _item.title = "#{title}#{i}"
- _item.link = "#{link}#{i}"
- _item.description = "#{description}#{i}"
- end
- end
- maker.items.do_sort = Proc.new do |x, y|
- if with_convenience_way
- y.title[-1] <=> x.title[-1]
- else
- y.title {|t| t.content[-1]} <=> x.title {|t| t.content[-1]}
- end
- end
-
- setup_dummy_image(maker)
- end
- assert_equal(item_size, rss.items.size)
- rss.channel.items.reverse.each_with_index do |_item, i|
- assert_equal("#{title}#{i}", _item.title)
- assert_equal("#{link}#{i}", _item.link)
- assert_equal("#{description}#{i}", _item.description)
- end
- end
-
- def test_items_with_new_api_since_018
- test_items(false)
- end
-
- def test_textInput
- title = "fugafuga"
- description = "text hoge fuga"
- name = "hoge"
- link = "http://hoge.com"
-
- rss = RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_image(maker)
-
- maker.textinput.title = title
- maker.textinput.description = description
- maker.textinput.name = name
- maker.textinput.link = link
- end
- textInput = rss.channel.textInput
- assert_equal(title, textInput.title)
- assert_equal(description, textInput.description)
- assert_equal(name, textInput.name)
- assert_equal(link, textInput.link)
-
- assert_not_set_error("maker.channel",
- %w(link language description title)) do
- RSS::Maker.make("0.91") do |maker|
- # setup_dummy_channel(maker)
-
- maker.textinput.title = title
- maker.textinput.description = description
- maker.textinput.name = name
- maker.textinput.link = link
- end
- end
- end
-
- def test_not_valid_textInput
- title = "fugafuga"
- description = "text hoge fuga"
- name = "hoge"
- link = "http://hoge.com"
-
- rss = RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_image(maker)
-
- # maker.textinput.title = title
- maker.textinput.description = description
- maker.textinput.name = name
- maker.textinput.link = link
- end
- assert_nil(rss.channel.textInput)
-
- rss = RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_image(maker)
-
- maker.textinput.title = title
- # maker.textinput.description = description
- maker.textinput.name = name
- maker.textinput.link = link
- end
- assert_nil(rss.channel.textInput)
-
- rss = RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_image(maker)
-
- maker.textinput.title = title
- maker.textinput.description = description
- # maker.textinput.name = name
- maker.textinput.link = link
- end
- assert_nil(rss.channel.textInput)
-
- rss = RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_image(maker)
-
- maker.textinput.title = title
- maker.textinput.description = description
- maker.textinput.name = name
- # maker.textinput.link = link
- end
- assert_nil(rss.channel.textInput)
- end
-
- def test_date_in_string
- date = Time.now
-
- rss = RSS::Maker.make("0.91") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_image(maker)
-
- maker.items.new_item do |item|
- item.title = "The first item"
- item.link = "http://example.com/blog/1.html"
- item.date = date.rfc822
- end
- end
-
- assert_equal(date.iso8601, rss.items[0].date.iso8601)
- end
- end
-end
diff --git a/test/rss/test_maker_1.0.rb b/test/rss/test_maker_1.0.rb
deleted file mode 100644
index f3c0e50cebc..00000000000
--- a/test/rss/test_maker_1.0.rb
+++ /dev/null
@@ -1,519 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss-testcase"
-
-require "rss/maker"
-
-module RSS
- class TestMaker10 < TestCase
- def test_supported?
- assert(RSS::Maker.supported?("1.0"))
- assert(RSS::Maker.supported?("rss1.0"))
- assert(!RSS::Maker.supported?("1.1"))
- assert(!RSS::Maker.supported?("rss1.1"))
- end
-
- def test_find_class
- assert_equal(RSS::Maker::RSS10, RSS::Maker["1.0"])
- assert_equal(RSS::Maker::RSS10, RSS::Maker["rss1.0"])
- end
-
- def test_rdf
- assert_raise(LocalJumpError) do
- RSS::Maker.make("1.0")
- end
-
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
- end
- assert_equal("1.0", rss.rss_version)
-
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
- maker.encoding = "EUC-JP"
-
- setup_dummy_item(maker)
- end
- assert_equal("1.0", rss.rss_version)
- assert_equal("EUC-JP", rss.encoding)
-
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
- maker.standalone = "yes"
-
- setup_dummy_item(maker)
- end
- assert_equal("1.0", rss.rss_version)
- assert_equal("yes", rss.standalone)
-
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
- maker.encoding = "EUC-JP"
- maker.standalone = "yes"
-
- setup_dummy_item(maker)
- end
- assert_equal("1.0", rss.rss_version)
- assert_equal("EUC-JP", rss.encoding)
- assert_equal("yes", rss.standalone)
- end
-
- def test_channel
- about = "http://hoge.com"
- title = "fugafuga"
- link = "http://hoge.com"
- description = "fugafugafugafuga"
-
- rss = RSS::Maker.make("1.0") do |maker|
- maker.channel.about = about
- maker.channel.title = title
- maker.channel.link = link
- maker.channel.description = description
-
- setup_dummy_item(maker)
- end
- channel = rss.channel
- assert_equal(about, channel.about)
- assert_equal(title, channel.title)
- assert_equal(link, channel.link)
- assert_equal(description, channel.description)
- assert_equal(1, channel.items.Seq.lis.size)
- assert_nil(channel.image)
- assert_nil(channel.textinput)
-
- rss = RSS::Maker.make("1.0") do |maker|
- maker.channel.about = about
- maker.channel.title = title
- maker.channel.link = link
- maker.channel.description = description
-
- setup_dummy_image(maker)
-
- setup_dummy_textinput(maker)
-
- setup_dummy_item(maker)
- end
- channel = rss.channel
- assert_equal(about, channel.about)
- assert_equal(title, channel.title)
- assert_equal(link, channel.link)
- assert_equal(description, channel.description)
- assert_equal(1, channel.items.Seq.lis.size)
- assert_equal(rss.image.about, channel.image.resource)
- assert_equal(rss.textinput.about, channel.textinput.resource)
- end
-
- def test_channel_language
- about = "http://hoge.com"
- title = "fugafuga"
- link = "http://hoge.com"
- description = "fugafugafugafuga"
- language = "ja"
-
- rss = RSS::Maker.make("1.0") do |maker|
- maker.channel.about = about
- maker.channel.title = title
- maker.channel.link = link
- maker.channel.description = description
- maker.channel.language = language
-
- setup_dummy_item(maker)
- end
- channel = rss.channel
- assert_equal(language, channel.dc_language)
- end
-
- def test_not_valid_channel
- about = "http://hoge.com"
- title = "fugafuga"
- link = "http://hoge.com"
- description = "fugafugafugafuga"
-
- assert_not_set_error("maker.channel", %w(about)) do
- RSS::Maker.make("1.0") do |maker|
- # maker.channel.about = about
- maker.channel.title = title
- maker.channel.link = link
- maker.channel.description = description
- end
- end
-
- assert_not_set_error("maker.channel", %w(title)) do
- RSS::Maker.make("1.0") do |maker|
- maker.channel.about = about
- # maker.channel.title = title
- maker.channel.link = link
- maker.channel.description = description
- end
- end
-
- assert_not_set_error("maker.channel", %w(link)) do
- RSS::Maker.make("1.0") do |maker|
- maker.channel.about = about
- maker.channel.title = title
- # maker.channel.link = link
- maker.channel.description = description
- end
- end
-
- assert_not_set_error("maker.channel", %w(description)) do
- RSS::Maker.make("1.0") do |maker|
- maker.channel.about = about
- maker.channel.title = title
- maker.channel.link = link
- # maker.channel.description = description
- end
- end
- end
-
-
- def test_image
- title = "fugafuga"
- link = "http://hoge.com"
- url = "http://hoge.com/hoge.png"
-
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
- maker.channel.link = link
-
- maker.image.title = title
- maker.image.url = url
-
- setup_dummy_item(maker)
- end
- image = rss.image
- assert_equal(url, image.about)
- assert_equal(url, rss.channel.image.resource)
- assert_equal(title, image.title)
- assert_equal(link, image.link)
- assert_equal(url, image.url)
-
- assert_not_set_error("maker.channel", %w(about title description)) do
- RSS::Maker.make("1.0") do |maker|
- # setup_dummy_channel(maker)
- maker.channel.link = link
-
- maker.image.title = title
- maker.image.url = url
- end
- end
- end
-
- def test_not_valid_image
- title = "fugafuga"
- link = "http://hoge.com"
- url = "http://hoge.com/hoge.png"
-
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
- maker.channel.link = link
-
- # maker.image.url = url
- maker.image.title = title
-
- setup_dummy_item(maker)
- end
- assert_nil(rss.channel.image)
- assert_nil(rss.image)
-
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
- maker.channel.link = link
-
- maker.image.url = url
- # maker.image.title = title
-
- setup_dummy_item(maker)
- end
- assert_nil(rss.channel.image)
- assert_nil(rss.image)
-
- assert_not_set_error("maker.channel", %w(link)) do
- RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
- # maker.channel.link = link
- maker.channel.link = nil
-
- maker.image.url = url
- maker.image.title = title
-
- setup_dummy_item(maker)
- end
- end
- end
-
- def test_items(with_convenience_way=true)
- title = "TITLE"
- link = "http://hoge.com/"
- description = "text hoge fuga"
-
- assert_not_set_error("maker", %w(items)) do
- RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
- end
- end
-
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.items.new_item do |item|
- item.title = title
- item.link = link
- # item.description = description
- end
- end
- assert_equal(1, rss.items.size)
- item = rss.items.first
- assert_equal(link, item.about)
- assert_equal(title, item.title)
- assert_equal(link, item.link)
- assert_nil(item.description)
-
- pubDate = Time.now
-
- item_size = 5
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
-
- item_size.times do |i|
- maker.items.new_item do |_item|
- _item.title = "#{title}#{i}"
- _item.link = "#{link}#{i}"
- _item.description = "#{description}#{i}"
- _item.date = pubDate - i
- end
- end
- maker.items.do_sort = true
- end
- assert_equal(item_size, rss.items.size)
- rss.items.each_with_index do |_item, i|
- assert_equal("#{link}#{i}", _item.about)
- assert_equal("#{title}#{i}", _item.title)
- assert_equal("#{link}#{i}", _item.link)
- assert_equal("#{description}#{i}", _item.description)
- end
-
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
-
- item_size.times do |i|
- maker.items.new_item do |_item|
- _item.title = "#{title}#{i}"
- _item.link = "#{link}#{i}"
- _item.description = "#{description}#{i}"
- end
- end
- maker.items.do_sort = Proc.new do |x, y|
- if with_convenience_way
- y.title[-1] <=> x.title[-1]
- else
- y.title {|t| t.content[-1]} <=> x.title {|t| t.content[-1]}
- end
- end
- end
- assert_equal(item_size, rss.items.size)
- rss.items.reverse.each_with_index do |_item, i|
- assert_equal("#{link}#{i}", _item.about)
- assert_equal("#{title}#{i}", _item.title)
- assert_equal("#{link}#{i}", _item.link)
- assert_equal("#{description}#{i}", _item.description)
- end
-
- max_size = item_size / 2
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
-
- item_size.times do |i|
- maker.items.new_item do |_item|
- _item.title = "#{title}#{i}"
- _item.link = "#{link}#{i}"
- _item.description = "#{description}#{i}"
- end
- end
- maker.items.max_size = max_size
- end
- assert_equal(max_size, rss.items.size)
- rss.items.each_with_index do |_item, i|
- assert_equal("#{link}#{i}", _item.about)
- assert_equal("#{title}#{i}", _item.title)
- assert_equal("#{link}#{i}", _item.link)
- assert_equal("#{description}#{i}", _item.description)
- end
-
- max_size = 0
- assert_not_set_error("maker", %w(items)) do
- RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
-
- item_size.times do |i|
- maker.items.new_item do |_item|
- _item.title = "#{title}#{i}"
- _item.link = "#{link}#{i}"
- _item.description = "#{description}#{i}"
- end
- end
- maker.items.max_size = max_size
- end
- end
-
- max_size = -2
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
-
- item_size.times do |i|
- maker.items.new_item do |_item|
- _item.title = "#{title}#{i}"
- _item.link = "#{link}#{i}"
- _item.description = "#{description}#{i}"
- end
- end
- maker.items.max_size = max_size
- end
- assert_equal(item_size + max_size + 1, rss.items.size)
- rss.items.each_with_index do |_item, i|
- assert_equal("#{link}#{i}", _item.about)
- assert_equal("#{title}#{i}", _item.title)
- assert_equal("#{link}#{i}", _item.link)
- assert_equal("#{description}#{i}", _item.description)
- end
- end
-
- def test_items_with_new_api_since_018
- test_items(false)
- end
-
- def test_not_valid_items
- title = "TITLE"
- link = "http://hoge.com/"
-
- assert_not_set_error("maker.item", %w(title)) do
- RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.items.new_item do |item|
- # item.title = title
- item.link = link
- end
- end
- end
-
- assert_not_set_error("maker.item", %w(link)) do
- RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.items.new_item do |item|
- item.title = title
- # item.link = link
- end
- end
- end
-
- assert_not_set_error("maker.item", %w(title link)) do
- RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.items.new_item do |item|
- # item.title = title
- # item.link = link
- end
- end
- end
- end
-
- def test_textinput
- title = "fugafuga"
- description = "text hoge fuga"
- name = "hoge"
- link = "http://hoge.com"
-
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.textinput.link = link
- maker.textinput.title = title
- maker.textinput.description = description
- maker.textinput.name = name
-
- setup_dummy_item(maker)
- end
- textinput = rss.textinput
- assert_equal(link, textinput.about)
- assert_equal(link, rss.channel.textinput.resource)
- assert_equal(title, textinput.title)
- assert_equal(name, textinput.name)
- assert_equal(description, textinput.description)
- assert_equal(link, textinput.link)
-
- assert_not_set_error("maker.channel", %w(about link description title)) do
- RSS::Maker.make("1.0") do |maker|
- # setup_dummy_channel(maker)
-
- maker.textinput.link = link
- maker.textinput.title = title
- maker.textinput.description = description
- maker.textinput.name = name
- end
- end
- end
-
- def test_not_valid_textinput
- title = "fugafuga"
- description = "text hoge fuga"
- name = "hoge"
- link = "http://hoge.com"
-
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
-
- # maker.textinput.link = link
- maker.textinput.title = title
- maker.textinput.description = description
- maker.textinput.name = name
-
- setup_dummy_item(maker)
- end
- assert_nil(rss.channel.textinput)
- assert_nil(rss.textinput)
-
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.textinput.link = link
- # maker.textinput.title = title
- maker.textinput.description = description
- maker.textinput.name = name
-
- setup_dummy_item(maker)
- end
- assert_nil(rss.channel.textinput)
- assert_nil(rss.textinput)
-
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.textinput.link = link
- maker.textinput.title = title
- # maker.textinput.description = description
- maker.textinput.name = name
-
- setup_dummy_item(maker)
- end
- assert_nil(rss.channel.textinput)
- assert_nil(rss.textinput)
-
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.textinput.link = link
- maker.textinput.title = title
- maker.textinput.description = description
- # maker.textinput.name = name
-
- setup_dummy_item(maker)
- end
- assert_nil(rss.channel.textinput)
- assert_nil(rss.textinput)
- end
-
- end
-end
diff --git a/test/rss/test_maker_2.0.rb b/test/rss/test_maker_2.0.rb
deleted file mode 100644
index f6d83f0c3d4..00000000000
--- a/test/rss/test_maker_2.0.rb
+++ /dev/null
@@ -1,758 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss-testcase"
-
-require "rss/maker"
-
-module RSS
- class TestMaker20 < TestCase
- def test_supported?
- assert(RSS::Maker.supported?("2.0"))
- assert(RSS::Maker.supported?("rss2.0"))
- assert(!RSS::Maker.supported?("2.2"))
- assert(!RSS::Maker.supported?("rss2.2"))
- end
-
- def test_find_class
- assert_equal(RSS::Maker::RSS20, RSS::Maker["2.0"])
- assert_equal(RSS::Maker::RSS20, RSS::Maker["rss2.0"])
- end
-
- def test_rss
- assert_raise(LocalJumpError) do
- RSS::Maker.make("2.0")
- end
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- end
- assert_equal("2.0", rss.rss_version)
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.encoding = "EUC-JP"
- end
- assert_equal("2.0", rss.rss_version)
- assert_equal("EUC-JP", rss.encoding)
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.standalone = "yes"
- end
- assert_equal("2.0", rss.rss_version)
- assert_equal("yes", rss.standalone)
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.encoding = "EUC-JP"
- maker.standalone = "yes"
- end
- assert_equal("2.0", rss.rss_version)
- assert_equal("EUC-JP", rss.encoding)
- assert_equal("yes", rss.standalone)
- end
-
- def test_channel
- title = "fugafuga"
- link = "http://hoge.com"
- description = "fugafugafugafuga"
- language = "ja"
- copyright = "foo"
- managingEditor = "bar"
- webMaster = "web master"
- rating = '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))'
- docs = "http://foo.com/doc"
- skipDays = [
- "Sunday",
- "Monday",
- ]
- skipHours = [
- "0",
- "13",
- ]
- pubDate = Time.now
- lastBuildDate = Time.now
- categories = [
- "Nespapers",
- "misc",
- ]
- generator = "RSS Maker"
- ttl = "60"
-
- rss = RSS::Maker.make("2.0") do |maker|
- maker.channel.title = title
- maker.channel.link = link
- maker.channel.description = description
- maker.channel.language = language
- maker.channel.copyright = copyright
- maker.channel.managingEditor = managingEditor
- maker.channel.webMaster = webMaster
- maker.channel.rating = rating
- maker.channel.docs = docs
- maker.channel.pubDate = pubDate
- maker.channel.lastBuildDate = lastBuildDate
-
- skipDays.each do |day|
- maker.channel.skipDays.new_day do |new_day|
- new_day.content = day
- end
- end
- skipHours.each do |hour|
- maker.channel.skipHours.new_hour do |new_hour|
- new_hour.content = hour
- end
- end
-
- categories.each do |category|
- maker.channel.categories.new_category do |new_category|
- new_category.content = category
- end
- end
-
- maker.channel.generator = generator
- maker.channel.ttl = ttl
- end
- channel = rss.channel
-
- assert_equal(title, channel.title)
- assert_equal(link, channel.link)
- assert_equal(description, channel.description)
- assert_equal(language, channel.language)
- assert_equal(copyright, channel.copyright)
- assert_equal(managingEditor, channel.managingEditor)
- assert_equal(webMaster, channel.webMaster)
- assert_equal(rating, channel.rating)
- assert_equal(docs, channel.docs)
- assert_equal(pubDate, channel.pubDate)
- assert_equal(pubDate, channel.date)
- assert_equal(lastBuildDate, channel.lastBuildDate)
-
- skipDays.each_with_index do |day, i|
- assert_equal(day, channel.skipDays.days[i].content)
- end
- skipHours.each_with_index do |hour, i|
- assert_equal(hour.to_i, channel.skipHours.hours[i].content)
- end
-
- channel.categories.each_with_index do |category, i|
- assert_equal(categories[i], category.content)
- end
-
- assert_equal(generator, channel.generator)
- assert_equal(ttl.to_i, channel.ttl)
-
- assert(channel.items.empty?)
- assert_nil(channel.image)
- assert_nil(channel.textInput)
- end
-
- def test_not_valid_channel
- title = "fugafuga"
- link = "http://hoge.com"
- description = "fugafugafugafuga"
- language = "ja"
-
- assert_not_set_error("maker.channel", %w(title)) do
- RSS::Maker.make("2.0") do |maker|
- # maker.channel.title = title
- maker.channel.link = link
- maker.channel.description = description
- maker.channel.language = language
- end
- end
-
- assert_not_set_error("maker.channel", %w(link)) do
- RSS::Maker.make("2.0") do |maker|
- maker.channel.title = title
- # maker.channel.link = link
- maker.channel.description = description
- maker.channel.language = language
- end
- end
-
- assert_not_set_error("maker.channel", %w(description)) do
- RSS::Maker.make("2.0") do |maker|
- maker.channel.title = title
- maker.channel.link = link
- # maker.channel.description = description
- maker.channel.language = language
- end
- end
-
- rss = RSS::Maker.make("2.0") do |maker|
- maker.channel.title = title
- maker.channel.link = link
- maker.channel.description = description
- # maker.channel.language = language
- end
- assert_not_nil(rss)
- end
-
-
- def test_cloud
- domain = "rpc.sys.com"
- port = "80"
- path = "/RPC2"
- registerProcedure = "myCloud.rssPleaseNotify"
- protocol = "xml-rpc"
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.channel.cloud.domain = domain
- maker.channel.cloud.port = port
- maker.channel.cloud.path = path
- maker.channel.cloud.registerProcedure = registerProcedure
- maker.channel.cloud.protocol = protocol
- end
- cloud = rss.channel.cloud
- assert_equal(domain, cloud.domain)
- assert_equal(port.to_i, cloud.port)
- assert_equal(path, cloud.path)
- assert_equal(registerProcedure, cloud.registerProcedure)
- assert_equal(protocol, cloud.protocol)
- end
-
- def test_not_valid_cloud
- domain = "rpc.sys.com"
- port = "80"
- path = "/RPC2"
- registerProcedure = "myCloud.rssPleaseNotify"
- protocol = "xml-rpc"
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- # maker.channel.cloud.domain = domain
- maker.channel.cloud.port = port
- maker.channel.cloud.path = path
- maker.channel.cloud.registerProcedure = registerProcedure
- maker.channel.cloud.protocol = protocol
- end
- assert_nil(rss.channel.cloud)
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.channel.cloud.domain = domain
- # maker.channel.cloud.port = port
- maker.channel.cloud.path = path
- maker.channel.cloud.registerProcedure = registerProcedure
- maker.channel.cloud.protocol = protocol
- end
- assert_nil(rss.channel.cloud)
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.channel.cloud.domain = domain
- maker.channel.cloud.port = port
- # maker.channel.cloud.path = path
- maker.channel.cloud.registerProcedure = registerProcedure
- maker.channel.cloud.protocol = protocol
- end
- assert_nil(rss.channel.cloud)
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.channel.cloud.domain = domain
- maker.channel.cloud.port = port
- maker.channel.cloud.path = path
- # maker.channel.cloud.registerProcedure = registerProcedure
- maker.channel.cloud.protocol = protocol
- end
- assert_nil(rss.channel.cloud)
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.channel.cloud.domain = domain
- maker.channel.cloud.port = port
- maker.channel.cloud.path = path
- maker.channel.cloud.registerProcedure = registerProcedure
- # maker.channel.cloud.protocol = protocol
- end
- assert_nil(rss.channel.cloud)
- end
-
-
- def test_image
- title = "fugafuga"
- link = "http://hoge.com"
- url = "http://hoge.com/hoge.png"
- width = "144"
- height = "400"
- description = "an image"
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- maker.channel.link = link
-
- maker.image.title = title
- maker.image.url = url
- maker.image.width = width
- maker.image.height = height
- maker.image.description = description
- end
- image = rss.image
- assert_equal(title, image.title)
- assert_equal(link, image.link)
- assert_equal(url, image.url)
- assert_equal(width.to_i, image.width)
- assert_equal(height.to_i, image.height)
- assert_equal(description, image.description)
-
- assert_not_set_error("maker.channel", %w(title description)) do
- RSS::Maker.make("2.0") do |maker|
- # setup_dummy_channel(maker)
- maker.channel.link = link
-
- maker.image.title = title
- maker.image.url = url
- maker.image.width = width
- maker.image.height = height
- maker.image.description = description
- end
- end
- end
-
- def test_not_valid_image
- title = "fugafuga"
- link = "http://hoge.com"
- url = "http://hoge.com/hoge.png"
- width = "144"
- height = "400"
- description = "an image"
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- maker.channel.link = link
-
- # maker.image.title = title
- maker.image.url = url
- maker.image.width = width
- maker.image.height = height
- maker.image.description = description
- end
- assert_nil(rss.image)
-
- assert_not_set_error("maker.channel", %w(link)) do
- RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- # maker.channel.link = link
- maker.channel.link = nil
-
- maker.image.title = title
- maker.image.url = url
- maker.image.width = width
- maker.image.height = height
- maker.image.description = description
- end
- end
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- maker.channel.link = link
-
- maker.image.title = title
- # maker.image.url = url
- maker.image.width = width
- maker.image.height = height
- maker.image.description = description
- end
- assert_nil(rss.image)
- end
-
- def test_items(with_convenience_way=true)
- title = "TITLE"
- link = "http://hoge.com/"
- description = "text hoge fuga"
- author = "oprah@oxygen.net"
- comments = "http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290"
- pubDate = Time.now
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- end
- assert(rss.channel.items.empty?)
-
- item_size = 5
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- item_size.times do |i|
- maker.items.new_item do |item|
- item.title = "#{title}#{i}"
- item.link = "#{link}#{i}"
- item.description = "#{description}#{i}"
- item.author = "#{author}#{i}"
- item.comments = "#{comments}#{i}"
- item.date = pubDate - i
- end
- end
- maker.items.do_sort = true
- end
- assert_equal(item_size, rss.items.size)
- rss.channel.items.each_with_index do |item, i|
- assert_equal("#{title}#{i}", item.title)
- assert_equal("#{link}#{i}", item.link)
- assert_equal("#{description}#{i}", item.description)
- assert_equal("#{author}#{i}", item.author)
- assert_equal("#{comments}#{i}", item.comments)
- assert_equal(pubDate - i, item.pubDate)
- assert_equal(pubDate - i, item.date)
- end
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- item_size.times do |i|
- maker.items.new_item do |item|
- item.title = "#{title}#{i}"
- item.link = "#{link}#{i}"
- item.description = "#{description}#{i}"
- item.author = "#{author}#{i}"
- item.comments = "#{comments}#{i}"
- item.date = pubDate
- end
- end
- maker.items.do_sort = Proc.new do |x, y|
- if with_convenience_way
- y.title[-1] <=> x.title[-1]
- else
- y.title {|t| t.content[-1]} <=> x.title {|t| t.content[-1]}
- end
- end
- end
- assert_equal(item_size, rss.items.size)
- rss.channel.items.reverse.each_with_index do |item, i|
- assert_equal("#{title}#{i}", item.title)
- assert_equal("#{link}#{i}", item.link)
- assert_equal("#{description}#{i}", item.description)
- assert_equal("#{author}#{i}", item.author)
- assert_equal("#{comments}#{i}", item.comments)
- assert_equal(pubDate, item.pubDate)
- assert_equal(pubDate, item.date)
- end
- end
-
- def test_items_with_new_api_since_018
- test_items(false)
- end
-
- def test_pubDate_without_description
- title = "TITLE"
- link = "http://hoge.com/"
- # description = "text hoge fuga"
- author = "oprah@oxygen.net"
- pubDate = Time.now
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.items.new_item do |item|
- item.title = title
- item.link = link
- # item.description = description
- item.author = author
- item.pubDate = pubDate
- end
- end
- assert_equal(1, rss.items.size)
- rss.channel.items.each_with_index do |item, i|
- assert_equal(title, item.title)
- assert_equal(link, item.link)
- # assert_equal(description, item.description)
- assert_equal(author, item.author)
- assert_equal(pubDate, item.pubDate)
- assert_equal(pubDate, item.date)
- end
- end
-
- def test_guid
- isPermaLink = "true"
- content = "http://inessential.com/2002/09/01.php#a2"
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- guid = maker.items.last.guid
- guid.isPermaLink = isPermaLink
- guid.content = content
- end
- guid = rss.channel.items.last.guid
- assert_equal(isPermaLink == "true", guid.isPermaLink)
- assert_equal(content, guid.content)
- end
-
- def test_guid_permanent_link
- content = "http://inessential.com/2002/09/01.php#a2"
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- guid = maker.items.last.guid
- assert_equal(nil, guid.permanent_link?)
- assert_equal(guid.isPermaLink, guid.permanent_link?)
- guid.permanent_link = true
- assert_equal(true, guid.permanent_link?)
- assert_equal(guid.isPermaLink, guid.permanent_link?)
- guid.content = content
- end
- guid = rss.channel.items.last.guid
- assert_equal(true, guid.isPermaLink)
- assert_equal(content, guid.content)
- end
-
- def test_guid_permanent_link_false
- content = "http://inessential.com/2002/09/01.php#a2"
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- guid = maker.items.last.guid
- assert_equal(nil, guid.permanent_link?)
- assert_equal(guid.isPermaLink, guid.permanent_link?)
- guid.permanent_link = false
- assert_equal(false, guid.permanent_link?)
- assert_equal(guid.isPermaLink, guid.permanent_link?)
- guid.content = content
- end
- guid = rss.channel.items.last.guid
- assert_equal(false, guid.isPermaLink)
- assert_equal(content, guid.content)
- end
-
- def test_not_valid_guid
- # content = "http://inessential.com/2002/09/01.php#a2"
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- # guid = maker.items.last.guid
- # guid.content = content
- end
- assert_nil(rss.channel.items.last.guid)
- end
-
- def test_enclosure
- url = "http://www.scripting.com/mp3s/weatherReportSuite.mp3"
- length = "12216320"
- type = "audio/mpeg"
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- enclosure = maker.items.last.enclosure
- enclosure.url = url
- enclosure.length = length
- enclosure.type = type
- end
- enclosure = rss.channel.items.last.enclosure
- assert_equal(url, enclosure.url)
- assert_equal(length.to_i, enclosure.length)
- assert_equal(type, enclosure.type)
- end
-
- def test_not_valid_enclosure
- url = "http://www.scripting.com/mp3s/weatherReportSuite.mp3"
- length = "12216320"
- type = "audio/mpeg"
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- enclosure = maker.items.last.enclosure
- # enclosure.url = url
- enclosure.length = length
- enclosure.type = type
- end
- assert_nil(rss.channel.items.last.enclosure)
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- enclosure = maker.items.last.enclosure
- enclosure.url = url
- # enclosure.length = length
- enclosure.type = type
- end
- assert_nil(rss.channel.items.last.enclosure)
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- enclosure = maker.items.last.enclosure
- enclosure.url = url
- enclosure.length = length
- # enclosure.type = type
- end
- assert_nil(rss.channel.items.last.enclosure)
- end
-
-
- def test_source
- url = "http://static.userland.com/tomalak/links2.xml"
- content = "Tomalak's Realm"
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- source = maker.items.last.source
- source.url = url
- source.content = content
- end
- source = rss.channel.items.last.source
- assert_equal(url, source.url)
- assert_equal(content, source.content)
- end
-
- def test_not_valid_source
- url = "http://static.userland.com/tomalak/links2.xml"
- content = "Tomalak's Realm"
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- source = maker.items.last.source
- # source.url = url
- source.content = content
- end
- assert_nil(rss.channel.items.last.source)
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- source = maker.items.last.source
- source.url = url
- # source.content = content
- end
- assert_nil(rss.channel.items.last.source)
- end
-
- def test_category
- domain = "http://www.fool.com/cusips"
- content = "MSFT"
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- maker.items.last.categories.new_category do |category|
- category.domain = domain
- category.content = content
- end
- end
- category = rss.channel.items.last.categories.last
- assert_equal(domain, category.domain)
- assert_equal(content, category.content)
- end
-
- def test_not_valid_category
- # content = "Grateful Dead"
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- maker.items.last.categories.new_category do |category|
- # category.content = content
- end
- end
- assert(rss.channel.items.last.categories.empty?)
- end
-
- def test_textInput
- title = "fugafuga"
- description = "text hoge fuga"
- name = "hoge"
- link = "http://hoge.com"
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.textinput.title = title
- maker.textinput.description = description
- maker.textinput.name = name
- maker.textinput.link = link
- end
- textInput = rss.channel.textInput
- assert_equal(title, textInput.title)
- assert_equal(description, textInput.description)
- assert_equal(name, textInput.name)
- assert_equal(link, textInput.link)
-
- assert_not_set_error("maker.channel", %w(link description title)) do
- RSS::Maker.make("2.0") do |maker|
- # setup_dummy_channel(maker)
-
- maker.textinput.title = title
- maker.textinput.description = description
- maker.textinput.name = name
- maker.textinput.link = link
- end
- end
- end
-
- def test_not_valid_textInput
- title = "fugafuga"
- description = "text hoge fuga"
- name = "hoge"
- link = "http://hoge.com"
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- # maker.textinput.title = title
- maker.textinput.description = description
- maker.textinput.name = name
- maker.textinput.link = link
- end
- assert_nil(rss.channel.textInput)
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.textinput.title = title
- # maker.textinput.description = description
- maker.textinput.name = name
- maker.textinput.link = link
- end
- assert_nil(rss.channel.textInput)
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.textinput.title = title
- maker.textinput.description = description
- # maker.textinput.name = name
- maker.textinput.link = link
- end
- assert_nil(rss.channel.textInput)
-
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- maker.textinput.title = title
- maker.textinput.description = description
- maker.textinput.name = name
- # maker.textinput.link = link
- end
- assert_nil(rss.channel.textInput)
- end
- end
-end
diff --git a/test/rss/test_maker_atom_entry.rb b/test/rss/test_maker_atom_entry.rb
deleted file mode 100644
index 8e41c7c50eb..00000000000
--- a/test/rss/test_maker_atom_entry.rb
+++ /dev/null
@@ -1,394 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss-testcase"
-
-require "rss/maker"
-
-module RSS
- class TestMakerAtomEntry < TestCase
- def test_supported?
- assert(RSS::Maker.supported?("atom:entry"))
- assert(RSS::Maker.supported?("atom1.0:entry"))
- assert(!RSS::Maker.supported?("atom2.0:entry"))
- end
-
- def test_find_class
- assert_equal(RSS::Maker::Atom::Entry, RSS::Maker["atom:entry"])
- assert_equal(RSS::Maker::Atom::Entry, RSS::Maker["atom1.0:entry"])
- end
-
- def test_root_element
- entry = Maker.make("atom:entry") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- assert_equal(["atom", "1.0", "entry"], entry.feed_info)
-
- entry = Maker.make("atom:entry") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- maker.encoding = "EUC-JP"
- end
- assert_equal(["atom", "1.0", "entry"], entry.feed_info)
- assert_equal("EUC-JP", entry.encoding)
-
- entry = Maker.make("atom:entry") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- maker.standalone = "yes"
- end
- assert_equal(["atom", "1.0", "entry"], entry.feed_info)
- assert_equal("yes", entry.standalone)
-
- entry = Maker.make("atom:entry") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- maker.encoding = "EUC-JP"
- maker.standalone = "yes"
- end
- assert_equal(["atom", "1.0", "entry"], entry.feed_info)
- assert_equal("EUC-JP", entry.encoding)
- assert_equal("yes", entry.standalone)
- end
-
- def test_invalid_feed
- assert_not_set_error("maker.item", %w(id title author updated)) do
- Maker.make("atom:entry") do |maker|
- end
- end
-
- assert_not_set_error("maker.item", %w(id title updated)) do
- Maker.make("atom:entry") do |maker|
- maker.channel.author = "foo"
- end
- end
-
- assert_not_set_error("maker.item", %w(title updated)) do
- Maker.make("atom:entry") do |maker|
- maker.channel.author = "foo"
- maker.channel.id = "http://example.com"
- end
- end
-
- assert_not_set_error("maker.item", %w(updated)) do
- Maker.make("atom:entry") do |maker|
- maker.channel.author = "foo"
- maker.channel.id = "http://example.com"
- maker.channel.title = "Atom Feed"
- end
- end
-
- assert_not_set_error("maker.item", %w(author)) do
- Maker.make("atom:entry") do |maker|
- maker.channel.id = "http://example.com"
- maker.channel.title = "Atom Feed"
- maker.channel.updated = Time.now
- end
- end
-
- entry = Maker.make("atom:entry") do |maker|
- maker.channel.author = "Foo"
- maker.channel.id = "http://example.com"
- maker.channel.title = "Atom Feed"
- maker.channel.updated = Time.now
- end
- assert_not_nil(entry)
- end
-
- def test_author
- assert_maker_atom_persons("entry",
- ["channel", "authors"],
- ["authors"],
- "maker.channel.author") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
-
- assert_maker_atom_persons("entry",
- ["items", "first", "authors"],
- ["authors"],
- "maker.item.author",
- "maker.item", ["author"]) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- maker.channel.authors.clear
- maker.items.first.authors.clear
- end
-
- assert_maker_atom_persons("entry",
- ["items", "first", "source", "authors"],
- ["source", "authors"],
- "maker.item.source.author") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_category
- assert_maker_atom_categories("entry",
- ["channel", "categories"],
- ["categories"],
- "maker.channel.category") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
-
- assert_maker_atom_categories("entry",
- ["items", "first", "categories"],
- ["categories"],
- "maker.item.category") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
-
- assert_maker_atom_categories("entry",
- ["items", "first", "source", "categories"],
- ["source", "categories"],
- "maker.item.source.category") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_content
- assert_maker_atom_content("entry",
- ["items", "first", "content"],
- ["content"],
- "maker.item.content") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_contributor
- assert_maker_atom_persons("entry",
- ["channel", "contributors"],
- ["contributors"],
- "maker.channel.contributor") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
-
- assert_maker_atom_persons("entry",
- ["items", "first", "contributors"],
- ["contributors"],
- "maker.item.contributor") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
-
- assert_maker_atom_persons("entry",
- ["items", "first", "source", "contributors"],
- ["source", "contributors"],
- "maker.item.source.contributor") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_link
- assert_maker_atom_links("entry",
- ["channel", "links"],
- ["links"],
- "maker.channel.link") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- maker.channel.links.clear
- maker.items.first.links.clear
- end
-
- assert_maker_atom_links("entry",
- ["items", "first", "links"],
- ["links"],
- "maker.item.link") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- maker.channel.links.clear
- maker.items.first.links.clear
- end
-
- assert_maker_atom_links("entry",
- ["items", "first", "source", "links"],
- ["source", "links"],
- "maker.item.source.link", true) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_published
- assert_maker_atom_date_construct("entry",
- ["items", "first", "published"],
- ["published"]
- ) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_rights
- assert_maker_atom_text_construct("entry",
- ["channel", "copyright"],
- ["rights"]) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
-
- assert_maker_atom_text_construct("entry",
- ["items", "first", "rights"],
- ["rights"],
- nil, nil, "maker.item.rights"
- ) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
-
- assert_maker_atom_text_construct("entry",
- ["items", "first", "source", "rights"],
- ["source", "rights"],
- nil, nil, "maker.item.source.rights"
- ) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
-
- def test_source_generator
- assert_maker_atom_generator("entry",
- ["items", "first", "source", "generator"],
- ["source", "generator"],
- "maker.item.source.generator") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_source_icon
- assert_maker_atom_icon("entry",
- ["items", "first", "source", "icon"],
- ["source", "icon"],
- nil, "maker.item.source.icon") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_source_id
- assert_maker_atom_id("entry",
- ["items", "first", "source"],
- ["source"],
- "maker.item.source") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_source_logo
- assert_maker_atom_logo("entry",
- ["items", "first", "source", "logo"],
- ["source", "logo"],
- nil,
- "maker.item.source.logo") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_source_subtitle
- assert_maker_atom_text_construct("entry",
- ["items", "first", "source", "subtitle"],
- ["source", "subtitle"],
- nil, nil,
- "maker.item.source.subtitle") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_summary
- assert_maker_atom_text_construct("entry",
- ["items", "first", "description"],
- ["summary"],
- nil, nil, "maker.item.description"
- ) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_title
- assert_maker_atom_text_construct("entry",
- ["channel", "title"], ["title"],
- "maker.item", ["title"],
- "maker.channel.title") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- maker.channel.title = nil
- maker.items.first.title = nil
- end
-
- assert_maker_atom_text_construct("entry",
- ["items", "first", "title"],
- ["title"],
- "maker.item", ["title"],
- "maker.item.title") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- maker.channel.title = nil
- maker.items.first.title = nil
- end
-
- assert_maker_atom_text_construct("entry",
- ["items", "first", "source", "title"],
- ["source", "title"],
- nil, nil, "maker.item.source.title"
- ) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_updated
- assert_maker_atom_date_construct("entry",
- ["channel", "updated"], ["updated"],
- "maker.item", ["updated"]) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- maker.channel.updated = nil
- maker.items.first.updated = nil
- end
-
- assert_maker_atom_date_construct("entry",
- ["items", "first", "updated"],
- ["updated"],
- "maker.item", ["updated"]) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- maker.channel.updated = nil
- maker.items.first.updated = nil
- end
-
- assert_maker_atom_date_construct("entry",
- ["items", "first", "source", "updated"],
- ["source", "updated"]) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_date
- date = Time.parse("2004/11/1 10:10")
- feed = Maker.make("atom:entry") do |maker|
- setup_dummy_channel_atom(maker)
- maker.channel.date = nil
- maker.items.new_item do |item|
- item.link = "http://example.com/article.html"
- item.title = "Sample Article"
- item.date = date
- end
- end
- assert_equal(date, feed.items[0].updated.content)
- assert_equal([date], feed.items[0].dc_dates.collect {|_date| _date.value})
- end
- end
-end
diff --git a/test/rss/test_maker_atom_feed.rb b/test/rss/test_maker_atom_feed.rb
deleted file mode 100644
index d4eacd36ad1..00000000000
--- a/test/rss/test_maker_atom_feed.rb
+++ /dev/null
@@ -1,455 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss-testcase"
-
-require "rss/maker"
-
-module RSS
- class TestMakerAtomFeed < TestCase
- def test_supported?
- assert(RSS::Maker.supported?("atom"))
- assert(RSS::Maker.supported?("atom:feed"))
- assert(RSS::Maker.supported?("atom1.0"))
- assert(RSS::Maker.supported?("atom1.0:feed"))
- assert(!RSS::Maker.supported?("atom2.0"))
- assert(!RSS::Maker.supported?("atom2.0:feed"))
- end
-
- def test_find_class
- assert_equal(RSS::Maker::Atom::Feed, RSS::Maker["atom"])
- assert_equal(RSS::Maker::Atom::Feed, RSS::Maker["atom:feed"])
- assert_equal(RSS::Maker::Atom::Feed, RSS::Maker["atom1.0"])
- assert_equal(RSS::Maker::Atom::Feed, RSS::Maker["atom1.0:feed"])
- end
-
- def test_root_element
- feed = Maker.make("atom") do |maker|
- setup_dummy_channel_atom(maker)
- end
- assert_equal(["atom", "1.0", "feed"], feed.feed_info)
-
- feed = Maker.make("atom") do |maker|
- setup_dummy_channel_atom(maker)
- maker.encoding = "EUC-JP"
- end
- assert_equal(["atom", "1.0", "feed"], feed.feed_info)
- assert_equal("EUC-JP", feed.encoding)
-
- feed = Maker.make("atom") do |maker|
- setup_dummy_channel_atom(maker)
- maker.standalone = "yes"
- end
- assert_equal(["atom", "1.0", "feed"], feed.feed_info)
- assert_equal("yes", feed.standalone)
-
- feed = Maker.make("atom") do |maker|
- setup_dummy_channel_atom(maker)
- maker.encoding = "EUC-JP"
- maker.standalone = "yes"
- end
- assert_equal(["atom", "1.0", "feed"], feed.feed_info)
- assert_equal("EUC-JP", feed.encoding)
- assert_equal("yes", feed.standalone)
- end
-
- def test_invalid_feed
- assert_not_set_error("maker.channel", %w(id title author updated)) do
- Maker.make("atom") do |maker|
- end
- end
-
- assert_not_set_error("maker.channel", %w(id title updated)) do
- Maker.make("atom") do |maker|
- maker.channel.author = "foo"
- end
- end
-
- assert_not_set_error("maker.channel", %w(title updated)) do
- Maker.make("atom") do |maker|
- maker.channel.author = "foo"
- maker.channel.id = "http://example.com"
- end
- end
-
- assert_not_set_error("maker.channel", %w(updated)) do
- Maker.make("atom") do |maker|
- maker.channel.author = "foo"
- maker.channel.id = "http://example.com"
- maker.channel.title = "Atom Feed"
- end
- end
-
- assert_not_set_error("maker.channel", %w(author)) do
- Maker.make("atom") do |maker|
- maker.channel.id = "http://example.com"
- maker.channel.title = "Atom Feed"
- maker.channel.updated = Time.now
- end
- end
-
- feed = Maker.make("atom") do |maker|
- maker.channel.author = "Foo"
- maker.channel.id = "http://example.com"
- maker.channel.title = "Atom Feed"
- maker.channel.updated = Time.now
- end
- assert_not_nil(feed)
- end
-
- def test_author
- assert_maker_atom_persons("feed",
- ["channel", "authors"],
- ["authors"],
- "maker.channel.author") do |maker|
- setup_dummy_channel_atom(maker)
- end
-
- assert_not_set_error("maker.channel", %w(author)) do
- RSS::Maker.make("atom") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- maker.channel.authors.clear
- end
- end
-
- assert_maker_atom_persons("feed",
- ["items", "first", "authors"],
- ["entries", "first", "authors"],
- "maker.item.author") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
-
- assert_maker_atom_persons("feed",
- ["items", "first", "source", "authors"],
- ["entries", "first", "source", "authors"],
- "maker.item.source.author") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_category
- assert_maker_atom_categories("feed",
- ["channel", "categories"],
- ["categories"],
- "maker.channel.category") do |maker|
- setup_dummy_channel_atom(maker)
- end
-
- assert_maker_atom_categories("feed",
- ["items", "first", "categories"],
- ["entries", "first", "categories"],
- "maker.item.category") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
-
- assert_maker_atom_categories("feed",
- ["items", "first", "source", "categories"],
- ["entries", "first", "source", "categories"],
- "maker.item.source.category") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_contributor
- assert_maker_atom_persons("feed",
- ["channel", "contributors"],
- ["contributors"],
- "maker.channel.contributor") do |maker|
- setup_dummy_channel_atom(maker)
- end
-
- assert_maker_atom_persons("feed",
- ["items", "first", "contributors"],
- ["entries", "first", "contributors"],
- "maker.item.contributor") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
-
- assert_maker_atom_persons("feed",
- ["items", "first", "source", "contributors"],
- ["entries", "first", "source", "contributors"],
- "maker.item.source.contributor") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_generator
- assert_maker_atom_generator("feed",
- ["channel", "generator"],
- ["generator"]) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
-
- assert_maker_atom_generator("feed",
- ["items", "first", "source", "generator"],
- ["entries", "first", "source", "generator"],
- "maker.item.source.generator") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_icon
- assert_maker_atom_icon("feed", ["channel"], ["icon"], "icon") do |maker|
- setup_dummy_channel_atom(maker)
- end
-
- assert_maker_atom_icon("feed",
- ["items", "first", "source", "icon"],
- ["entries", "first", "source", "icon"],
- nil, "maker.item.source.icon") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_link
- assert_maker_atom_links("feed",
- ["channel", "links"],
- ["links"],
- "maker.channel.link") do |maker|
- setup_dummy_channel_atom(maker)
- end
-
- assert_maker_atom_links("feed",
- ["items", "first", "links"],
- ["entries", "first", "links"],
- "maker.item.link") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
-
- assert_maker_atom_links("feed",
- ["items", "first", "source", "links"],
- ["entries", "first", "source", "links"],
- "maker.item.source.link", true) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_logo
- assert_maker_atom_logo("feed", ["channel"], ["logo"], "logo") do |maker|
- setup_dummy_channel_atom(maker)
- end
-
- assert_maker_atom_logo("feed", ["image"], ["logo"], "url") do |maker|
- setup_dummy_channel_atom(maker)
- end
-
- assert_maker_atom_logo("feed",
- ["items", "first", "source", "logo"],
- ["entries", "first", "source", "logo"],
- nil, "maker.item.source.logo") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_rights
- assert_maker_atom_text_construct("feed",
- ["channel", "copyright"],
- ["rights"]) do |maker|
- setup_dummy_channel_atom(maker)
- end
-
- assert_maker_atom_text_construct("feed",
- ["items", "first", "rights"],
- ["entries", "first", "rights"],
- nil, nil, "maker.item.rights"
- ) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
-
- assert_maker_atom_text_construct("feed",
- ["items", "first", "source", "rights"],
- ["entries", "first", "source", "rights"],
- nil, nil, "maker.item.source.rights"
- ) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_subtitle
- assert_maker_atom_text_construct("feed",
- ["channel", "subtitle"],
- ["subtitle"],
- nil, nil,
- "maker.channel.description") do |maker|
- setup_dummy_channel_atom(maker)
- maker.channel.description = nil
- end
-
- assert_maker_atom_text_construct("feed",
- ["channel", "subtitle"],
- ["subtitle"],
- nil, nil,
- "maker.channel.description") do |maker|
- setup_dummy_channel_atom(maker)
- maker.channel.description {|d| d.content = nil}
- end
-
- assert_maker_atom_text_construct("feed",
- ["items", "first", "source", "subtitle"],
- ["entries", "first",
- "source", "subtitle"],
- nil, nil,
- "maker.item.source.subtitle") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_title
- assert_maker_atom_text_construct("feed",
- ["channel", "title"], ["title"],
- "maker.channel", ["title"]) do |maker|
- setup_dummy_channel_atom(maker)
- maker.channel.title = nil
- end
-
- assert_maker_atom_text_construct("feed",
- ["items", "first", "title"],
- ["entries", "first", "title"],
- "maker.item", ["title"],
- "maker.item.title") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- maker.items.first.title = nil
- end
-
- assert_maker_atom_text_construct("feed",
- ["items", "first", "source", "title"],
- ["entries", "first", "source", "title"],
- nil, nil, "maker.item.source.title"
- ) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_updated
- assert_maker_atom_date_construct("feed",
- ["channel", "updated"], ["updated"],
- "maker.channel", ["updated"]) do |maker|
- setup_dummy_channel_atom(maker)
- maker.channel.updated = nil
- end
-
- assert_maker_atom_date_construct("feed",
- ["items", "first", "updated"],
- ["entries", "first", "updated"],
- "maker.item", ["updated"]) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- maker.items.first.updated = nil
- end
-
- assert_maker_atom_date_construct("feed",
- ["items", "first", "source", "updated"],
- ["entries", "first", "source", "updated"]
- ) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_published
- assert_maker_atom_date_construct("feed",
- ["items", "first", "published"],
- ["entries", "first", "published"]
- ) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_summary
- assert_maker_atom_text_construct("feed",
- ["items", "first", "description"],
- ["entries", "first", "summary"],
- nil, nil, "maker.item.description"
- ) do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_content
- assert_maker_atom_content("feed",
- ["items", "first", "content"],
- ["entries", "first", "content"],
- "maker.item.content") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_id
- assert_maker_atom_id("feed",
- ["items", "first", "source"],
- ["entries", "first", "source"],
- "maker.item.source") do |maker|
- setup_dummy_channel_atom(maker)
- setup_dummy_item_atom(maker)
- end
- end
-
- def test_language
- language = "ja"
- feed = Maker.make("atom") do |maker|
- setup_dummy_channel_atom(maker)
- maker.channel.language = "ja"
- end
- assert_equal(language, feed.dc_language)
- end
-
- def test_date
- date = Time.parse("2004/11/1 10:10")
- feed = Maker.make("atom") do |maker|
- setup_dummy_channel_atom(maker)
- maker.items.new_item do |item|
- item.link = "http://example.com/article.html"
- item.title = "sample article"
- item.date = date
- end
- end
- assert_equal(date, feed.items[0].updated.content)
- assert_equal([date], feed.items[0].dc_dates.collect {|_date| _date.value})
- end
-
- def test_channel_dc_date
- date = Time.parse("2004/11/1 10:10")
- feed = Maker.make("atom") do |maker|
- setup_dummy_channel_atom(maker)
- maker.channel.updated = nil
- maker.channel.dc_date = date
- setup_dummy_item_atom(maker)
- end
- assert_equal(date, feed.updated.content)
- assert_equal([date], feed.dc_dates.collect {|_date| _date.value})
- end
-
- def test_item_dc_date
- date = Time.parse("2004/11/1 10:10")
- feed = Maker.make("atom") do |maker|
- setup_dummy_channel_atom(maker)
- maker.items.new_item do |item|
- item.link = "http://example.com/article.html"
- item.title = "sample article"
- item.dc_date = date
- end
- end
- assert_equal(date, feed.items[0].updated.content)
- assert_equal([date], feed.items[0].dc_dates.collect {|_date| _date.value})
- end
- end
-end
diff --git a/test/rss/test_maker_content.rb b/test/rss/test_maker_content.rb
deleted file mode 100644
index e3b84c53a41..00000000000
--- a/test/rss/test_maker_content.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss-testcase"
-
-require "rss/maker"
-
-module RSS
- class TestMakerContent < TestCase
-
- def setup
- @uri = "http://purl.org/rss/1.0/modules/content/"
-
- @elements = {
- :encoded => "<em>ATTENTION</em>",
- }
- end
-
- def test_rss10
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
-
- setup_dummy_item(maker)
- item = maker.items.last
- @elements.each do |name, value|
- item.__send__("#{accessor_name(name)}=", value)
- end
- end
- assert_content(@elements, rss.items.last)
- end
-
- def test_rss20
- rss = RSS::Maker.make("2.0") do |maker|
- setup_dummy_channel(maker)
-
- setup_dummy_item(maker)
- item = maker.items.last
- @elements.each do |name, value|
- item.__send__("#{accessor_name(name)}=", value)
- end
- end
- assert_content(@elements, rss.items.last)
- end
-
- private
- def accessor_name(name)
- "content_#{name}"
- end
- end
-end
diff --git a/test/rss/test_maker_dc.rb b/test/rss/test_maker_dc.rb
deleted file mode 100644
index f5c8bad2b30..00000000000
--- a/test/rss/test_maker_dc.rb
+++ /dev/null
@@ -1,150 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss-testcase"
-
-require "rss/maker"
-
-module RSS
- class TestMakerDublinCore < TestCase
-
- def setup
- @uri = "http://purl.org/dc/elements/1.1/"
-
- t = Time.iso8601("2000-01-01T12:00:05+00:00")
- class << t
- alias_method(:to_s, :iso8601)
- end
-
- @elements = {
- :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,
- }
- end
-
- def test_rss10
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
- set_elements(maker.channel)
-
- setup_dummy_image(maker)
- set_elements(maker.image)
-
- setup_dummy_item(maker)
- item = maker.items.last
- @elements.each do |name, value|
- item.__send__("#{accessor_name(name)}=", value)
- end
-
- setup_dummy_textinput(maker)
- set_elements(maker.textinput)
- end
- assert_dublin_core(@elements, rss.channel)
- assert_dublin_core(@elements, rss.image)
- assert_dublin_core(@elements, rss.items.last)
- assert_dublin_core(@elements, rss.textinput)
- end
-
- def test_rss10_multiple
- assert_multiple_dublin_core_rss10("_list")
- assert_multiple_dublin_core_rss10("es")
- end
-
- def assert_multiple_dublin_core_rss10(multiple_rights_suffix)
- elems = []
- @elements.each do |name, value|
- plural = name.to_s + (name == :rights ? multiple_rights_suffix : "s")
- values = [value]
- if name == :date
- values << value + 60
- else
- values << value * 2
- end
- elems << [name, values, plural]
- end
-
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
- set_multiple_elements(maker.channel, elems)
-
- setup_dummy_image(maker)
- set_multiple_elements(maker.image, elems)
-
- setup_dummy_item(maker)
- item = maker.items.last
- elems.each do |name, values, plural|
- dc_elems = item.__send__("dc_#{plural}")
- values.each do |value|
- elem = dc_elems.__send__("new_#{name}")
- elem.value = value
- end
- end
-
- setup_dummy_textinput(maker)
- set_multiple_elements(maker.textinput, elems)
- end
- assert_multiple_dublin_core(elems, rss.channel)
- assert_multiple_dublin_core(elems, rss.image)
- assert_multiple_dublin_core(elems, rss.items.last)
- assert_multiple_dublin_core(elems, rss.textinput)
- end
-
- def test_date
- t1 = Time.iso8601("2000-01-01T12:00:05+00:00")
- t2 = Time.iso8601("2005-01-01T12:00:05+00:00")
-
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
- maker.channel.date = t1
- maker.channel.dc_dates.new_date do |date|
- date.value = t2
- end
-
- setup_dummy_item(maker)
- item = maker.items.last
- item.date = t2
- item.dc_dates.new_date do |date|
- date.value = t1
- end
- end
- assert_equal([t1, t2], rss.channel.dc_dates.collect{|x| x.value})
- assert_equal([t2, t1], rss.items.last.dc_dates.collect{|x| x.value})
- end
-
- private
- def accessor_name(name)
- "dc_#{name}"
- end
-
- def set_elements(target, elems=@elements)
- elems.each do |name, value|
- target.__send__("#{accessor_name(name)}=", value)
- end
- end
-
- def set_multiple_elements(target, elems)
- elems.each do |name, values, plural|
- plural ||= "#{name}s"
- dc_elems = target.__send__("dc_#{plural}")
- values.each do |value|
- dc_elems.__send__("new_#{name}") do |new_dc_elem|
- new_dc_elem.value = value
- end
- end
- end
- end
-
- end
-end
diff --git a/test/rss/test_maker_image.rb b/test/rss/test_maker_image.rb
deleted file mode 100644
index cc663c6a5cd..00000000000
--- a/test/rss/test_maker_image.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss-testcase"
-
-require "rss/maker"
-
-module RSS
- class TestMakerImage < TestCase
-
- def setup
- @uri = "http://web.resource.org/rss/1.0/modules/image/"
-
- @favicon_infos = {
- "about" => "http://www.kuro5hin.org/favicon.ico",
- "image_size" => "small",
- "dc_title" => "example",
- }
- @item_infos = {
- "about" => "http://www.example.org/item.png",
- "resource" => "http://www.example.org/item",
- "dc_title" => "Example Image",
- "image_width" => "100",
- "image_height" => "65",
- }
- end
-
- def test_rss10
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
- @favicon_infos.each do |name, value|
- maker.channel.image_favicon.__send__("#{name}=", value)
- end
-
- setup_dummy_image(maker)
-
- setup_dummy_item(maker)
- item = maker.items.last
- @item_infos.each do |name, value|
- item.image_item.__send__("#{name}=", value)
- end
-
- setup_dummy_textinput(maker)
- end
-
- setup_rss = RSS::Maker.make("1.0") do |maker|
- rss.setup_maker(maker)
- end
-
- [rss, setup_rss].each_with_index do |target, i|
- favicon = target.channel.image_favicon
- assert_equal(@favicon_infos["about"], favicon.about)
- assert_equal(@favicon_infos["image_size"], favicon.image_size)
- assert_equal(@favicon_infos["dc_title"], favicon.dc_title)
-
- item = target.items.last.image_item
- assert_equal(@item_infos["about"], item.about)
- assert_equal(@item_infos["resource"], item.resource)
- assert_equal(@item_infos["image_width"].to_i, item.image_width)
- assert_equal(@item_infos["image_height"].to_i, item.image_height)
- assert_equal(@item_infos["dc_title"], item.dc_title)
- end
- end
- end
-end
diff --git a/test/rss/test_maker_itunes.rb b/test/rss/test_maker_itunes.rb
deleted file mode 100644
index cba612c099d..00000000000
--- a/test/rss/test_maker_itunes.rb
+++ /dev/null
@@ -1,487 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss-testcase"
-
-require "rss/maker"
-
-module RSS
- class TestMakerITunes < TestCase
- def test_author
- assert_maker_itunes_author(%w(channel))
- assert_maker_itunes_author(%w(items last))
- end
-
- def test_block
- assert_maker_itunes_block(%w(channel))
- assert_maker_itunes_block(%w(items last))
- end
-
- def test_category
- assert_maker_itunes_category(%w(channel))
- end
-
- def test_image
- assert_maker_itunes_image(%w(channel))
- end
-
- def test_duration
- assert_maker_itunes_duration(%w(items last))
- end
-
- def test_explicit
- assert_maker_itunes_explicit(%w(channel))
- assert_maker_itunes_explicit(%w(items last))
- end
-
- def test_keywords
- assert_maker_itunes_keywords(%w(channel))
- assert_maker_itunes_keywords(%w(items last))
- end
-
- def test_new_feed_url
- assert_maker_itunes_new_feed_url(%w(channel))
- end
-
- def test_owner
- assert_maker_itunes_owner(%w(channel))
- end
-
- def test_subtitle
- assert_maker_itunes_subtitle(%w(channel))
- assert_maker_itunes_subtitle(%w(items last))
- end
-
- def test_summary
- assert_maker_itunes_summary(%w(channel))
- assert_maker_itunes_summary(%w(items last))
- end
-
- private
-
- def assert_maker_itunes_author(maker_readers, feed_readers=nil)
- _wrap_assertion do
- feed_readers ||= maker_readers
- author = "John Doe"
- rss20 = ::RSS::Maker.make("rss2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- target = chain_reader(maker, maker_readers)
- target.itunes_author = author
- end
- target = chain_reader(rss20, feed_readers)
- assert_equal(author, target.itunes_author)
- end
- end
-
- def _assert_maker_itunes_block(value, boolean_value, maker_readers,
- feed_readers)
- rss20 = ::RSS::Maker.make("rss2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- target = chain_reader(maker, maker_readers)
- target.itunes_block = value
- assert_equal(value, target.itunes_block)
- assert_equal(boolean_value, target.itunes_block?)
- end
- target = chain_reader(rss20, feed_readers)
- if [true, false].include?(value)
- value = value ? "yes" : "no"
- end
- assert_equal(value, target.itunes_block)
- assert_equal(boolean_value, target.itunes_block?)
- end
-
- def assert_maker_itunes_block(maker_readers, feed_readers=nil)
- _wrap_assertion do
- feed_readers ||= maker_readers
- _assert_maker_itunes_block("yes", true, maker_readers, feed_readers)
- _assert_maker_itunes_block("Yes", true, maker_readers, feed_readers)
- _assert_maker_itunes_block("no", false, maker_readers, feed_readers)
- _assert_maker_itunes_block("", false, maker_readers, feed_readers)
- _assert_maker_itunes_block(true, true, maker_readers, feed_readers)
- _assert_maker_itunes_block(false, false, maker_readers, feed_readers)
- _assert_maker_itunes_block(nil, false, maker_readers, feed_readers)
- end
- end
-
- def _assert_maker_itunes_category(categories, maker_readers, feed_readers)
- rss20 = ::RSS::Maker.make("rss2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- target = chain_reader(maker, maker_readers)
- categories.each do |category|
- sub_target = target.itunes_categories
- if category.is_a?(Array)
- category.each do |sub_category|
- sub_target = sub_target.new_category
- sub_target.text = sub_category
- end
- else
- sub_target.new_category.text = category
- end
- end
- end
-
- target = chain_reader(rss20, feed_readers)
- actual_categories = target.itunes_categories.collect do |category|
- cat = category.text
- if category.itunes_categories.empty?
- cat
- else
- [cat, *category.itunes_categories.collect {|c| c.text}]
- end
- end
- assert_equal(categories, actual_categories)
- end
-
- def assert_maker_itunes_category(maker_readers, feed_readers=nil)
- _wrap_assertion do
- feed_readers ||= maker_readers
- _assert_maker_itunes_category(["Audio Blogs"],
- maker_readers, feed_readers)
- _assert_maker_itunes_category([["Arts & Entertainment", "Games"]],
- maker_readers, feed_readers)
- _assert_maker_itunes_category([["Arts & Entertainment", "Games"],
- ["Technology", "Computers"],
- "Audio Blogs"],
- maker_readers, feed_readers)
- end
- end
-
- def assert_maker_itunes_image(maker_readers, feed_readers=nil)
- _wrap_assertion do
- feed_readers ||= maker_readers
- url = "http://example.com/podcasts/everything/AllAboutEverything.jpg"
-
- rss20 = ::RSS::Maker.make("rss2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- target = chain_reader(maker, maker_readers)
- target.itunes_image = url
- end
-
- target = chain_reader(rss20, feed_readers)
- assert_not_nil(target.itunes_image)
- assert_equal(url, target.itunes_image.href)
- end
- end
-
- def _assert_maker_itunes_duration(hour, minute, second, value,
- maker_readers, feed_readers)
- _assert_maker_itunes_duration_by_value(hour, minute, second, value,
- maker_readers, feed_readers)
- _assert_maker_itunes_duration_by_hour_minute_second(hour, minute, second,
- value,
- maker_readers,
- feed_readers)
- end
-
- def _assert_maker_itunes_duration_by(hour, minute, second, value,
- maker_readers, feed_readers)
- expected_value = nil
- rss20 = ::RSS::Maker.make("rss2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- target = chain_reader(maker, maker_readers)
- expected_value = yield(target)
- assert_equal(expected_value, target.itunes_duration)
- target.itunes_duration do |duration|
- assert_equal([hour, minute, second, expected_value],
- [duration.hour, duration.minute,
- duration.second, duration.content])
- end
- end
- target = chain_reader(rss20, feed_readers)
- duration = target.itunes_duration
- assert_not_nil(duration)
- assert_equal([hour, minute, second, expected_value],
- [duration.hour, duration.minute,
- duration.second, duration.content])
- end
-
- def _assert_maker_itunes_duration_by_value(hour, minute, second, value,
- maker_readers, feed_readers)
- _assert_maker_itunes_duration_by(hour, minute, second, value,
- maker_readers, feed_readers) do |target|
- target.itunes_duration = value
- value
- end
- end
-
- def _assert_maker_itunes_duration_by_hour_minute_second(hour, minute, second,
- value,
- maker_readers,
- feed_readers)
- _assert_maker_itunes_duration_by(hour, minute, second, value,
- maker_readers, feed_readers) do |target|
- target.itunes_duration do |duration|
- duration.hour = hour
- duration.minute = minute
- duration.second = second
- end
- value.split(":").collect {|v| "%02d" % v.to_i}.join(":")
- end
- end
-
- def _assert_maker_itunes_duration_invalid_value(value, maker_readers)
- assert_raise(ArgumentError) do
- ::RSS::Maker.make("rss2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- target = chain_reader(maker, maker_readers)
- target.itunes_duration = value
- end
- end
- end
-
- def assert_maker_itunes_duration(maker_readers, feed_readers=nil)
- _wrap_assertion do
- feed_readers ||= maker_readers
- _assert_maker_itunes_duration(7, 14, 5, "07:14:05", maker_readers,
- feed_readers)
- _assert_maker_itunes_duration(7, 14, 5, "7:14:05", maker_readers,
- feed_readers)
- _assert_maker_itunes_duration(0, 4, 55, "04:55", maker_readers,
- feed_readers)
- _assert_maker_itunes_duration(0, 4, 5, "4:05", maker_readers,
- feed_readers)
- _assert_maker_itunes_duration(0, 0, 5, "0:05", maker_readers,
- feed_readers)
- _assert_maker_itunes_duration_by_value(0, 5, 15, "315", maker_readers,
- feed_readers)
- _assert_maker_itunes_duration_by_value(1, 0, 1, "3601", maker_readers,
- feed_readers)
-
- _assert_maker_itunes_duration_invalid_value("09:07:14:05", maker_readers)
- _assert_maker_itunes_duration_invalid_value("10:5", maker_readers)
- _assert_maker_itunes_duration_invalid_value("10:03:5", maker_readers)
- _assert_maker_itunes_duration_invalid_value("10:3:05", maker_readers)
-
- _assert_maker_itunes_duration_invalid_value("xx:xx:xx", maker_readers)
-
- _assert_maker_itunes_duration_invalid_value("", maker_readers)
- end
- end
-
- def _assert_maker_itunes_explicit(explicit, value,
- maker_readers, feed_readers)
- rss20 = ::RSS::Maker.make("rss2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- target = chain_reader(maker, maker_readers)
- target.itunes_explicit = value
- assert_equal(explicit, target.itunes_explicit?)
- end
- target = chain_reader(rss20, feed_readers)
- assert_equal(value, target.itunes_explicit)
- assert_equal(explicit, target.itunes_explicit?)
- end
-
- def assert_maker_itunes_explicit(maker_readers, feed_readers=nil)
- _wrap_assertion do
- feed_readers ||= maker_readers
- _assert_maker_itunes_explicit(true, "explicit",
- maker_readers, feed_readers)
- _assert_maker_itunes_explicit(true, "yes",
- maker_readers, feed_readers)
- _assert_maker_itunes_explicit(true, "true",
- maker_readers, feed_readers)
- _assert_maker_itunes_explicit(false, "clean",
- maker_readers, feed_readers)
- _assert_maker_itunes_explicit(false, "no",
- maker_readers, feed_readers)
- _assert_maker_itunes_explicit(false, "false",
- maker_readers, feed_readers)
- _assert_maker_itunes_explicit(nil, "invalid",
- maker_readers, feed_readers)
- end
- end
-
- def _assert_maker_itunes_keywords(keywords, value,
- maker_readers, feed_readers)
- _assert_maker_itunes_keywords_by_value(keywords, value,
- maker_readers, feed_readers)
- _assert_maker_itunes_keywords_by_keywords(keywords, maker_readers,
- feed_readers)
- end
-
- def _assert_maker_itunes_keywords_by(keywords, maker_readers, feed_readers)
- rss20 = ::RSS::Maker.make("rss2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- target = chain_reader(maker, maker_readers)
- yield(target)
- end
- assert_nothing_raised do
- rss20 = ::RSS::Parser.parse(rss20.to_s)
- end
- target = chain_reader(rss20, feed_readers)
- assert_equal(keywords, target.itunes_keywords)
- end
-
- def _assert_maker_itunes_keywords_by_value(keywords, value,
- maker_readers, feed_readers)
- _assert_maker_itunes_keywords_by(keywords, maker_readers,
- feed_readers) do |target|
- target.itunes_keywords = value
- end
- end
-
- def _assert_maker_itunes_keywords_by_keywords(keywords,
- maker_readers, feed_readers)
- _assert_maker_itunes_keywords_by(keywords, maker_readers,
- feed_readers) do |target|
- target.itunes_keywords = keywords
- end
- end
-
- def assert_maker_itunes_keywords(maker_readers, feed_readers=nil)
- _wrap_assertion do
- feed_readers ||= maker_readers
- _assert_maker_itunes_keywords(["salt"], "salt",
- maker_readers, feed_readers)
- _assert_maker_itunes_keywords(["salt"], " salt ",
- maker_readers, feed_readers)
- _assert_maker_itunes_keywords(["salt", "pepper", "shaker", "exciting"],
- "salt, pepper, shaker, exciting",
- maker_readers, feed_readers)
- _assert_maker_itunes_keywords(["metric", "socket", "wrenches",
- "toolsalt"],
- "metric, socket, wrenches, toolsalt",
- maker_readers, feed_readers)
- _assert_maker_itunes_keywords(["olitics", "red", "blue", "state"],
- "olitics, red, blue, state",
- maker_readers, feed_readers)
- end
- end
-
- def assert_maker_itunes_new_feed_url(maker_readers, feed_readers=nil)
- feed_readers ||= maker_readers
- url = "http://newlocation.com/example.rss"
-
- rss20 = ::RSS::Maker.make("rss2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- target = chain_reader(maker, maker_readers)
- target.itunes_new_feed_url = url
- end
- target = chain_reader(rss20, feed_readers)
- assert_equal(url, target.itunes_new_feed_url)
- end
-
- def _assert_maker_itunes_owner(name, email, maker_readers, feed_readers)
- rss20 = ::RSS::Maker.make("rss2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- target = chain_reader(maker, maker_readers)
- owner = target.itunes_owner
- owner.itunes_name = name
- owner.itunes_email = email
- end
- owner = chain_reader(rss20, feed_readers).itunes_owner
- if name.nil? and email.nil?
- assert_nil(owner)
- else
- assert_not_nil(owner)
- assert_equal(name, owner.itunes_name)
- assert_equal(email, owner.itunes_email)
- end
- end
-
- def assert_maker_itunes_owner(maker_readers, feed_readers=nil)
- _wrap_assertion do
- feed_readers ||= maker_readers
- _assert_maker_itunes_owner("John Doe", "john.doe@example.com",
- maker_readers, feed_readers)
-
- not_set_name = (["maker"] + maker_readers + ["itunes_owner"]).join(".")
- assert_not_set_error(not_set_name, ["itunes_name"]) do
- _assert_maker_itunes_owner(nil, "john.doe@example.com",
- maker_readers, feed_readers)
- end
- assert_not_set_error(not_set_name, ["itunes_email"]) do
- _assert_maker_itunes_owner("John Doe", nil,
- maker_readers, feed_readers)
- end
-
- _assert_maker_itunes_owner(nil, nil, maker_readers, feed_readers)
- end
- end
-
- def _assert_maker_itunes_subtitle(subtitle, maker_readers, feed_readers)
- rss20 = ::RSS::Maker.make("rss2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- target = chain_reader(maker, maker_readers)
- target.itunes_subtitle = subtitle
- end
-
- target = chain_reader(rss20, feed_readers)
- assert_equal(subtitle, target.itunes_subtitle)
- end
-
- def assert_maker_itunes_subtitle(maker_readers, feed_readers=nil)
- _wrap_assertion do
- feed_readers ||= maker_readers
- _assert_maker_itunes_subtitle("A show about everything",
- maker_readers, feed_readers)
- _assert_maker_itunes_subtitle("A short primer on table spices",
- maker_readers, feed_readers)
- _assert_maker_itunes_subtitle("Comparing socket wrenches is fun!",
- maker_readers, feed_readers)
- _assert_maker_itunes_subtitle("Red + Blue != Purple",
- maker_readers, feed_readers)
- end
- end
-
- def _assert_maker_itunes_summary(summary, maker_readers, feed_readers)
- rss20 = ::RSS::Maker.make("rss2.0") do |maker|
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
-
- target = chain_reader(maker, maker_readers)
- target.itunes_summary = summary
- end
-
- target = chain_reader(rss20, feed_readers)
- assert_equal(summary, target.itunes_summary)
- end
-
- def assert_maker_itunes_summary(maker_readers, feed_readers=nil)
- _wrap_assertion do
- feed_readers ||= maker_readers
- _assert_maker_itunes_summary("All About Everything is a show about " +
- "everything. Each week we dive into any " +
- "subject known to man and talk about it " +
- "as much as we can. Look for our Podcast " +
- "in the iTunes Music Store",
- maker_readers, feed_readers)
- _assert_maker_itunes_summary("This week we talk about salt and pepper " +
- "shakers, comparing and contrasting pour " +
- "rates, construction materials, and " +
- "overall aesthetics. Come and join the " +
- "party!",
- maker_readers, feed_readers)
- _assert_maker_itunes_summary("This week we talk about metric vs. old " +
- "english socket wrenches. Which one is " +
- "better? Do you really need both? Get " +
- "all of your answers here.",
- maker_readers, feed_readers)
- _assert_maker_itunes_summary("This week we talk about surviving in a " +
- "Red state if you're a Blue person. Or " +
- "vice versa.",
- maker_readers, feed_readers)
- end
- end
- end
-end
diff --git a/test/rss/test_maker_slash.rb b/test/rss/test_maker_slash.rb
deleted file mode 100644
index 5e5761ab0f6..00000000000
--- a/test/rss/test_maker_slash.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss-testcase"
-
-require "rss/maker"
-
-module RSS
- class TestMakerSlash < TestCase
- def setup
- @elements = {
- "section" => "articles",
- "department" => "not-an-ocean-unless-there-are-lobsters",
- "comments" => 177,
- "hit_parades" => [177, 155, 105, 33, 6, 3, 0],
- }
- end
-
- def test_rss10
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
-
- setup_dummy_item(maker)
- item = maker.items.last
- @elements.each do |name, value|
- item.send("slash_#{name}=", value)
- end
- end
-
- item = rss.items.last
- assert_not_nil(item)
- assert_slash_elements(item)
- end
-
- private
- def assert_slash_elements(target)
- super(@elements, target)
- end
- end
-end
diff --git a/test/rss/test_maker_sy.rb b/test/rss/test_maker_sy.rb
deleted file mode 100644
index 6f4d6f83907..00000000000
--- a/test/rss/test_maker_sy.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss-testcase"
-
-require "rss/maker"
-
-module RSS
- class TestMakerSyndication < TestCase
-
- def setup
- @uri = "http://purl.org/rss/1.0/modules/syndication/"
-
- t = Time.iso8601("2000-01-01T12:00:05+00:00")
- class << t
- alias_method(:to_s, :iso8601)
- end
-
- @elements = {
- :updatePeriod => "hourly",
- :updateFrequency => "2",
- :updateBase => t,
- }
- end
-
- def test_rss10
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
- set_elements(maker.channel)
- setup_dummy_item(maker)
- end
- assert_syndication(@elements, rss.channel)
- end
-
- private
- def accessor_name(name)
- "sy_#{name}"
- end
-
- def set_elements(target)
- @elements.each do |name, value|
- target.__send__("#{accessor_name(name)}=", value)
- end
- end
-
- end
-end
diff --git a/test/rss/test_maker_taxo.rb b/test/rss/test_maker_taxo.rb
deleted file mode 100644
index 9a19a52dc46..00000000000
--- a/test/rss/test_maker_taxo.rb
+++ /dev/null
@@ -1,82 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss-testcase"
-
-require "rss/maker"
-
-module RSS
- class TestMakerTaxonomy < TestCase
-
- def setup
- @uri = "http://purl.org/rss/1.0/modules/taxonomy/"
-
- @resources = [
- "http://meerkat.oreillynet.com/?c=cat23",
- "http://meerkat.oreillynet.com/?c=47",
- "http://dmoz.org/Computers/Data_Formats/Markup_Languages/XML/",
- ]
-
- @topics = [
- {
- :link => "http://meerkat.oreillynet.com/?c=cat23",
- :title => "Data: XML",
- :description => "A Meerkat channel",
- },
- {
- :link => "http://dmoz.org/Computers/Data_Formats/Markup_Languages/XML/",
- :title => "XML",
- :subject => "XML",
- :description => "DMOZ category",
- :topics => [
- "http://meerkat.oreillynet.com/?c=cat23",
- "http://dmoz.org/Computers/Data_Formats/Markup_Languages/SGML/",
- "http://dmoz.org/Computers/Programming/Internet/",
- ]
- },
- ]
- end
-
- def test_rss10
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
- set_topics(maker.channel)
-
- setup_dummy_item(maker)
- set_topics(maker.items.last)
-
- setup_taxo_topic(maker, @topics)
- end
- assert_equal(@resources, rss.channel.taxo_topics.resources)
- assert_equal(@resources, rss.items.last.taxo_topics.resources)
- assert_taxo_topic(@topics, rss)
- end
-
- def _test_date
- t1 = Time.iso8601("2000-01-01T12:00:05+00:00")
- t2 = Time.iso8601("2005-01-01T12:00:05+00:00")
-
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
- maker.channel.date = t1
- maker.channel.dc_dates.new_date do |date|
- date.value = t2
- end
-
- setup_dummy_item(maker)
- item = maker.items.last
- item.date = t2
- item.dc_dates.new_date do |date|
- date.value = t1
- end
- end
- assert_equal([t1, t2], rss.channel.dc_dates.collect{|x| x.value})
- assert_equal([t2, t1], rss.items.last.dc_dates.collect{|x| x.value})
- end
-
- private
- def set_topics(target, resources=@resources)
- resources.each do |value|
- target.taxo_topics << value
- end
- end
- end
-end
diff --git a/test/rss/test_maker_trackback.rb b/test/rss/test_maker_trackback.rb
deleted file mode 100644
index b49e5c3f57c..00000000000
--- a/test/rss/test_maker_trackback.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss-testcase"
-
-require "rss/maker"
-
-module RSS
- class TestMakerTrackBack < TestCase
-
- def setup
- @uri = "http://madskills.com/public/xml/rss/module/trackback/"
-
- @elements = {
- :ping => "http://bar.com/tb.cgi?tb_id=rssplustrackback",
- :abouts => [
- "http://foo.com/trackback/tb.cgi?tb_id=20020923",
- "http://bar.com/trackback/tb.cgi?tb_id=20041114",
- ],
- }
- end
-
- def test_rss10
- rss = RSS::Maker.make("1.0") do |maker|
- setup_dummy_channel(maker)
-
- setup_dummy_item(maker)
- item = maker.items.last
- item.trackback_ping = @elements[:ping]
- @elements[:abouts].each do |about|
- item.trackback_abouts.new_about do |new_about|
- new_about.value = about
- end
- end
- end
- assert_trackback(@elements, rss.items.last)
- end
-
- private
- def accessor_name(name)
- "trackback_#{name}"
- end
- end
-end
diff --git a/test/rss/test_maker_xml-stylesheet.rb b/test/rss/test_maker_xml-stylesheet.rb
deleted file mode 100644
index 4563de9902a..00000000000
--- a/test/rss/test_maker_xml-stylesheet.rb
+++ /dev/null
@@ -1,84 +0,0 @@
-# frozen_string_literal: false
-require_relative "rss-testcase"
-
-require "rss/maker"
-
-module RSS
- class TestMakerXMLStyleSheet < TestCase
-
- def test_xml_stylesheet
- href = 'a.xsl'
- type = 'text/xsl'
- title = 'sample'
- media = 'printer'
- charset = 'UTF-8'
- alternate = 'yes'
-
- rss = RSS::Maker.make("1.0") do |maker|
- maker.xml_stylesheets.new_xml_stylesheet do |xss|
- xss.href = href
- xss.type = type
- xss.title = title
- xss.media = media
- xss.charset = charset
- xss.alternate = alternate
- end
-
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
- end
-
- xss = rss.xml_stylesheets.first
- assert_equal(href, xss.href)
- assert_equal(type, xss.type)
- assert_equal(title, xss.title)
- assert_equal(media, xss.media)
- assert_equal(charset, xss.charset)
- assert_equal(alternate, xss.alternate)
-
-
- href = 'http://example.com/index.xsl'
- type = 'text/xsl'
- rss = RSS::Maker.make("1.0") do |maker|
- maker.xml_stylesheets.new_xml_stylesheet do |_xss|
- _xss.href = href
- end
-
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
- end
-
- xss = rss.xml_stylesheets.first
- assert_equal(href, xss.href)
- assert_equal(type, xss.type)
- end
-
- def test_not_valid_xml_stylesheet
- href = 'xss.XXX'
- type = "text/xsl"
-
- rss = RSS::Maker.make("1.0") do |maker|
- maker.xml_stylesheets.new_xml_stylesheet do |xss|
- # xss.href = href
- xss.type = type
- end
-
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
- end
- assert(rss.xml_stylesheets.empty?)
-
- rss = RSS::Maker.make("1.0") do |maker|
- maker.xml_stylesheets.new_xml_stylesheet do |xss|
- xss.href = href
- # xss.type = type
- end
-
- setup_dummy_channel(maker)
- setup_dummy_item(maker)
- end
- assert(rss.xml_stylesheets.empty?)
- end
-
- end
-end
diff --git a/test/rss/test_parser.rb b/test/rss/test_parser.rb
deleted file mode 100644
index 19344a06432..00000000000
--- a/test/rss/test_parser.rb
+++ /dev/null
@@ -1,121 +0,0 @@
-# frozen_string_literal: false
-require "tempfile"
-
-require_relative "rss-testcase"
-
-require "rss/1.0"
-require "rss/dublincore"