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 18, 2024
1 parent c28f600 commit d1babde
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions 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 @@ -151,6 +152,18 @@ boolField name f = field' name (\i -> if f i
then return EmptyField
else noResult $ "Field " ++ name ++ " is false")

-- | 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")


--------------------------------------------------------------------------------
-- | Creates a 'field' that does not depend on the 'Item' but always yields
Expand Down

0 comments on commit d1babde

Please sign in to comment.