* Dave Hodgkinson <[EMAIL PROTECTED]> [2002-05-29 17:58]:
> Anyone got any quick and dirty templates tips for _generating_ RSS? It
> smells like a simple standalone template and/or view with maybe a DBI
> plugin.
> 
> Any other offers?

Here's a patch to Template::Plugin::XML::RSS; when applied, you can do
this:

  [% USE  news = XML.RSS("version", "0.9");
     CALL news.channel("title", "foo", "link", "bar");
     CALL news.image("title", "fooimage", "url", "fooimage.gif");
     CALL news.add_item("title", "item one", "link", "link one");
     CALL news.add_item("title", "item two", "link", "link two");
     news.as_string;
  %]

(Use real values for the attributes, of course).

The basic idea is:  if there is one argument passed to XML.RSS, it's a
filename; otherwise, you are creating a new RSS file (XML::RSS requires
"version" and a version number in this case).  Pretty simplistic, but it
works.  BTW, the results from the above look like:

  <?xml version="1.0"?>

  <rdf:RDF
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
  xmlns="http://my.netscape.com/rdf/simple/0.9/";>

  <channel>
  <title>foo</title>
  <link>bar</link>
  <description></description>
  </channel>

  <image>
  <title>fooimage</title>
  <url>fooimage.gif</url>
  </image>

  <item>
  <title>item one</title>
  <link>link one</link>
  </item>

  <item>
  <title>item two</title>
  <link>link two</link>
  </item>

And, the patch:

--- RSS.pm.orig Thu May 30 09:14:15 2002
+++ RSS.pm      Thu May 30 13:43:45 2002
@@ -44,12 +44,19 @@ sub new {
     return $class->fail('No filename specified')
        unless $filename;
     
-    my $rss = XML::RSS->new
+    my $rss;
+    if (@_) {
+       $rss = XML::RSS->new(@_)
+           or return $class->fail('failed to create XML::RSS');
+    } else {
+       $rss = XML::RSS->new
        or return $class->fail('failed to create XML::RSS');
 
     eval { $rss->parsefile($filename) } and not $@
        or return $class->fail("failed to parse $filename: $@");
 
+    }
+
     return $rss;
 }

(darren)

-- 
How is it possible to find meaning in a finite world, given my waist
and shirt size?
    -- Woody Allen


Reply via email to