Minor fixes

* Added GHC7 checks where missing
  * used typeRss whenever possible
  * added formatRFC822
  * minor whitespace changes
This commit is contained in:
patrick brisbin 2011-01-16 17:57:22 -05:00
parent 76eabc2969
commit b530166c09

View File

@ -23,11 +23,17 @@ import Yesod.Handler
import Yesod.Content import Yesod.Content
import Yesod.Widget import Yesod.Widget
import Text.Hamlet import Text.Hamlet
import System.Locale (defaultTimeLocale)
import Data.Time.Clock (UTCTime) import Data.Time.Clock (UTCTime)
import Data.Time.Format (formatTime)
-- | note: This would normally be added in Yesod.Content -- | FIXME unneeded if formatRFC822 moves
import Data.Time.Format (formatTime)
import System.Locale (defaultTimeLocale)
-- | FIXME move this to Yesod.Content
formatRFC822 :: UTCTime -> String
formatRFC822 = formatTime defaultTimeLocale "%a, %d %b %Y %H:%M:%S %z"
-- | FIXME move this to Yesod.Content
typeRss :: ContentType typeRss :: ContentType
typeRss = "application/rss+xml" typeRss = "application/rss+xml"
@ -59,39 +65,40 @@ data RssFeedEntry url = RssFeedEntry
} }
template :: RssFeed url -> Hamlet url template :: RssFeed url -> Hamlet url
template arg = [$xhamlet| template arg =
%rss!version="2.0"!xmlns:atom="http://www.w3.org/2005/Atom" #if __GLASGOW_HASKELL__ >= 700
[xhamlet|
#else
[$xhamlet|
#endif
%rss!version="2.0"!xmlns:atom="http://www.w3.org/2005/Atom"
%channel %channel
%atom:link!href=@rssLinkSelf.arg@!rel="self"!type="application/rss+xml" %atom:link!href=@rssLinkSelf.arg@!rel="self"!type=$typeRss$
%title $rssTitle.arg$ %title $rssTitle.arg$
%link @rssLinkHome.arg@ %link @rssLinkHome.arg@
%description $rssDescription.arg$ %description $rssDescription.arg$
%lastBuildDate $format.rssUpdated.arg$ %lastBuildDate $formatRFC822.rssUpdated.arg$
%language $rssLanguage.arg$ %language $rssLanguage.arg$
$forall rssEntries.arg entry $forall rssEntries.arg entry
^entryTemplate.entry^ ^entryTemplate.entry^
|] |]
entryTemplate :: RssFeedEntry url -> Hamlet url entryTemplate :: RssFeedEntry url -> Hamlet url
entryTemplate arg = [$xhamlet| entryTemplate arg =
%item #if __GLASGOW_HASKELL__ >= 700
%title $rssEntryTitle.arg$ [xhamlet|
%link @rssEntryLink.arg@ #else
%guid @rssEntryLink.arg@ [$xhamlet|
%pubDate $format.rssEntryUpdated.arg$ #endif
%description $rssEntryContent.arg$ %item
|] %title $rssEntryTitle.arg$
%link @rssEntryLink.arg@
-- | Format as string %guid @rssEntryLink.arg@
format :: UTCTime -> String %pubDate $formatRFC822.rssEntryUpdated.arg$
format = formatTime defaultTimeLocale rfc822DateFormat %description $rssEntryContent.arg$
|]
-- | System.Local.rfc822DateFormat disagrees with date -R and does not
-- validate, this one does.
rfc822DateFormat :: String
rfc822DateFormat = "%a, %d %b %Y %H:%M:%S %z"
-- | Generates a link tag in the head of a widget. -- | Generates a link tag in the head of a widget.
rssLink :: Route m rssLink :: Route m
@ -99,9 +106,9 @@ rssLink :: Route m
-> GWidget s m () -> GWidget s m ()
rssLink u title = addHamletHead rssLink u title = addHamletHead
#if __GLASGOW_HASKELL__ >= 700 #if __GLASGOW_HASKELL__ >= 700
[hamlet| [hamlet|
#else #else
[$hamlet| [$hamlet|
#endif #endif
%link!href=@u@!type="application/rss+xml"!rel="alternate"!title=$title$ %link!href=@u@!type=$typeRss$!rel="alternate"!title=$title$
|] |]