on master help sign in
Merge pull request #328 from wferi/boolField

Add boolField

commitb296f623352b354d76a891a03ef9a2e94e57a7c8 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateTue 13 Jan 2015, 18:28 (12 years ago) parent9307ec526b2ee3
1 file changed+13−1
src/Hakyll/Web/Template/Context.hs+13−1
src/Hakyll/Web/Template/Context.hs+13−1
@@ -4,6 +4,7 @@ module Hakyll.Web.Template.Context
44 ( ContextField (..)
55 , Context (..)
66 , field
7+ , boolField
78 , constField
89 , listField
910 , listFieldWith
@@ -27,7 +28,7 @@ module Hakyll.Web.Template.Context
2728
2829
2930--------------------------------------------------------------------------------
30−import Control.Applicative (Alternative (..), (<$>))
31+import Control.Applicative (Alternative (..), (<$>), pure)
3132import Control.Monad (msum)
3233import Data.List (intercalate)
3334import qualified Data.Map as M
@@ -97,6 +98,17 @@ field
9798field key value = field' key (fmap StringField . value)
9899
99100
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+
100112--------------------------------------------------------------------------------
101113-- | Creates a 'field' that does not depend on the 'Item'
102114constField :: String -> String -> Context a