@@ -9,6 +9,7 @@ module Text.Hakyll.Render
11import Control.Arrow ((>>>))
11import Control.Arrow ((>>>))
12+import Control.Applicative ((<$>))
12import Control.Monad.Reader (liftIO)
13import Control.Monad.Reader (liftIO)
13import System.Directory (copyFile)
14import System.Directory (copyFile)
14import Data.Maybe (fromMaybe)
15import Data.Maybe (fromMaybe)
@@ -21,10 +22,10 @@ import Text.Hakyll.HakyllAction
21import Text.Hakyll.Internal.CompressCss
22import Text.Hakyll.Internal.CompressCss
22import Text.Hakyll.Internal.Template
23import Text.Hakyll.Internal.Template
24−-- | A pure render function.
25+-- | A pure render function - used internally.
25pureRender :: Template -- ^ Template to use for rendering.
26pureRender :: Template -- ^ Template to use for rendering.
26− -> Context -- ^ Renderable object to render with given template.
27+ -> Context -- ^ Renderable object to render with given template.
27− -> Context -- ^ The body of the result will contain the render.
28+ -> Context -- ^ The body of the result will contain the render.
28pureRender template context =
29pureRender template context =
29 -- Ignore $root when substituting here. We will only replace that in the
30 -- Ignore $root when substituting here. We will only replace that in the
30 -- final render (just before writing).
31 -- final render (just before writing).
@@ -32,29 +33,26 @@ pureRender template context =
32 body = regularSubstitute template contextIgnoringRoot
33 body = regularSubstitute template contextIgnoringRoot
33 in M.insert "body" body context
34 in M.insert "body" body context
35−-- | Render to a Page.
36+-- | This is the most simple render action. You render a @Context@ with a
37+-- template, and get back the result.
36render :: FilePath -- ^ Template to use for rendering.
38render :: FilePath -- ^ Template to use for rendering.
37 -> HakyllAction Context Context -- ^ The render computation.
39 -> HakyllAction Context Context -- ^ The render computation.
38render templatePath = HakyllAction
40render templatePath = HakyllAction
39 { actionDependencies = [templatePath]
41 { actionDependencies = [templatePath]
40 , actionUrl = Nothing
42 , actionUrl = Nothing
41− , actionFunction = actionFunction'
43+ , actionFunction = \context ->
44+ flip pureRender context <$> readTemplate templatePath
44− actionFunction' context = do
45− template <- readTemplate templatePath
46− return $ pureRender template context
48−-- | Render each renderable with the given templates, then concatenate the
47+-- | Render each @Context@ with the given templates, then concatenate the
49-- result. So, basically this function:
48-- result. So, basically this function:
51−-- * Takes every renderable.
50+-- - Takes every @Context@.
53−-- * Renders every renderable with all given templates. This is comparable
52+-- - Renders every @Context@ with all given templates. This is comparable
54-- with a renderChain action.
53-- with a renderChain action.
56−-- * Concatenates the result.
55+-- - Concatenates the result and returns that as a @String@.
58renderAndConcat :: [FilePath]
56renderAndConcat :: [FilePath]
59 -> [HakyllAction () Context]
57 -> [HakyllAction () Context]
60 -> HakyllAction () String
58 -> HakyllAction () String
@@ -87,11 +85,8 @@ renderChain :: [FilePath]
87renderChain templatePaths initial =
85renderChain templatePaths initial =
88 runHakyllActionIfNeeded renderChainWith'
86 runHakyllActionIfNeeded renderChainWith'
90− renderChainWith' :: HakyllAction () ()
91 renderChainWith' = initial >>> chain' >>> writePage
88 renderChainWith' = initial >>> chain' >>> writePage
93− chain' = chain (map render templatePaths)
89+ chain' = chain $ map render templatePaths
96-- | Mark a certain file as static, so it will just be copied when the site is
91-- | Mark a certain file as static, so it will just be copied when the site is
97-- generated.
92-- generated.