diff options
author | Ferenc Wágner <wferi@niif.hu> | 2015-01-13 09:20:45 +0100 |
---|---|---|
committer | Ferenc Wágner <wferi@niif.hu> | 2015-01-13 09:33:58 +0100 |
commit | 26b2ee3b94f0b05b3c0c1624ce3ea05bc4ce70a2 (patch) | |
tree | ffa8d419fd6581849946f1487ae8af1b2d013ebf /src | |
parent | 9307ec526308f55340b95e199d6aad0850d17d04 (diff) | |
download | hakyll-26b2ee3b94f0b05b3c0c1624ce3ea05bc4ce70a2.tar.gz |
Add boolField
Diffstat (limited to 'src')
-rw-r--r-- | src/Hakyll/Web/Template/Context.hs | 14 |
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 |