tinytemplate-0.1.2.0: A tiny text templating library

Copyright(c) DICOM Grid Inc. 2015
LicenseMIT
Maintainerpaf31@cantab.net
Stabilityexperimental
Safe HaskellSafe-Inferred
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

data Template Source

A text template

Functions

Creating Templates

lit :: Text -> Template Source

Create a Template from a literal string

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.