1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/rss/{0.9,1.0,2.0,trackback,xml-stylesheet}.rb: added

#setup_maker.
* test/rss/test_setup_maker_*.rb: added tests for #setup_maker.
* lib/rss/maker/base.rb(RSS::Maker::Items#max_size=): supported
  output item size limitation.
* sample/rss/blend.rb: added sample for RSS Maker.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kou 2004-11-27 08:47:28 +00:00
parent 0a93165e16
commit 2572d5e20e
12 changed files with 1066 additions and 14 deletions

View file

@ -1,3 +1,15 @@
Sat Nov 27 17:43:21 2004 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/{0.9,1.0,2.0,trackback,xml-stylesheet}.rb: added
#setup_maker.
* test/rss/test_setup_maker_*.rb: added tests for #setup_maker.
* lib/rss/maker/base.rb(RSS::Maker::Items#max_size=): supported
output item size limitation.
* sample/rss/blend.rb: added sample for RSS Maker.
Sat Nov 27 17:41:35 2004 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/maker/0.9.rb: supported RSS::Maker.make("0.91"). Now,

View file

@ -203,6 +203,26 @@ module RSS
rv
end
def maker_target(maker)
maker.channel
end
def setup_maker_elements(channel)
super
[
[skipDays, "day"],
[skipHours, "hour"],
].each do |skip, key|
if skip
skip.__send__("#{key}s").each do |val|
target_skips = channel.__send__("skip#{key.capitalize}s")
new_target = target_skips.__send__("new_#{key}")
new_target.content = val.content
end
end
end
end
class SkipDays < Element
include RSS09
@ -323,7 +343,7 @@ module RSS
other_element(false, next_indent),
]
end
rv = @converter.convert(rv) if convert and @converter
rv = @converter.convert(rv) if convert and @converter
rv
end
@ -335,6 +355,10 @@ module RSS
[nil, elem]
end
end
def maker_target(maker)
maker.image
end
end
class Cloud < Element
@ -440,6 +464,16 @@ module RSS
rv
end
def maker_target(maker)
maker.items.new_item
end
def setup_maker_element(item)
super
@enclosure.setup_maker(item) if @enclosure
@source.setup_maker(item) if @source
end
class Source < Element
include RSS09
@ -469,6 +503,15 @@ module RSS
]
end
def maker_target(item)
item.source
end
def setup_maker_attributes(source)
source.url = url
source.content = content
end
end
class Enclosure < Element
@ -505,6 +548,15 @@ module RSS
]
end
def maker_target(item)
item.enclosure
end
def setup_maker_attributes(enclosure)
enclosure.url = url
enclosure.length = length
enclosure.type = type
end
end
class Category < Element
@ -532,6 +584,15 @@ module RSS
]
end
def maker_target(item)
item.new_category
end
def setup_maker_attributes(category)
category.domain = domain
category.content = content
end
end
end
@ -555,7 +616,7 @@ module RSS
other_element(false, next_indent),
]
end
rv = @converter.convert(rv) if convert and @converter
rv = @converter.convert(rv) if convert and @converter
rv
end
@ -567,6 +628,10 @@ module RSS
[nil, elem]
end
end
def maker_target(maker)
maker.textinput
end
end
end

View file

@ -274,6 +274,14 @@ module RSS
]
end
def maker_target(maker)
maker.channel
end
def setup_maker_attributes(channel)
channel.about = self.about
end
class Image < Element
include RSS10
@ -469,6 +477,10 @@ module RSS
["#{PREFIX}:about", true, "about"]
]
end
def maker_target(maker)
maker.image
end
end
class Item < Element
@ -535,6 +547,10 @@ module RSS
["#{PREFIX}:about", true, "about"]
]
end
def maker_target(maker)
maker.items.new_item
end
end
class Textinput < Element
@ -604,6 +620,10 @@ module RSS
["#{PREFIX}:about", true, "about"]
]
end
def maker_target(maker)
maker.textinput
end
end
end

View file

@ -113,6 +113,12 @@ EOT
end + _tags09
end
alias _setup_maker_element setup_maker_element
def setup_maker_element(item)
_setup_maker_element(item)
@guid.setup_maker(item) if @guid
end
class Guid < Element
include RSS09
@ -138,6 +144,14 @@ EOT
]
end
def maker_target(item)
item.guid
end
def setup_maker_attributes(guid)
guid.isPermaLink = isPermaLink
guid.content = content
end
end
end

