Skip to content

Instantly share code, notes, and snippets.

@madx
Created June 26, 2009 12:32
Show Gist options
  • Save madx/136445 to your computer and use it in GitHub Desktop.
Save madx/136445 to your computer and use it in GitHub Desktop.
Using Xup to create a RSS feed
$:.unshift File.join(File.dirname(__FILE__), 'lib')
require 'time'
require 'xup'
require 'xup/modules/xml'
class Xup::Document::RSS < Xup::Context
use Xup::Modules::XML
end
context = Xup::Document::RSS.new do
instruct! :xml, :version => "1.0", :encoding => "UTF-8"
tag! :rss, '', :version => "2.0" do
tag! :channel do
tag! :title, "Yapok"
tag! :description, "Yapok"
tag! :link, "http://yapok.org/"
tag! :item do
tag! :title, "An item"
tag! :link, "http://yapok.org/post/an_item"
tag! :description, "Contents"
tag! :pubDate, Time.now.httpdate
tag! :guid, "http://yapok.org/post/an_item"
end
end
end
end
puts context.buffer
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Yapok</title>
<description>Yapok</description>
<link>http://yapok.org/</link>
<item>
<title>An item</title>
<link>http://yapok.org/post/an_item</link>
<description>Contents</description>
<pubDate>Fri, 26 Jun 2009 12:32:32 GMT</pubDate>
<guid>http://yapok.org/post/an_item</guid>
</item>
</channel>
</rss>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment