Skip to content

Commit

Permalink
Add boolFieldM for monadic bool fields creation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xd34df00d committed Sep 19, 2024
1 parent c28f600 commit 31160aa
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/Hakyll/Web/Template/Context.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Hakyll.Web.Template.Context
, Context (..)
, field
, boolField
, boolFieldM
, constField
, listField
, listFieldWith
Expand Down Expand Up @@ -147,7 +148,17 @@ boolField
:: String
-> (Item a -> Bool)
-> Context a
boolField name f = field' name (\i -> if f i
boolField name f = boolFieldM name (pure . f)

-- | Creates a 'field' to use with the @$if()$@ template macro, in the 'Compiler' monad.
-- Attempting to substitute the field into the template will cause an error.
boolFieldM
:: String
-> (Item a -> Compiler Bool)
-> Context a
boolFieldM name f = field' name (\i -> do
b <- f i
if b
then return EmptyField
else noResult $ "Field " ++ name ++ " is false")

Expand Down

0 comments on commit 31160aa

Please sign in to comment.