Skip to content

Instantly share code, notes, and snippets.

@regularfry
Created June 3, 2009 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save regularfry/122959 to your computer and use it in GitHub Desktop.
Save regularfry/122959 to your computer and use it in GitHub Desktop.
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