summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll/Render.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-14 20:46:08 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-14 20:46:08 +0100
commit4bc34b8a98ffa1e7f3478a596b73c4ab12d9cb1b (patch)
tree86ff0e311ec49f794b28f973c95620918ab4f9ee /src/Text/Hakyll/Render.hs
parent332f2f95cdb9c72e01a55eaf46c0b08bcf37d7e9 (diff)
downloadhakyll-4bc34b8a98ffa1e7f3478a596b73c4ab12d9cb1b.tar.gz
Added ReaderT to our stack.
Diffstat (limited to 'src/Text/Hakyll/Render.hs')
-rw-r--r--src/Text/Hakyll/Render.hs44
1 files changed, 24 insertions, 20 deletions
diff --git a/src/Text/Hakyll/Render.hs b/src/Text/Hakyll/Render.hs
index d8deea2..4b22836 100644
--- a/src/Text/Hakyll/Render.hs
+++ b/src/Text/Hakyll/Render.hs
@@ -11,10 +11,12 @@ module Text.Hakyll.Render
) where
import Control.Monad (unless, mapM)
+import Control.Monad.Reader (liftIO)
import System.Directory (copyFile)
import System.IO
+import Text.Hakyll.Hakyll (Hakyll)
import Text.Hakyll.Context (ContextManipulation)
import Text.Hakyll.Page
import Text.Hakyll.Renderable
@@ -26,17 +28,17 @@ import Text.Hakyll.Render.Internal
-- | Execute an IO action only when the cache is invalid.
depends :: FilePath -- ^ File to be rendered or created.
-> [FilePath] -- ^ Files the render depends on.
- -> IO () -- ^ IO action to execute when the file is out of date.
- -> IO ()
+ -> Hakyll () -- ^ IO action to execute when the file is out of date.
+ -> Hakyll ()
depends file dependencies action = do
- valid <- isCacheValid (toDestination file) dependencies
+ valid <- liftIO $ isCacheValid (toDestination file) dependencies
unless valid action
-- | Render to a Page.
render :: Renderable a
=> FilePath -- ^ Template to use for rendering.
-> a -- ^ Renderable object to render with given template.
- -> IO Page -- ^ The body of the result will contain the render.
+ -> Hakyll Page -- ^ The body of the result will contain the render.
render = renderWith id
-- | Render to a Page. This function allows you to manipulate the context
@@ -45,15 +47,15 @@ renderWith :: Renderable a
=> ContextManipulation -- ^ Manipulation to apply on the context.
-> FilePath -- ^ Template to use for rendering.
-> a -- ^ Renderable object to render with given template.
- -> IO Page -- ^ The body of the result will contain the render.
+ -> Hakyll Page -- ^ The body of the result will contain the render.
renderWith manipulation templatePath renderable = do
- template <- readFile templatePath
+ template <- liftIO $ readFile templatePath
context <- toContext renderable
return $ fromContext $ pureRenderWith manipulation template context
-- | Render each renderable with the given template, then concatenate the
-- result.
-renderAndConcat :: Renderable a => FilePath -> [a] -> IO String
+renderAndConcat :: Renderable a => FilePath -> [a] -> Hakyll String
renderAndConcat = renderAndConcatWith id
-- | Render each renderable with the given template, then concatenate the
@@ -63,41 +65,43 @@ renderAndConcatWith :: Renderable a
=> ContextManipulation
-> FilePath
-> [a]
- -> IO String
+ -> Hakyll String
renderAndConcatWith manipulation templatePath renderables = do
- template <- readFile templatePath
+ template <- liftIO $ readFile templatePath
contexts <- mapM toContext renderables
return $ pureRenderAndConcatWith manipulation template contexts
-- | Chain a render action for a page with a number of templates. This will
-- also write the result to the site destination. This is the preferred way
-- to do general rendering.
-renderChain :: Renderable a => [FilePath] -> a -> IO ()
+renderChain :: Renderable a => [FilePath] -> a -> Hakyll ()
renderChain = renderChainWith id
-- | A more custom render chain that allows you to specify a
-- "ContextManipulation" which to apply on the context when it is read first.
renderChainWith :: Renderable a
- => ContextManipulation -> [FilePath] -> a -> IO ()
+ => ContextManipulation -> [FilePath] -> a -> Hakyll ()
renderChainWith manipulation templatePaths renderable =
- depends (getURL renderable) (getDependencies renderable ++ templatePaths) $
- do templates <- mapM readFile templatePaths
- context <- toContext renderable
- let result = pureRenderChainWith manipulation templates context
- writePage $ fromContext result
+ depends (getURL renderable) dependencies render'
+ where
+ dependencies = (getDependencies renderable) ++ templatePaths
+ render' = do templates <- liftIO $ mapM readFile templatePaths
+ context <- toContext renderable
+ let result = pureRenderChainWith manipulation templates context
+ writePage $ fromContext result
-- | Mark a certain file as static, so it will just be copied when the site is
-- generated.
-static :: FilePath -> IO ()
-static source = depends destination [source] action
+static :: FilePath -> Hakyll ()
+static source = depends destination [source] (liftIO action)
where
destination = toDestination source
action = do makeDirectories destination
copyFile source destination
-- | Render a css file, compressing it.
-css :: FilePath -> IO ()
-css source = depends destination [source] css'
+css :: FilePath -> Hakyll ()
+css source = depends destination [source] (liftIO css')
where
destination = toDestination source
css' = do contents <- readFile source