summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Web/Template/Context.hs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/Hakyll/Web/Template/Context.hs b/src/Hakyll/Web/Template/Context.hs
index 2da76d4..f5646b9 100644
--- a/src/Hakyll/Web/Template/Context.hs
+++ b/src/Hakyll/Web/Template/Context.hs
@@ -4,6 +4,7 @@ module Hakyll.Web.Template.Context
( ContextField (..)
, Context (..)
, field
+ , boolField
, constField
, listField
, listFieldWith
@@ -27,7 +28,7 @@ module Hakyll.Web.Template.Context
--------------------------------------------------------------------------------
-import Control.Applicative (Alternative (..), (<$>))
+import Control.Applicative (Alternative (..), (<$>), pure)
import Control.Monad (msum)
import Data.List (intercalate)
import qualified Data.Map as M
@@ -98,6 +99,17 @@ field key value = field' key (fmap StringField . value)
--------------------------------------------------------------------------------
+-- | Creates a 'field' to use with the @$if()$@ template macro.
+boolField
+ :: String
+ -> (Item a -> Bool)
+ -> Context a
+boolField name f = field name (\i -> if f i
+ then pure (error $ unwords ["no string value for bool field:",name])
+ else empty)
+
+
+--------------------------------------------------------------------------------
-- | Creates a 'field' that does not depend on the 'Item'
constField :: String -> String -> Context a
constField key = field key . const . return