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,15 +65,20 @@ data RssFeedEntry url = RssFeedEntry
} }
template :: RssFeed url -> Hamlet url template :: RssFeed url -> Hamlet url
template arg = [$xhamlet| template arg =
#if __GLASGOW_HASKELL__ >= 700
[xhamlet|
#else
[$xhamlet|
#endif
%rss!version="2.0"!xmlns:atom="http://www.w3.org/2005/Atom" %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
@ -75,24 +86,20 @@ template arg = [$xhamlet|
|] |]
entryTemplate :: RssFeedEntry url -> Hamlet url entryTemplate :: RssFeedEntry url -> Hamlet url
entryTemplate arg = [$xhamlet| entryTemplate arg =
#if __GLASGOW_HASKELL__ >= 700
[xhamlet|
#else
[$xhamlet|
#endif
%item %item
%title $rssEntryTitle.arg$ %title $rssEntryTitle.arg$
%link @rssEntryLink.arg@ %link @rssEntryLink.arg@
%guid @rssEntryLink.arg@ %guid @rssEntryLink.arg@
%pubDate $format.rssEntryUpdated.arg$ %pubDate $formatRFC822.rssEntryUpdated.arg$
%description $rssEntryContent.arg$ %description $rssEntryContent.arg$
|] |]
-- | Format as string
format :: UTCTime -> String
format = formatTime defaultTimeLocale rfc822DateFormat
-- | 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
-> String -- ^ title -> String -- ^ title
@ -103,5 +110,5 @@ rssLink u title = addHamletHead
#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$
|] |]