wpart_rss

Overview

Each RSS channel looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>SOME TITLE</title>
    <link>LINK TO THE SITE</link>
    <description>
      CHANNEL DESCRIPTION
    </description>
    <language>CHANNEL LANGUAGE</language>
    CHANNEL ITEMS
  </channel>
</rss>

Each channel item is as follows:

<item>
        <title>ITEM TITLE</title>
        <link>ITEM LINK</link>
        <pubDate>ITEM PUBLICATION DATE</pubDate>
        <description>ITEM DESCRIPTION</description>
        <category>ITEM CATEGORY</category>
</item>

Having the skeletons prepared, wpart_rss allows users to provide only the generator of the content and it gives the complete feed in return.

Records

The wpart_rss component defines two new records:

   1 -record(rss, {
   2           title = "", 
   3           link = "",
   4           description = "",
   5           language = "en"
   6          }).
   7 
   8 -record(rss_item, {
   9           title = "",
  10           link = "",
  11           publication_date = "",
  12           description = "",
  13           category = ""
  14          }).

In order to include them in your application, you must add the following directive to your module:

   1 -include_lib("wpart_rss/include/rss.hrl").

API

Example

   1 -module(rss).
   2 -export([dataflow/1, error/2]).
   3 -export([rss/1]).
   4 
   5 -export([rss_channel/0, rss_item/1]).
   6 
   7 -include_lib("wpart_rss/include/rss.hrl").
   8 
   9 dataflow(rss) -> [].
  10 
  11 error(_, _) -> 
  12   ok.
  13 
  14 rss(_) ->
  15   {content, html, wpart_rss:create_channel(?MODULE, rss_channel, rss_item, 
  16                   [[{title, "Dog article"}, {resource, "/dog"}, 
  17                       {description, "Why do people love dogs"}, {category, "animals"}],
  18                    [{title, "IE"}, {resource, "/dev/null"}, 
  19                       {description, "Why some programs should be banned"}, {category, "crap code"}]])}.
  20 
  21 rss_channel() ->
  22   #rss{title = "My service RSS feed",
  23        link = "http://" ++ e_conf:host() ++ "/rss",
  24        description = "hot and fresh RSS"}.
  25 
  26 rss_item(Item) ->
  27   #rss_item{title = proplists:get_value(title, Item),
  28             link = "http://" ++ e_conf:host() ++ "/" ++ proplists:get_value(category, Item) ++ 
  29                      proplists:get_value(resource, Item),
  30             publication_date = wtype_date:get_date("SDAY, DD SMONTH YYYY ", date()) ++ 
  31                                  wtype_time:format("HH:MM:SS", time()),
  32             description = wtype_html:htmlize(proplists:get_value(description, Item),
  33             category = proplists:get_value(category, Item)}.

Ecomponents/wpart_rss (last edited 2009-03-20 14:28:41 by Michal Ptaszek)