View file

@ -370,15 +370,16 @@ EOC
def_array_element("items")
attr_accessor :do_sort
attr_accessor :do_sort, :max_size
def initialize(maker)
super
@do_sort = false
@max_size = -1
end
def normalize
sort_if_need
sort_if_need[0..@max_size]
end
def current_element(rss)

View file

@ -165,8 +165,9 @@ EOC
alias_method(:install_have_attribute_element, :install_have_child_element)
def install_have_children_element(name, plural_name=nil)
add_have_children_element(name)
plural_name ||= "#{name}s"
add_have_children_element(name, plural_name)
def_children_accessor(name, plural_name)
install_element(name, "s") do |n, elem_name|
<<-EOC
@ -289,8 +290,7 @@ EOC
end
end
def def_children_accessor(accessor_name, plural_name=nil)
plural_name ||= "#{accessor_name}s"
def def_children_accessor(accessor_name, plural_name)
module_eval(<<-EOC, *get_file_and_line_from_caller(2))
def #{plural_name}
@#{accessor_name}
@ -405,8 +405,8 @@ EOC
@@have_children_elements
end
def self.add_have_children_element(variable_name)
@@have_children_elements << variable_name
def self.add_have_children_element(variable_name, plural_name)
@@have_children_elements << [variable_name, plural_name]
end
@@need_initialize_variables = []
@ -484,6 +484,15 @@ EOC
__validate(tags, false)
end
def setup_maker(maker)
target = maker_target(maker)
unless target.nil?
setup_maker_attributes(target)
setup_maker_element(target)
setup_maker_elements(target)
end
end
private
def initialize_variables
self.class.need_initialize_variables.each do |variable_name|
@ -494,7 +503,7 @@ EOC
end
def initialize_have_children_elements
self.class.have_children_elements.each do |variable_name|
self.class.have_children_elements.each do |variable_name, plural_name|
instance_eval("@#{variable_name} = []")
end
end
@ -558,6 +567,34 @@ EOC
def calc_indent
INDENT * (self.class.indent_size)
end
def maker_target(maker)
nil
end
def setup_maker_attributes(target)
end
def setup_maker_element(target)
self.class.need_initialize_variables.each do |var|
setter = "#{var}="
if target.respond_to?(setter)
target.__send__(setter, __send__(var))
end
end
end
def setup_maker_elements(parent)
self.class.have_children_elements.each do |name, plural_name|
real_name = name.sub(/^[^_]+_/, '')
if parent.respond_to?(plural_name)
target = parent.__send__(plural_name)
__send__(plural_name).each do |elem|
elem.__send__("setup_maker", target)
end
end
end
end
# not String class children.
def children
@ -735,6 +772,18 @@ EOC
self.converter = Converter.new(@output_encoding, @encoding)
end
def setup_maker(maker)
maker.version = version
maker.encoding = encoding
maker.standalone = standalone
xml_stylesheets.each do |xss|
xss.setup_maker(maker)
end
setup_maker_elements(maker)
end
private
def tag(indent, attrs)
rv = xmldecl + xml_stylesheet_pi
@ -759,6 +808,14 @@ EOC
end
end
def setup_maker_elements(maker)
channel.setup_maker(maker) if channel
image.setup_maker(maker) if image
textinput.setup_maker(maker) if textinput
items.each do |item|
item.setup_maker(maker)
end
end
end
end

View file

@ -65,9 +65,9 @@ module RSS
EOC
end
[%w(about s)].each do |x, postfix|
var_name = "#{TRACKBACK_PREFIX}_#{x}"
klass_name = x.capitalize
[%w(about s)].each do |name, postfix|
var_name = "#{TRACKBACK_PREFIX}_#{name}"
klass_name = name.capitalize
klass.install_have_children_element(var_name)
klass.module_eval(<<-EOC, __FILE__, __LINE__)
undef #{var_name}
@ -207,6 +207,14 @@ module RSS
]
end
def maker_target(abouts)
abouts.new_about
end
def setup_maker_attributes(about)
about.resource = self.resource
end
end
end

View file

