Skip to content

Commit

Permalink
Documentation++, added copyValue function.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspervdj committed Mar 6, 2010
1 parent 1736710 commit 89d6cb2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion data/templates/rss.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0" encoding="utf8"?>
<rss version="2.0">
<channel>
<title>$title</title>
Expand Down
11 changes: 9 additions & 2 deletions src/Text/Hakyll/Context.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Text.Hakyll.Context
, ContextManipulation
, renderValue
, changeValue
, copyValue
, renderDate
, changeExtension
) where
Expand Down Expand Up @@ -31,9 +32,9 @@ renderValue :: String -- ^ Key of which the value should be copied.
-> String -- ^ Key the value should be copied to.
-> (String -> String) -- ^ Function to apply on the value.
-> ContextManipulation
renderValue src dst f context = case M.lookup src context of
renderValue source destination f context = case M.lookup source context of
Nothing -> context
(Just value) -> M.insert dst (f value) context
(Just value) -> M.insert destination (f value) context

-- | Change a value in a @Context@.
--
Expand All @@ -46,6 +47,12 @@ changeValue :: String -- ^ Key to change.
-> ContextManipulation
changeValue key = renderValue key key

-- | Copy a value from one key to another in a @Context@.
copyValue :: String -- ^ Source key.
-> String -- ^ Destination key.
-> ContextManipulation
copyValue source destination = renderValue source destination id

-- | When the context has a key called @path@ in a @yyyy-mm-dd-title.extension@
-- format (default for pages), this function can render the date.
--
Expand Down
1 change: 1 addition & 0 deletions src/Text/Hakyll/RenderAction.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- | This is the module which exports @RenderAction@.
module Text.Hakyll.RenderAction
( RenderAction (..)
, createRenderAction
Expand Down
31 changes: 21 additions & 10 deletions src/Text/Hakyll/Rss.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
-- | A Module that allows easy rendering of RSS feeds.
-- | A Module that allows easy rendering of RSS feeds. If you use this module,
-- you must make sure you set the `absoluteUrl` field in the main Hakyll
-- configuration.
module Text.Hakyll.Rss
( RssConfiguration (..)
, renderRss
Expand All @@ -16,6 +18,7 @@ import Text.Hakyll.RenderAction (Renderable)

import Paths_hakyll

-- | This is a data structure to keep the configuration of an RSS feed.
data RssConfiguration = RssConfiguration
{ -- | Url of the RSS feed (relative to site root). For example, @rss.xml@.
rssUrl :: String
Expand All @@ -25,11 +28,13 @@ data RssConfiguration = RssConfiguration
rssDescription :: String
}

createRssWith :: ContextManipulation
-> RssConfiguration
-> [Renderable]
-> FilePath
-> FilePath
-- | This is an auxiliary function to create a listing that is, in fact, an RSS
-- feed.
createRssWith :: ContextManipulation -- ^ Manipulation to apply on the items.
-> RssConfiguration -- ^ Feed configuration.
-> [Renderable] -- ^ Items to include.
-> FilePath -- ^ RSS feed template.
-> FilePath -- ^ RSS item template.
-> Renderable
createRssWith manipulation configuration renderables template itemTemplate =
listing >>> render template
Expand All @@ -42,12 +47,18 @@ createRssWith manipulation configuration renderables template itemTemplate =
, ("description", rssDescription)
]

renderRss :: RssConfiguration -> [Renderable] -> Hakyll ()
-- | Render an RSS feed with a number of items.
renderRss :: RssConfiguration -- ^ Feed configuration.
-> [Renderable] -- ^ Items to include in the feed.
-> Hakyll ()
renderRss = renderRssWith id

renderRssWith :: ContextManipulation
-> RssConfiguration
-> [Renderable]
-- | Render an RSS feed with a number of items. This function allows you to
-- specify a @ContextManipulation@ which will be applied on every
-- @Renderable@.
renderRssWith :: ContextManipulation -- ^ Manipulation to apply on the items.
-> RssConfiguration -- ^ Feed configuration.
-> [Renderable] -- ^ Items to include in the feed.
-> Hakyll ()
renderRssWith manipulation configuration renderables = do
template <- liftIO $ getDataFileName "templates/rss.xml"
Expand Down

0 comments on commit 89d6cb2

Please sign in to comment.