Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add boolFieldM for Compiler-dependent bool fields #1044

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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