@ -84,6 +84,13 @@ module RSS
@alternate
end
def setup_maker(maker)
xss = maker.xml_stylesheets.new_xml_stylesheet
ATTRIBUTES.each do |attr|
xss.__send__("#{attr}=", __send__(attr))
end
end
private
def guess_type(filename)
/\.([^.]+)$/ =~ filename

76
sample/rss/blend.rb Executable file
View file

@ -0,0 +1,76 @@
#!/usr/bin/env ruby
require "rss/1.0"
require "rss/2.0"
require "rss/dublincore"
require "rss/maker"
feeds = []
verbose = false
encoding = "UTF-8"
def error(exception)
mark = "=" * 20
mark = "#{mark} error #{mark}"
STDERR.puts mark
STDERR.puts exception.class
STDERR.puts exception.message
STDERR.puts exception.backtrace
STDERR.puts mark
end
before_time = Time.now
ARGV.each do |fname|
if fname == '-v'
verbose = true
next
end
rss = nil
f = File.new(fname).read
begin
## do validate parse
rss = RSS::Parser.parse(f)
rescue RSS::InvalidRSSError
error($!) if verbose
## do non validate parse for invalid RSS 1.0
begin
rss = RSS::Parser.parse(f, false)
rescue RSS::Error
## invalid RSS.
error($!) if verbose
end
rescue RSS::Error
error($!) if verbose
end
if rss.nil?
STDERR.puts "#{fname} does not include RSS 1.0 or 0.9x/2.0"
else
begin
rss.output_encoding = encoding
rescue RSS::UnknownConversionMethodError
error($!) if verbose
end
feeds << rss
end
end
processing_time = Time.now - before_time
rss = RSS::Maker.make("1.0") do |maker|
maker.encoding = encoding
maker.channel.about = "http://example.com/blend.rdf"
maker.channel.title = "blended feeds"
maker.channel.link = "http://example.com/"
maker.channel.description = "blended feeds generated by RSS Parser"
feeds.each do |feed|
feed.items.each do |item|
item.setup_maker(maker)
end
end
maker.items.do_sort = true
maker.items.max_size = 15
end
puts rss
STDERR.puts "Used XML parser: #{RSS::Parser.default_parser}"
STDERR.puts "Processing time: #{processing_time}s"

View file

@ -0,0 +1,221 @@
require "rss-testcase"
require "rss/maker"
module RSS
class TestSetupMaker09 < TestCase
def test_setup_maker_channel
title = "fugafuga"
link = "http://hoge.com"
description = "fugafugafugafuga"
language = "ja"
copyright = "foo"
managingEditor = "bar"
webMaster = "web master"
rating = "6"
docs = "http://foo.com/doc"
skipDays = [
"Sunday",
"Monday",
]
skipHours = [
0,
13,
]
pubDate = Time.now
lastBuildDate = Time.now
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|
new_day = maker.channel.skipDays.new_day
new_day.content = day
end
skipHours.each do |hour|
new_hour = maker.channel.skipHours.new_hour
new_hour.content = hour
end
end
new_rss = RSS::Maker.make("0.91") do |maker|
rss.channel.setup_maker(maker)
end
channel = new_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(lastBuildDate, channel.lastBuildDate)
skipDays.each_with_index do |day, i|
assert_equal(day, channel.skipDays.days[i].content)
end
skipHours.each_with_index do |hour, i|
assert_equal(hour, channel.skipHours.hours[i].content)
end
assert(channel.items.empty?)
assert_nil(channel.image)
assert_nil(channel.textInput)
end
def test_setup_maker_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
new_rss = RSS::Maker.make("0.91") do |maker|
rss.channel.setup_maker(maker)
rss.image.setup_maker(maker)
end
image = new_rss.image
assert_equal(title, image.title)
assert_equal(link, image.link)
assert_equal(url, image.url)
assert_equal(width, image.width)
assert_equal(height, image.height)
assert_equal(description, image.description)
end
def test_setup_maker_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)
maker.textinput.title = title
maker.textinput.description = description
maker.textinput.name = name
maker.textinput.link = link
end
new_rss = RSS::Maker.make("0.91") do |maker|
rss.channel.setup_maker(maker)
rss.textinput.setup_maker(maker)
end
textInput = new_rss.channel.textInput
assert_equal(title, textInput.title)
assert_equal(description, textInput.description)
assert_equal(name, textInput.name)
assert_equal(link, textInput.link)
end
def test_setup_maker_items
title = "TITLE"
link = "http://hoge.com/"
description = "text hoge fuga"
item_size = 5
rss = RSS::Maker.make("0.91") do |maker|
setup_dummy_channel(maker)
item_size.times do |i|
item = maker.items.new_item
item.title = "#{title}#{i}"
item.link = "#{link}#{i}"
item.description = "#{description}#{i}"
end
end
new_rss = RSS::Maker.make("0.91") do |maker|
rss.channel.setup_maker(maker)
rss.items.each do |item|
item.setup_maker(maker)
end
end
assert_equal(item_size, new_rss.items.size)
new_rss.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
end
def test_setup_maker
encoding = "EUC-JP"
standalone = true
href = 'a.xsl'
type = 'text/xsl'
title = 'sample'
media = 'printer'
charset = 'UTF-8'
alternate = 'yes'
rss = RSS::Maker.make("0.91") do |maker|
maker.encoding = encoding
maker.standalone = standalone
xss = maker.xml_stylesheets.new_xml_stylesheet
xss.href = href
xss.type = type
xss.title = title
xss.media = media
xss.charset = charset
xss.alternate = alternate
setup_dummy_channel(maker)
end
new_rss = RSS::Maker.make("0.91") do |maker|
rss.setup_maker(maker)
end
assert_equal("0.91", new_rss.rss_version)
assert_equal(encoding, new_rss.encoding)
assert_equal(standalone, new_rss.standalone)
xss = rss.xml_stylesheets.first
assert_equal(1, rss.xml_stylesheets.size)
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)
end
end
end

