') { |atom|
atom.title "foo"
}.elements['html/body/h1'].text.should == 'foo'
end
it "should support owner_name" do
tmpl('') { |atom|
atom.author { atom.name "me" }
}.elements['html/body/a'].text.should == 'me'
end
it "should support rights" do
tmpl('
') { |atom|
atom.rights "public domain"
}.elements['html/body/p'].text.should == 'public domain'
end
it "should support subtitle" do
tmpl('
') { |atom|
atom.subtitle "foo"
}.elements['html/body/h2'].text.should == 'foo'
end
it "should support title" do
tmpl('
') { |atom|
atom.title "foo"
}.elements['html/body/h1'].text.should == 'foo'
end
it "should support title_plain" do
tmpl('
') { |atom|
atom.title "foo"
}.elements['html/body/h1'].text.should == 'foo'
end
it "should support url" do
tmpl('foo') { |atom|
atom.link :rel=>'alternate', :href=>'http://example.com/'
}.elements['html/body/a/@href'].value.should == 'http://example.com/'
end
end
describe "entry" do
it "should support author" do
itmpl('') { |atom|
atom.author { atom.name "Herman Melville" }
}.elements['html/body/a'].text.should == 'Herman Melville'
end
it "should support author_name" do
itmpl('') { |atom|
atom.author { atom.name "Herman Melville" }
}.elements['html/body/a'].text.should == 'Herman Melville'
end
it "should support author_email" do
itmpl('') { |atom|
atom.author { atom.email "me@hotmail.com" }
}.elements['html/body/a'].text.should == 'me@hotmail.com'
end
it "should support author_uri" do
itmpl('') { |atom|
atom.author { atom.uri "http://example.org/" }
}.elements['html/body/a'].text.should == 'http://example.org/'
end
it "should support content_language" do
itmpl('
foo
') { |atom|
atom.content "xml:lang" => "de"
}.elements['html/body/div/@lang'].value.should == 'de'
end
it "should support date" do
itmpl('') { |atom|
atom.entry 'xmlns:planet' => 'http://planet.intertwingly.net/' do
atom.updated "planet:format" => "May 03, 2008 10:59 PM"
end
}.elements['html/body/time'].text.should == 'May 03, 2008 10:59 PM'
end
it "should support date_iso" do
itmpl('') { |atom|
atom.updated "2008-05-03T22:59:00-05:00"
}.elements['html/body/time'].text.should == '2008-05-03T22:59:00-05:00'
end
it "should support enclosure_href" do
itmpl('foo') { |atom|
atom.link :rel=>'enclosure', :href=>'http://example.com/a.mp3'
}.elements['html/body/a/@href'].value.should == 'http://example.com/a.mp3'
end
it "should support enclosure_length" do
itmpl(' bytes') { |atom|
atom.link :rel=>'enclosure', :length=>32000
}.elements['html/body/span'].text.should == '32000 bytes'
end
it "should support enclosure_type" do
itmpl('()') { |atom|
atom.link :rel=>'enclosure', :type=>'audio/mpeg'
}.elements['html/body/span'].text.should == '(audio/mpeg)'
end
it "should support id" do
itmpl('') { |atom|
atom.id "42"
}.elements['html/body/a/@id'].value.should == '42'
end
it "should support link" do
itmpl('foo') { |atom|
atom.link :rel=>'alternate', :href=>'http://example.com/'
}.elements['html/body/a/@href'].value.should == 'http://example.com/'
end
it "should support published" do
itmpl('') { |atom|
atom.entry 'xmlns:planet' => 'http://planet.intertwingly.net/' do
atom.published "planet:format" => "May 03, 2008 10:59 PM"
end
}.elements['html/body/time'].text.should == 'May 03, 2008 10:59 PM'
end
it "should support published_iso" do
itmpl('') { |atom|
atom.published "2008-05-03T22:59:00-05:00"
}.elements['html/body/time'].text.should == '2008-05-03T22:59:00-05:00'
end
it "should support rights" do
itmpl('
') { |atom|
atom.rights "public domain"
}.elements['html/body/p'].text.should == 'public domain'
end
it "should support title" do
itmpl('
') { |atom|
atom.title "foo"
}.elements['html/body/h2'].text.should == 'foo'
end
it "should support title_language" do
itmpl('
foo
') { |atom|
atom.title "xml:lang" => "de"
}.elements['html/body/div/@lang'].value.should == 'de'
end
it "should support title_plain" do
itmpl('
') { |atom|
atom.title "foo"
}.elements['html/body/h2'].text.should == 'foo'
end
it "should support summary_language" do
itmpl('
foo
') { |atom|
atom.summary "xml:lang" => "de"
}.elements['html/body/div/@lang'].value.should == 'de'
end
it "should support updated" do
itmpl('') { |atom|
atom.entry 'xmlns:planet' => 'http://planet.intertwingly.net/' do
atom.updated "planet:format" => "May 03, 2008 10:59 PM"
end
}.elements['html/body/time'].text.should == 'May 03, 2008 10:59 PM'
end
it "should support updated_iso" do
itmpl('') { |atom|
atom.updated "2008-05-03T22:59:00-05:00"
}.elements['html/body/time'].text.should == '2008-05-03T22:59:00-05:00'
end
end
describe "channel" do
it "should support channel_face" do
itmpl('') { |atom|
atom.source 'xmlns:planet' => 'http://planet.intertwingly.net/' do
atom.planet :face, "jimbo"
end
}.elements['html/body/img/@src'].value.should == 'images/jimbo'
end
it "should support channel_link" do
itmpl('foo') { |atom|
atom.source { atom.link :rel=>'alternate', :href=>'http://example.com' }
}.elements['html/body/a/@href'].value.should == 'http://example.com'
end
it "should support channel_title" do
itmpl('
') { |atom|
atom.source { atom.title 'something witty' }
}.elements['html/body/h2'].text.should == 'something witty'
end
it "should support channel_title_plain" do
itmpl('foo') { |atom|
atom.source { atom.title 'something witty' }
}.elements['html/body/a/@title'].value.should == 'something witty'
end
end
describe "new" do
it "should support date" do
itmpl('
' +
'
') { |atom|
atom.feed 'xmlns:planet' => 'http://planet.intertwingly.net/' do
atom.entry do
atom.title 1
atom.updated "2008-05-03T10:59-05:00",
"planet:format" => "May 03, 2008 10:59 PM"
end
atom.entry do
atom.title 2
atom.updated "2008-05-03T03:59-05:00",
"planet:format" => "May 03, 2008 03:59 PM"
end
atom.entry do
atom.title 3
atom.updated "2008-05-02T10:59-05:00",
"planet:format" => "May 02, 2008 10:59 PM"
end
atom.entry do
atom.title 4
atom.updated "2008-05-02T03:59-05:00",
"planet:format" => "May 02, 2008 03:59 PM"
end
atom.entry do
atom.title 5
atom.updated "2008-05-01T10:59-05:00",
"planet:format" => "May 01, 2008 10:59 PM"
end
end
}.elements['html/body'].to_s.should == '' +
'
May 03, 2008
1
2
' +
'
May 02, 2008
3
4
' +
'
May 01, 2008
5
'
end
it "should support channel" do
itmpl('
' +
'
') { |atom|
atom.feed 'xmlns:planet' => 'http://planet.intertwingly.net/' do
atom.entry do
atom.title 1
atom.source {atom.id 1; atom.title 'a'}
end
atom.entry do
atom.title 2
atom.source {atom.id 1; atom.title 'a'}
end
atom.entry do
atom.title 3
atom.source {atom.id 2; atom.title 'b'}
end
atom.entry do
atom.title 4
atom.source {atom.id 2; atom.title 'b'}
end
atom.entry do
atom.title 5
atom.source {atom.id 1; atom.title 'a'}
end
end
}.elements['html/body'].to_s.should == '' +
'
a
1
2
' +
'
b
3
4
' +
'
a
5
'
end
end
# support method: apply a template against a feed
def tmpl(tmpl)
feed = REXML::Document.new(yield(Builder::XmlMarkup.new))
if feed.root.name != 'feed'
feed << REXML::Element.new('feed').add_element(feed.root).parent
end
feed.root.add_namespace 'http://www.w3.org/2005/Atom'
REXML::Document.new(Planet::Xslt.process(tmpl2xslt(tmpl).to_s, feed))
end
# support method: apply a "item" template against an entry
def itmpl(tmpl, &block)
entry = REXML::Document.new(block.call(Builder::XmlMarkup.new))
if entry.root.name != 'feed'
if entry.root.name != 'entry'
entry << REXML::Element.new('entry').add_element(entry.root).parent
end
entry << REXML::Element.new('feed').add_element(entry.root).parent
end
entry.root.add_namespace 'http://www.w3.org/2005/Atom'
tmpl = "#{tmpl}"
REXML::Document.new(Planet::Xslt.process(tmpl2xslt(tmpl).to_s, entry))
end