[HTML (nearly done) and RSS stub
Manuel M T Chakravarty **20060428041241] {
addfile ./HTML.hs
addfile ./RSS.hs
hunk ./HTML.hs 1
+-- |A simple feed generator: HTML generator
+--
+-- Copyright (c) 2006 Manuel M T Chakravarty
+--
+-- License:
+--
+--- Description ---------------------------------------------------------------
+--
+-- Language: Haskell 98
+--
+-- Docs ----------------------------------------------------------------------
+--
+-- Introduction to Text.Html:
+--
+
+module HTML (
+ channelToHTML
+) where
+
+-- hierachical libraries
+import Control.Monad (
+ mplus, liftM2)
+import Text.Html
+
+-- lambdaFeed
+import Config (
+ Config(..))
+import Date (
+ Date, addMinutes)
+import Feed (
+ URL, Channel(..), Image(..), Category(..), Item(..), Enclosure(..),
+ GUID(..), Source(..))
+
+
+-- Render a channel to HTML.
+--
+channelToHTML :: Config -> Channel [Item] -> String
+channelToHTML config chan =
+ renderHtml $
+ header << concatHtml
+ [ thetitle <<
+ titleChan chan
+ , primHtml ""
+ , meta ! [httpequiv "Content-Type",
+ content "text/html; charset=iso-8859-1"]
+ -- FIXME: We should be able to parametrise the charset!!
+ , languageChan chan `optional`
+ \lang -> meta ! [httpequiv "Content-Language", content lang]
+ , (liftM2 addMinutes (lastBuildDateChan chan) (ttlChan chan)) `optional`
+ \expiryDate -> meta ! [httpequiv "expires",
+ content (show expiryDate)]
+ , generatorChan chan `optional`
+ \gen -> meta ! [name "generator", content gen]
+ , copyrightChan chan `optional`
+ \cr -> meta ! [name "copyright", content cr]
+ , (pubDateChan chan `mplus` lastBuildDateChan chan) `optional`
+ \date -> meta ! [name "date", content (show date)]
+ -- NB: `pubDate' takes preference
+ ]
+ +++
+ body << concatHtml
+ [ h1 << titleChan chan
+ , imageChan chan `optional` imageToHTML
+ , p << descriptionChan chan
+ ]
+ +++
+ map itemToHTML (itemsChan chan)
+
+-- Render an channel image element in HTML.
+--
+imageToHTML :: Image -> Html
+imageToHTML img =
+ anchor ! ([href (linkImage img)] ++
+ descriptionImage img `optionalAttr` title) <<
+ image ! ([ src (urlImage img)
+ , alt (urlImage img)
+ ] ++
+ ((widthImage img `mplus` Just 88) `optionalAttr` (width.show))++
+ ((heightImage img `mplus` Just 31) `optionalAttr` height))
+ -- defaults from RSS 2.0 spec
+
+-- Render an item in HTML.
+--
+itemToHTML :: Item -> Html
+itemToHTML item = noHtml -- !!!FIXME
+
+-- Render an optional element.
+--
+optional :: Maybe a -> (a -> Html) -> Html
+optional = flip (maybe noHtml)
+
+-- Render an optional attribute.
+--
+optionalAttr :: Maybe a -> (a -> HtmlAttr) -> [HtmlAttr]
+optionalAttr Nothing _ = []
+optionalAttr (Just x) attr = [attr x]
hunk ./RSS.hs 1
+-- |A simple feed generator: RSS 2.0 generator
+--
+-- Copyright (c) 2006 Manuel M T Chakravarty
+--
+-- License:
+--
+--- Description ---------------------------------------------------------------
+--
+-- Language: Haskell 98
+--
+
+module RSS (
+ channelToRSS
+) where
+
+-- lambdaFeed
+import Config (Config(..))
+import Feed (
+ URL, Channel(..), Image(..), Category(..), Item(..), Enclosure(..),
+ GUID(..), Source(..))
+
+
+-- Render a channel to RSS.
+--
+channelToRSS :: Config -> Channel [Item] -> String
+channelToRSS config chan = ""
}