From 26b2ee3b94f0b05b3c0c1624ce3ea05bc4ce70a2 Mon Sep 17 00:00:00 2001 From: Ferenc Wágner Date: Tue, 13 Jan 2015 09:20:45 +0100 Subject: Add boolField --- src/Hakyll/Web/Template/Context.hs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src') 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 @@ -97,6 +98,17 @@ field 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 -- cgit v1.2.3