Created
June 3, 2009 12:39
-
-
Save regularfry/122959 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'builder' | |
xml = Builder::XmlMarkup.new | |
@recent_items = [ | |
{:title => "Item Title", | |
:description => "Item Description", | |
:pub_date => Date.today, | |
:guid => "10893750189756019760127", | |
:link => "http://linky.example.com", | |
:author_name => "Mr Sillypants"} | |
] | |
output = xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do | |
xml.channel do | |
xml.title("Feed Title") | |
xml.link("http://www.example.com") | |
xml.description "A silly description" | |
xml.language "en-gb" | |
xml.ttl "40" | |
for item in @recent_items | |
xml.item do | |
xml.title(item[:title]) | |
xml.description(item[:description]) if item[:description] | |
xml.pubDate(item[:pub_date]) | |
xml.guid(item[:guid]) | |
xml.link(item[:link]) | |
xml.tag!("dc:creator", item[:author_name]) if item[:author_name] | |
end | |
end | |
end | |
end | |
puts output | |
# >> <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Feed Title</title><link>http://www.example.com</link><description>A silly description</description><language>en-gb</language><ttl>40</ttl><item><title>Item Title</title><description>Item Description</description><pubDate>2009-06-03</pubDate><guid>10893750189756019760127</guid><link>http://linky.example.com</link><dc:creator>Mr Sillypants</dc:creator></item></channel></rss> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment