on master help sign in
Merge pull request #328 from wferi/boolField
b296f62Jasper Van der Jeugt
src/Hakyll/Web/Template/Context.hs+13−1
@@ -4,6 +4,7 @@ module Hakyll.Web.Template.Context
4 ( ContextField (..)
4 ( ContextField (..)
5 , Context (..)
5 , Context (..)
6 , field
6 , field
7+ , boolField
7 , constField
8 , constField
8 , listField
9 , listField
9 , listFieldWith
10 , listFieldWith
@@ -27,7 +28,7 @@ module Hakyll.Web.Template.Context
27
28
28
29
29--------------------------------------------------------------------------------
30--------------------------------------------------------------------------------
30−import Control.Applicative (Alternative (..), (<$>))
31+import Control.Applicative (Alternative (..), (<$>), pure)
31import Control.Monad (msum)
32import Control.Monad (msum)
32import Data.List (intercalate)
33import Data.List (intercalate)
33import qualified Data.Map as M
34import qualified Data.Map as M
@@ -97,6 +98,17 @@ field
97field key value = field' key (fmap StringField . value)
98field key value = field' key (fmap StringField . value)
98
99
99
100
101+--------------------------------------------------------------------------------
102+-- | Creates a 'field' to use with the @$if()$@ template macro.
103+boolField
104+ :: String
105+ -> (Item a -> Bool)
106+ -> Context a
107+boolField name f = field name (\i -> if f i
108+ then pure (error $ unwords ["no string value for bool field:",name])
109+ else empty)
110+
111+
100--------------------------------------------------------------------------------
112--------------------------------------------------------------------------------
101-- | Creates a 'field' that does not depend on the 'Item'
113-- | Creates a 'field' that does not depend on the 'Item'
102constField :: String -> String -> Context a
114constField :: String -> String -> Context a