View file

@ -0,0 +1,276 @@
require "rss-testcase"
require "rss/maker"
module RSS
class TestSetupMaker10 < TestCase
def setup
t = Time.iso8601("2000-01-01T12:00:05+00:00")
class << t
alias_method(:to_s, :iso8601)
end
@dc_elems = {
:title => "hoge",
:description =>
" XML is placing increasingly heavy loads on
the existing technical infrastructure of the Internet.",
:creator => "Rael Dornfest (mailto:rael@oreilly.com)",
:subject => "XML",
:publisher => "The O'Reilly Network",
:contributor => "hogehoge",
:type => "fugafuga",
:format => "hohoho",
:identifier => "fufufu",
:source => "barbar",
:language => "ja",
:relation => "cococo",
:rights => "Copyright (c) 2000 O'Reilly &amp; Associates, Inc.",
:date => t,
}
@sy_elems = {
:updatePeriod => "hourly",
:updateFrequency => 2,
:updateBase => t,
}
@content_elems = {
:encoded => "<em>ATTENTION</em>",
}
@trackback_elems = {
:ping => "http://bar.com/tb.cgi?tb_id=rssplustrackback",
:about => [
"http://foo.com/trackback/tb.cgi?tb_id=20020923",
"http://foo.com/trackback/tb.cgi?tb_id=20021010",
],
}
end
def test_setup_maker_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
@dc_elems.each do |var, value|
maker.channel.__send__("dc_#{var}=", value)
end
@sy_elems.each do |var, value|
maker.channel.__send__("sy_#{var}=", value)
end
end
new_rss = RSS::Maker.make("1.0") do |maker|
rss.channel.setup_maker(maker)
end
channel = new_rss.channel
assert_equal(about, channel.about)
assert_equal(title, channel.title)
assert_equal(link, channel.link)
assert_equal(description, channel.description)
assert_equal(true, channel.items.Seq.lis.empty?)
assert_nil(channel.image)
assert_nil(channel.textinput)
@dc_elems.each do |var, value|
assert_equal(channel.__send__("dc_#{var}"), value)
end
@sy_elems.each do |var, value|
assert_equal(channel.__send__("sy_#{var}"), value)
end
end
def test_setup_maker_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
@dc_elems.each do |var, value|
maker.image.__send__("dc_#{var}=", value)
end
end
new_rss = RSS::Maker.make("1.0") do |maker|
rss.channel.setup_maker(maker)
rss.image.setup_maker(maker)
end
image = new_rss.image
assert_equal(url, image.about)
assert_equal(url, new_rss.channel.image.resource)
assert_equal(title, image.title)
assert_equal(link, image.link)
assert_equal(url, image.url)
@dc_elems.each do |var, value|
assert_equal(image.__send__("dc_#{var}"), value)
end
end
def test_setup_maker_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
@dc_elems.each do |var, value|
maker.textinput.__send__("dc_#{var}=", value)
end
end
new_rss = RSS::Maker.make("1.0") do |maker|
rss.channel.setup_maker(maker)
rss.textinput.setup_maker(maker)
end
textinput = new_rss.textinput
assert_equal(link, textinput.about)
assert_equal(link, new_rss.channel.textinput.resource)
assert_equal(title, textinput.title)
assert_equal(name, textinput.name)
assert_equal(description, textinput.description)
assert_equal(link, textinput.link)
@dc_elems.each do |var, value|
assert_equal(textinput.__send__("dc_#{var}"), value)
end
end
def test_setup_maker_items
title = "TITLE"
link = "http://hoge.com/"
description = "text hoge fuga"
item_size = 5
rss = RSS::Maker.make("1.0") do |maker|
setup_dummy_channel(maker)
item_size.times do |i|
item = maker.items.new_item
item.title = "#{title}#{i}"
item.link = "#{link}#{i}"
item.description = "#{description}#{i}"
@dc_elems.each do |var, value|
item.__send__("dc_#{var}=", value)
end
@content_elems.each do |var, value|
item.__send__("content_#{var}=", value)
end
item.trackback_ping = @trackback_elems[:ping]
@trackback_elems[:about].each do |value|
new_about = item.trackback_abouts.new_about
new_about.value = value
end
end
end
new_rss = RSS::Maker.make("1.0") do |maker|
rss.channel.setup_maker(maker)
rss.items.each do |item|
item.setup_maker(maker)
end
end
assert_equal(item_size, new_rss.items.size)
new_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)
@dc_elems.each do |var, value|
assert_equal(item.__send__("dc_#{var}"), value)
end
@content_elems.each do |var, value|
assert_equal(item.__send__("content_#{var}"), value)
end
assert_equal(@trackback_elems[:ping], item.trackback_ping)
assert_equal(@trackback_elems[:about].size, item.trackback_abouts.size)
item.trackback_abouts.each_with_index do |about, i|
assert_equal(@trackback_elems[:about][i], about.value)
end
end
end
def test_setup_maker
encoding = "EUC-JP"
standalone = true
href = 'a.xsl'
type = 'text/xsl'
title = 'sample'
media = 'printer'
charset = 'UTF-8'
alternate = 'yes'
rss = RSS::Maker.make("1.0") do |maker|
maker.encoding = encoding
maker.standalone = standalone
xss = maker.xml_stylesheets.new_xml_stylesheet
xss.href = href
xss.type = type
xss.title = title
xss.media = media
xss.charset = charset
xss.alternate = alternate
setup_dummy_channel(maker)
end
new_rss = RSS::Maker.make("1.0") do |maker|
rss.setup_maker(maker)
end
assert_equal("1.0", new_rss.rss_version)
assert_equal(encoding, new_rss.encoding)
assert_equal(standalone, new_rss.standalone)
xss = rss.xml_stylesheets.first
assert_equal(1, rss.xml_stylesheets.size)
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)
end
end
end

