packages feed

snap-app 0.4.0 → 0.5.0

raw patch · 3 files changed

+46/−3 lines, 3 filesdep +feeddep +old-localedep +time

Dependencies added: feed, old-locale, time, xml

Files

snap-app.cabal view
@@ -1,5 +1,5 @@ name:                snap-app-version:             0.4.0+version:             0.5.0 synopsis:            Simple modules for writing apps with Snap, abstracted from hpaste. homepage:            Simple modules for writing apps with Snap, abstracted from hpaste. license:             BSD3@@ -14,7 +14,7 @@   ghc-options:       -O2   hs-source-dirs:    src   exposed-modules:   Snap.App, Snap.App.Types, Snap.App.Controller, Snap.App.Model, Snap.App.Migrate,-                     Snap.App.Cache,+                     Snap.App.Cache, Snap.App.XML, Snap.App.RSS,                      Data.Pagination, Text.Blaze.Extra, Text.Blaze.Pagination,                      Control.Monad.Env, Data.Monoid.Operator,                      Network.URI.Params@@ -34,4 +34,8 @@                      cgi,                      data-default,                      filepath,-                     directory+                     directory,+                     feed,+                     xml,+                     old-locale,+                     time
+ src/Snap/App/RSS.hs view
@@ -0,0 +1,30 @@+module Snap.App.RSS where++import           Data.Text (Text)+import qualified Data.Text as T+import           Data.Time+import           Snap.App+import           Snap.App.XML+import           System.Locale+import           Text.Feed.Export+import           Text.Feed.Types+import           Text.RSS.Syntax+import           Text.XML.Light+import           Text.XML.Light++-- | Output the given XML element.+outputRSS :: String -> String -> [(UTCTime,Text,Text)] -> Controller c s ()+outputRSS title link = outputXML . makeFeed title link++-- | Make a simple RSS feed.+makeFeed :: String -> String -> [(UTCTime,Text,Text)] -> Element+makeFeed title link = xmlFeed . RSSFeed . makeRSS where+  makeRSS qs = (nullRSS title link)+               { rssChannel = makeChannel qs }+  makeChannel qs = (nullChannel title link)+                   { rssItems = map makeItem qs }+  makeItem (time,title,desc) = (nullItem (T.unpack title))+                               { rssItemPubDate = return (toPubDate time)+                               , rssItemDescription = return (T.unpack desc)+                               }+  toPubDate = formatTime defaultTimeLocale "%a, %d %b %Y %H:%M:%S UT"
+ src/Snap/App/XML.hs view
@@ -0,0 +1,9 @@+module Snap.App.XML where++import Text.XML.Light+import Snap.App+import qualified Data.Text as T++-- | Output the given XML element.+outputXML :: Element -> Controller c s ()+outputXML = writeText . T.pack . showElement