on master help sign in
Added pure renderAndConcat function.
commita26f84dab5a49ce0fa00c7a0acfe84059451db5b authorJasper Van der Jeugt <jaspervdj@gmail.com> dateTue 12 Jan 2010, 14:48 (17 years ago) parentecd00b3
2 files changed+18−9
src/Text/Hakyll/Render.hs+5−9 src/Text/Hakyll/Render/Internal.hs+13
src/Text/Hakyll/Render.hs+5−9
@@ -10,7 +10,7 @@ module Text.Hakyll.Render
1010 , css
1111 ) where
1212
13−import Control.Monad (unless, mapM, foldM)
13+import Control.Monad (unless, mapM)
1414
1515import System.Directory (copyFile)
1616import System.IO
@@ -64,14 +64,10 @@ renderAndConcatWith :: Renderable a
6464 -> FilePath
6565 -> [a]
6666 -> IO String
67−renderAndConcatWith manipulation templatePath renderables =
68− foldM concatRender' [] renderables
69− where
70− concatRender' :: Renderable a => String -> a -> IO String
71− concatRender' chunk renderable = do
72− rendered <- renderWith manipulation templatePath renderable
73− let body = getBody rendered
74− return $ chunk ++ body
67+renderAndConcatWith manipulation templatePath renderables = do
68+ template <- readFile templatePath
69+ contexts <- mapM toContext renderables
70+ return $ pureRenderAndConcatWith manipulation template contexts
7571
7672-- | Chain a render action for a page with a number of templates. This will
7773-- also write the result to the site destination. This is the preferred way
src/Text/Hakyll/Render/Internal.hs+13
@@ -4,6 +4,7 @@ module Text.Hakyll.Render.Internal
44 , regularSubstitute
55 , finalSubstitute
66 , pureRenderWith
7+ , pureRenderAndConcatWith
78 , pureRenderChainWith
89 , writePage
910 ) where
@@ -55,6 +56,18 @@ pureRenderWith manipulation template context =
5556 -- Force the body to be rendered.
5657 in ($|) id rnf (M.insert "body" body context)
5758
59+-- | A pure renderAndConcat function.
60+pureRenderAndConcatWith :: ContextManipulation
61+ -> String -- ^ Template to use.
62+ -> [Context] -- ^ Different renderables.
63+ -> String
64+pureRenderAndConcatWith manipulation template contexts =
65+ foldl' renderAndConcat [] contexts
66+ where
67+ renderAndConcat chunk context =
68+ let rendered = pureRenderWith manipulation template context
69+ in chunk ++ fromMaybe "" (M.lookup "body" rendered)
70+
5871-- | A pure renderChain function.
5972pureRenderChainWith :: ContextManipulation
6073 -> [String]