| Portability | unknown |
|---|---|
| Stability | experimental |
| Maintainer | [email protected] |
| Safe Haskell | None |
Text.Template.Inserts
Description
Completely trivial, interpolation-only Templates; for when you want an API
that fits on a business card. Text.Template.Inserts implements a
subset of Mustache syntax. It uses template strings with named holes
deliminted by "mustaches":
import Data.HashMap.Strict as Map
import Data.ByteString as S
context :: HashMap ByteString ByteString
context = Map.fromList [ ("country", "Morocco")
, ("favoriteFruit", "bananas")
]
>>>runTemplate (flip Map.lookup context) "I live in {{country}} and love {{favoriteFruit}}."Right "I live in Morocco and love bananas"
>>>runTemplate (flip Map.lookup context) "My address is {{ address }}"Left ["address"]
Text.Template.Inserts seeks to be as unsurprising and simple as possible sacrificing all kinds of niceities. Sometimes though, all you need is obvious, trivial string interpolation
- data Template
- runTemplate :: (ByteString -> Maybe ByteString) -> Template -> Either [ByteString] ByteString
- parseTemplate :: ByteString -> Either String Template
- templateParser :: Parser Template
Documentation
runTemplate :: (ByteString -> Maybe ByteString) -> Template -> Either [ByteString] ByteStringSource
Outputs either the successfully interpolated template or the list of
missing keys. For fast operation, try building the lookup function using
unordered-containers HashMaps.
parseTemplate :: ByteString -> Either String TemplateSource
Try to parse a ByteString as a Template.