For those of you not “in-the-know” stan is a pure python syntax for generating xml typically used for html by nevow. stan is part of nevow and a typical stan expression looks something like this.
html[ head[ title[“Foo”], ], body[ h1(align=“center”)[“Bar”] ] ]
But like I said, stan is great for generating ANY XML. So i looked up the RSS 2.0 spec and got to hacking. With web applications these days particularly blogs and the like, the system is useless unless you generate RSS feeds. So I wrote a stan dialect. The source is available temporarily here. Here’s an example of the RSS stan dialect.
rss(version=“2.0”)[ channel[ title[“My Stan Generated RSS Feed”], link[“http://dreid.org/rss.py”], description[“An example RSS feed generated by a stan rss dialect.”], item[ title[“Woo a title”], pubDate[“Fri, 28 May 2004 01:29:00 PST”] description[“An example item”] ] ] ]
Now that’s all fine and dandy, you can use a very basic nevow.rend.Page to render that as html. Or I hear rumors of lore+stan integration.
I also wrote an RssPage to accompany the stan dialect. It’s very simple ... all keyword args passed to it are assumed to be channel sub-elements (put inside the channel tag).
There is also a special keyword argument called “items” which is a list of dicts corresponding to item entries. All keys in the items dicts are assumed to be valid item sub-elements and are handled as such. RssPage is kind of hacky at this point ... but it shows the flexibility of using stan to generate the RSS Feeds. Here is a very basic usage example right out of the rss.py.
items = [
{‘title’: “Test Item #1”,
‘description’: “this is the 1st test item for the stan rss dialect rsspage”,
‘pubDate’: “Sun, 29 Sep 2002 19:59:01 GMT”},
{‘title’: “Test Item #2”,
‘description’: “this is the 2nd test item for the stan rss dialect rsspage”,
‘pubDate’: “Sun, 28 Sep 2002 19:59:01 GMT”},
]
page = RssPage(
title=“Test”,
link=“http://test/”,
description=“test of the stan rss dialect and RssPage”,
items=items)
And the output. (Cleaned up to prevent sidescrolling madness)
<rss version=“2.0”> <channel> <link>http://test/</link> <description>test of the stan rss dialect and RssPage</description> <title>Test</title> <item> <description>this is the 1st test item for the stan rss dialect rsspage</description> <pubDate>Sun, 29 Sep 2002 19:59:01 GMT</pubDate> <title>Test Item #1</title> </item> <item> <description>this is the 2nd test item for the stan rss dialect rsspage</description> <pubDate>Sun, 28 Sep 2002 19:59:01 GMT</pubDate> <title>Test Item #2</title> </item> </channel> </rss>
Woo isn’t that cool?