summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll/Render/Internal.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-12 13:09:50 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-12 13:09:50 +0100
commitecd00b386e2848cab19c16afdcaeae3133f39569 (patch)
treeffe8445b3435c4e8bd9cd915ad0523aa10f3a9bd /src/Text/Hakyll/Render/Internal.hs
parentef7ccb15149862e1213ed66a31d65fc577c32d58 (diff)
downloadhakyll-ecd00b386e2848cab19c16afdcaeae3133f39569.tar.gz
Added pure renderChain function.
Diffstat (limited to 'src/Text/Hakyll/Render/Internal.hs')
-rw-r--r--src/Text/Hakyll/Render/Internal.hs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/Text/Hakyll/Render/Internal.hs b/src/Text/Hakyll/Render/Internal.hs
index 5b3e0a2..eca15a0 100644
--- a/src/Text/Hakyll/Render/Internal.hs
+++ b/src/Text/Hakyll/Render/Internal.hs
@@ -4,12 +4,13 @@ module Text.Hakyll.Render.Internal
, regularSubstitute
, finalSubstitute
, pureRenderWith
+ , pureRenderChainWith
, writePage
) where
import qualified Data.Map as M
import Text.Hakyll.Context (Context, ContextManipulation)
-import Data.List (isPrefixOf)
+import Data.List (isPrefixOf, foldl')
import Data.Char (isAlpha)
import Data.Maybe (fromMaybe)
import Control.Parallel.Strategies (rnf, ($|))
@@ -45,14 +46,23 @@ finalSubstitute = substitute "$"
pureRenderWith :: ContextManipulation -- ^ Manipulation to apply on the context.
-> String -- ^ Template to use for rendering.
-> Context -- ^ Renderable object to render with given template.
- -> Page -- ^ The body of the result will contain the render.
+ -> Context -- ^ The body of the result will contain the render.
pureRenderWith manipulation template context =
-- Ignore $root when substituting here. We will only replace that in the
-- final render (just before writing).
let contextIgnoringRoot = M.insert "root" "$root" (manipulation context)
body = regularSubstitute template contextIgnoringRoot
-- Force the body to be rendered.
- in ($|) fromContext rnf (M.insert "body" body context)
+ in ($|) id rnf (M.insert "body" body context)
+
+-- | A pure renderChain function.
+pureRenderChainWith :: ContextManipulation
+ -> [String]
+ -> Context
+ -> Context
+pureRenderChainWith manipulation templates context =
+ let initial = manipulation context
+ in foldl' (flip $ pureRenderWith id) initial templates
-- | Write a page to the site destination. Final action after render
-- chains and such.