summaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-15 15:41:42 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-15 15:41:42 +0100
commit129ab7f31af87962f73d534b045e57cb1975690b (patch)
tree63f6f0b3d157d28c4e67311c0df797aaf6a49b4a /src/Text
parent62330ceae51ea28f75768196ad5e3f93eb88b8a3 (diff)
downloadhakyll-129ab7f31af87962f73d534b045e57cb1975690b.tar.gz
Minor code cleanup.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Hakyll.hs3
-rw-r--r--src/Text/Hakyll/Hakyll.hs17
-rw-r--r--src/Text/Hakyll/Render/Internal.hs9
3 files changed, 18 insertions, 11 deletions
diff --git a/src/Text/Hakyll.hs b/src/Text/Hakyll.hs
index 2586c02..ae31fc3 100644
--- a/src/Text/Hakyll.hs
+++ b/src/Text/Hakyll.hs
@@ -15,8 +15,7 @@ import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
-- | Default hakyll configuration.
defaultHakyllConfiguration :: HakyllConfiguration
defaultHakyllConfiguration = HakyllConfiguration
- { hakyllDestination = "_site"
- , hakyllGlobalContext = M.empty
+ { additionalContext = M.empty
}
-- | Main function to run hakyll.
diff --git a/src/Text/Hakyll/Hakyll.hs b/src/Text/Hakyll/Hakyll.hs
index 3690914..c7f6d89 100644
--- a/src/Text/Hakyll/Hakyll.hs
+++ b/src/Text/Hakyll/Hakyll.hs
@@ -1,15 +1,24 @@
+-- | Module describing the Hakyll monad stack.
module Text.Hakyll.Hakyll
( HakyllConfiguration (..)
, Hakyll
+ , askHakyll
) where
import Text.Hakyll.Context (Context)
-import System.FilePath (FilePath)
-import Control.Monad.Reader (ReaderT)
+import Control.Monad.Reader (ReaderT, ask)
+import Control.Monad (liftM)
+-- | Hakyll global configuration type.
data HakyllConfiguration = HakyllConfiguration
- { hakyllDestination :: FilePath
- , hakyllGlobalContext :: Context
+ { -- | An additional context to use when rendering. This additional context
+ -- is used globally.
+ additionalContext :: Context
}
+-- | Our custom monad stack.
type Hakyll = ReaderT HakyllConfiguration IO
+
+-- | Simplified "ask" function for the Hakyll monad stack.
+askHakyll :: (HakyllConfiguration -> a) -> Hakyll a
+askHakyll = flip liftM ask
diff --git a/src/Text/Hakyll/Render/Internal.hs b/src/Text/Hakyll/Render/Internal.hs
index e296dd2..7e5fd37 100644
--- a/src/Text/Hakyll/Render/Internal.hs
+++ b/src/Text/Hakyll/Render/Internal.hs
@@ -11,8 +11,7 @@ module Text.Hakyll.Render.Internal
import qualified Data.Map as M
import Text.Hakyll.Context (Context, ContextManipulation)
-import Control.Monad.Reader (ask, liftIO)
-import Control.Monad (liftM)
+import Control.Monad.Reader (liftIO)
import Data.List (isPrefixOf, foldl')
import Data.Char (isAlpha)
import Data.Maybe (fromMaybe)
@@ -20,7 +19,7 @@ import Control.Parallel.Strategies (rdeepseq, ($|))
import Text.Hakyll.Renderable
import Text.Hakyll.Page
import Text.Hakyll.File
-import Text.Hakyll.Hakyll (Hakyll, hakyllGlobalContext)
+import Text.Hakyll.Hakyll
-- | Substitutes `$identifiers` in the given string by values from the given
-- "Context". When a key is not found, it is left as it is. You can here
@@ -84,9 +83,9 @@ pureRenderChainWith manipulation templates context =
-- chains and such.
writePage :: Page -> Hakyll ()
writePage page = do
- globalContext <- liftM hakyllGlobalContext ask
+ additionalContext' <- askHakyll additionalContext
let destination = toDestination url
- context = (M.singleton "root" $ toRoot url) `M.union` globalContext
+ context = additionalContext' `M.union` (M.singleton "root" $ toRoot url)
makeDirectories destination
    -- Substitute $root here, just before writing.
liftIO $ writeFile destination $ finalSubstitute (getBody page) context