on master help sign in
Context module?
6b11cbaJasper Van der Jeugt
hakyll.cabal+1
@@ -124,6 +124,7 @@ Library
124 Hakyll.Web.Pandoc.FileType
124 Hakyll.Web.Pandoc.FileType
125 Hakyll.Web.Tags
125 Hakyll.Web.Tags
126 Hakyll.Web.Template
126 Hakyll.Web.Template
127+ Hakyll.Web.Template.Context
127 Hakyll.Web.Template.Read
128 Hakyll.Web.Template.Read
128 Hakyll.Web.Urls
129 Hakyll.Web.Urls
129 Hakyll.Web.Urls.Relativize
130 Hakyll.Web.Urls.Relativize
src/Hakyll/Core/Compiler/Internal.hs+4−2
@@ -19,8 +19,7 @@ module Hakyll.Core.Compiler.Internal
19--------------------------------------------------------------------------------
19--------------------------------------------------------------------------------
20import Control.Applicative (Alternative (..), Applicative,
20import Control.Applicative (Alternative (..), Applicative,
21 pure, (<$>), (<*>))
21 pure, (<$>), (<*>))
22−import Control.Arrow (Arrow, ArrowChoice, arr, first,
22+import Control.Arrow
23− left)
24import Control.Category (Category, id, (.))
23import Control.Category (Category, id, (.))
25import Control.Monad (liftM2, (<=<))
24import Control.Monad (liftM2, (<=<))
26import Control.Monad.Error (ErrorT, catchError, runErrorT,
25import Control.Monad.Error (ErrorT, catchError, runErrorT,
@@ -137,6 +136,9 @@ instance ArrowChoice Compiler where
137 left ~(Compiler d j) = Compiler d $ \e -> case e of
136 left ~(Compiler d j) = Compiler d $ \e -> case e of
138 Left l -> Left <$> j l
137 Left l -> Left <$> j l
139 Right r -> Right <$> return r
138 Right r -> Right <$> return r
139+ -- Defined here for efficiency
140+ ~(Compiler d1 j1) ||| ~(Compiler d2 j2) = Compiler (liftM2 S.union d1 d2) $
141+ \e -> case e of Left x -> j1 x; Right y -> j2 y
140
142
141
143
142--------------------------------------------------------------------------------
144--------------------------------------------------------------------------------
src/Hakyll/Web/Template/Context.hsnew file+24
@@ -0,0 +1,24 @@
1+--------------------------------------------------------------------------------
2+module Hakyll.Web.Template.Context
3+ ( Context
4+ , field
5+ ) where
6+
7+
8+--------------------------------------------------------------------------------
9+import Control.Applicative (empty)
10+import Control.Arrow
11+import Hakyll.Core.Compiler
12+
13+
14+--------------------------------------------------------------------------------
15+type Context a = Compiler (String, a) String
16+
17+
18+--------------------------------------------------------------------------------
19+field :: String -> Compiler a String -> Context a
20+field key value = arr checkKey >>> empty ||| value
21+ where
22+ checkKey (k, x)
23+ | k == key = Left ()
24+ | otherwise = Right x