tinytemplate-0.1.2.0: A tiny text templating library

Copyright(c) DICOM Grid Inc. 2015
LicenseMIT
Maintainerpaf31@cantab.net
Stabilityexperimental
Safe HaskellSafe
LanguageHaskell98

Data.Text.Template

Contents

Description

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"

Synopsis

Types

Functions

Creating Templates

lit :: Text -> Template #

Create a Template from a literal string

placeholder :: Text -> Template #

Create a Template from a placeholder which will be replaced during rendering

parseTemplate :: Text -> Template #

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 #

Traverse a Template, replacing placeholders using the specified function.

printTemplate :: Template -> Text #

Render a Template as a template string.