RSS Feed
Here’s the code for the behavior I’m using to help generate the RSS feed for this Web site:
class XMLFeedBehavior < Behavior::Base
register "XML Feed"
description %{
Modifies page headers so that the content type is set to text/xml.
Adds the <r:escape_html /> tag.
}
def page_headers
super.merge('Content-Type' => 'text/xml')
end
define_tags do
tag "escape_html" do |tag|
CGI.escapeHTML(tag.expand)
end
end
end
And the code from the page part:
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Fun With Radiant</title>
<link>http://radiantcms.org/</link>
<language>en-us</language>
<ttl>40</ttl>
<description>The main blog for Radiant CMS</description>
<r:find url="/blog/">
<r:children:each limit="10">
<item>
<title><r:title /></title>
<description><r:escape_html><r:content /></r:escape_html></description>
<pubDate><r:date format="%a, %d %b %Y %H:%M:%S GMT" /></pubDate>
<guid>http://radiantcms.org<r:url /></guid>
<link>http://radiantcms.org<r:url /></link>
</item>
</r:children:each>
</r:find>
</channel>
</rss>
Pretty nifty, eh?
