Add functionField again
This commit is contained in:
parent
ab0aebb3c3
commit
fad9134fd4
6 changed files with 17 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
Name: hakyll
|
||||
Version: 4.3.2.0
|
||||
Version: 4.3.3.0
|
||||
|
||||
Synopsis: A static website compiler library
|
||||
Description:
|
||||
|
|
|
@ -6,6 +6,7 @@ module Hakyll.Web.Template.Context
|
|||
, field
|
||||
, constField
|
||||
, listField
|
||||
, functionField
|
||||
, mapContext
|
||||
|
||||
, defaultContext
|
||||
|
@ -86,6 +87,15 @@ listField :: String -> Context a -> Compiler [Item a] -> Context b
|
|||
listField key c xs = field' key $ \_ -> fmap (ListField c) xs
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
functionField :: String -> ([String] -> Item a -> Compiler String) -> Context a
|
||||
functionField name value = Context $ \k i -> case words k of
|
||||
[] -> empty
|
||||
(n : args)
|
||||
| n == name -> StringField <$> value args i
|
||||
| otherwise -> empty
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
mapContext :: (String -> String) -> Context a -> Context a
|
||||
mapContext f (Context c) = Context $ \k i -> do
|
||||
|
|
|
@ -58,6 +58,7 @@ testContext = mconcat
|
|||
n1 <- makeItem "Jan"
|
||||
n2 <- makeItem "Piet"
|
||||
return [n1, n2]
|
||||
, functionField "rev" $ \args _ -> return $ unwords $ map reverse args
|
||||
]
|
||||
where
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<div>
|
||||
I'm so rich I have $$3.
|
||||
|
||||
$rev foo$
|
||||
|
||||
$if(body)$
|
||||
I have body
|
||||
$else$
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<div>
|
||||
I'm so rich I have $3.
|
||||
|
||||
oof
|
||||
|
||||
|
||||
I have body
|
||||
|
||||
|
|
Loading…
Reference in a new issue