Copyright | (c) DICOM Grid Inc. 2015 |
---|---|
License | MIT |
Maintainer | paf31@cantab.net |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell98 |
Templates can be created in code using the lit
and placeholder
functions with the
Monoid
instance, or by parsing a template string:
import Data.Monoid ((<>)) t1 = placeholder "lastName" <> lit ", " <> placeholder "firstName" t2 = parseTemplate "{{lastName}}, {{firstName}}"
Templates can be applied using the applyTemplate
function:
>>>
:set -XOverloadedStrings
>>>
let vals = [("firstName", "Haskell"), ("lastName", "Curry")]
>>>
applyTemplate (`lookup` vals) t1
Just "Curry, Haskell"
- data Template
- lit :: Text -> Template
- placeholder :: Text -> Template
- parseTemplate :: Text -> Template
- applyTemplate :: forall f. Applicative f => (Text -> f Text) -> Template -> f Text
- printTemplate :: Template -> Text
Types
Functions
Creating Templates
placeholder :: Text -> Template Source
Create a Template
from a placeholder which will be replaced during rendering
parseTemplate :: Text -> Template Source
Parse a Template
from a template string.
Placeholders are represented using double-curly-braces ({{ ... }}
) and everything else is considered
literal text.
Applying Templates
applyTemplate :: forall f. Applicative f => (Text -> f Text) -> Template -> f Text Source
Traverse a Template
, replacing placeholders using the specified function.
printTemplate :: Template -> Text Source
Render a Template
as a template string.