inserts-0.1.0.1: Stupid simple bytestring templates.

Portabilityunknown
Stabilityexperimental
Maintainerme@jspha.com
Safe HaskellNone

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

Synopsis

Documentation

data Template Source

Instances

Show Template 
IsString Template

Template literals can be embedded directly in Haskell files.

Monoid Template

O(1) appends

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.

templateParser :: Parser TemplateSource

An attoparsec Parser for Templates. This is useful if you'd like to embed Templates into a more sophisticated, parseable type of your own.