View file

@ -0,0 +1,295 @@
require "rss-testcase"
require "rss/maker"
module RSS
class TestSetupMaker20 < TestCase
def test_setup_maker_channel
title = "fugafuga"
link = "http://hoge.com"
description = "fugafugafugafuga"
language = "ja"
copyright = "foo"
managingEditor = "bar"
webMaster = "web master"
rating = "6"
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|
new_day = maker.channel.skipDays.new_day
new_day.content = day
end
skipHours.each do |hour|
new_hour = maker.channel.skipHours.new_hour
new_hour.content = hour
end
categories.each do |category|
new_category = maker.channel.categories.new_category
new_category.content = category
end
maker.channel.generator = generator
maker.channel.ttl = ttl
end
new_rss = RSS::Maker.make("2.0") do |maker|
rss.channel.setup_maker(maker)
end
channel = new_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(lastBuildDate, channel.lastBuildDate)
skipDays.each_with_index do |day, i|
assert_equal(day, channel.skipDays.days[i].content)
end
skipHours.each_with_index do |hour, i|
assert_equal(hour, channel.skipHours.hours[i].content)
end
channel.categories.each_with_index do |category, i|
assert_equal(categories[i], category.content)
end
assert_equal(generator, channel.generator)
assert_equal(ttl, channel.ttl)
assert(channel.items.empty?)
assert_nil(channel.image)
assert_nil(channel.textInput)
end
def test_setup_maker_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
new_rss = RSS::Maker.make("2.0") do |maker|
rss.channel.setup_maker(maker)
rss.image.setup_maker(maker)
end
image = new_rss.image
assert_equal(title, image.title)
assert_equal(link, image.link)
assert_equal(url, image.url)
assert_equal(width, image.width)
assert_equal(height, image.height)
assert_equal(description, image.description)
end
def test_setup_maker_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
new_rss = RSS::Maker.make("2.0") do |maker|
rss.channel.setup_maker(maker)
rss.textinput.setup_maker(maker)
end
textInput = new_rss.channel.textInput
assert_equal(title, textInput.title)
assert_equal(description, textInput.description)
assert_equal(name, textInput.name)
assert_equal(link, textInput.link)
end
def test_setup_maker_items
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
guid_isPermaLink = true
guid_content = "http://inessential.com/2002/09/01.php#a2"
enclosure_url = "http://www.scripting.com/mp3s/weatherReportSuite.mp3"
enclosure_length = "12216320"
enclosure_type = "audio/mpeg"
source_url = "http://static.userland.com/tomalak/links2.xml"
source_content = "Tomalak's Realm"
category_domain = "http://www.fool.com/cusips"
category_content = "MSFT"
item_size = 5
rss = RSS::Maker.make("2.0") do |maker|
setup_dummy_channel(maker)
item_size.times do |i|
item = maker.items.new_item
item.title = "#{title}#{i}"
item.link = "#{link}#{i}"
item.description = "#{description}#{i}"
item.author = "#{author}#{i}"
item.comments = "#{comments}#{i}"
item.date = pubDate
item.guid.isPermaLink = guid_isPermaLink
item.guid.content = guid_content
item.enclosure.url = enclosure_url
item.enclosure.length = enclosure_length
item.enclosure.type = enclosure_type
item.source.url = source_url
item.source.content = source_content
category = item.categories.new_category
category.domain = category_domain
category.content = category_content
end
end
new_rss = RSS::Maker.make("2.0") do |maker|
rss.channel.setup_maker(maker)
rss.items.each do |item|
item.setup_maker(maker)
end
end
assert_equal(item_size, new_rss.items.size)
new_rss.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, item.pubDate)
assert_equal(guid_isPermaLink, item.guid.isPermaLink)
assert_equal(guid_content, item.guid.content)
assert_equal(enclosure_url, item.enclosure.url)
assert_equal(enclosure_length, item.enclosure.length)
assert_equal(enclosure_type, item.enclosure.type)
assert_equal(source_url, item.source.url)
assert_equal(source_content, item.source.content)
assert_equal(1, item.categories.size)
assert_equal(category_domain, item.category.domain)
assert_equal(category_content, item.category.content)
end
end
def test_setup_maker
encoding = "EUC-JP"
standalone = true
href = 'a.xsl'
type = 'text/xsl'
title = 'sample'
media = 'printer'
charset = 'UTF-8'
alternate = 'yes'
rss = RSS::Maker.make("2.0") do |maker|
maker.encoding = encoding
maker.standalone = standalone
xss = maker.xml_stylesheets.new_xml_stylesheet
xss.href = href
xss.type = type
xss.title = title
xss.media = media
xss.charset = charset
xss.alternate = alternate
setup_dummy_channel(maker)
end
new_rss = RSS::Maker.make("2.0") do |maker|
rss.setup_maker(maker)
end
assert_equal("2.0", new_rss.rss_version)
assert_equal(encoding, new_rss.encoding)
assert_equal(standalone, new_rss.standalone)
xss = rss.xml_stylesheets.first
assert_equal(1, rss.xml_stylesheets.size)
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)
end
end
end