Play framework template for RSS Subscribe Pub

Wanted to add RSS to my dinky geeky wiki/blog platform but couldn't find an already written play template for that, if you can believe it.

Well, didn't take too long and, after playing with some RSS validators whatnot, there now is one. Enjoy!

Note that XML templates are compiled in a views.xml... package instead of the usual views.html... package.

@(page:model.WikiEntry, items:List[model.UWID])<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
  <channel>
    <title>@page.label</title>
    <link>@page.wid.url</link>
    <description>TODO feed description</description>

    @defining(org.joda.time.format.DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss Z")) {fmt=>
    @items.flatMap(_.page).sortWith(_.crDtm isAfter _.crDtm).take(50).map {we=>
    <item>
        <title>@we.label</title>
        <link>@we.wid.url</link>
        <pubDate>@fmt.print(we.crDtm)</pubDate>
        <guid>@we.wid.url</guid>
        <description>TODO description @we.crDtm</description>
    </item>
    }
    }
  </channel>
</rss>

** Note** leave the xml header in the first line, otherwise it gets hairy - that's some play framework weirding factor. Otherwise, using this play xml template is pretty simple:

      Ok(views.xml.wiki.wikiRss(w, linksTo(w)))

You can see it in action in this blog: razie.dieselapps.com/wiki/Cool_Scala/rss.xml.

Also, if you need a geeky wiki blog like this one, get one (or a few) at www.dieselreactor.net.

Enjoy!


Was this useful?    

By: Razie | 2014-11-13 .. 2016-05-16 | Tags: post , scala , play , programming


See more in: Cool Scala Subscribe

Viewed 1435 times ( | History | Print ) this page.

You need to log in to post a comment!