mustache-2.1.3: A mustache template parser library.

Copyright(c) Justus Adam 2015
LicenseBSD3
Maintainerdev@justus.science
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Text.Mustache.Render

Contents

Description

 

Synopsis

Substitution

substitute :: ToMustache k => Template -> k -> Text Source #

Substitutes all mustache defined tokens (or tags) for values found in the provided data structure.

Equivalent to substituteValue . toMustache.

substituteValue :: Template -> Value -> Text Source #

Substitutes all mustache defined tokens (or tags) for values found in the provided data structure.

Checked substitution

checkedSubstitute :: ToMustache k => Template -> k -> ([SubstitutionError], Text) Source #

Substitutes all mustache defined tokens (or tags) for values found in the provided data structure and report any errors and warnings encountered during substitution.

This function always produces results, as in a fully substituted/rendered template, it never halts on errors. It simply reports them in the first part of the tuple. Sites with errors are usually substituted with empty string.

The second value in the tuple is a template rendered with errors ignored. Therefore if you must enforce that there were no errors during substitution you must check that the error list in the first tuple value is empty.

Equivalent to checkedSubstituteValue . toMustache.

checkedSubstituteValue :: Template -> Value -> ([SubstitutionError], Text) Source #

Substitutes all mustache defined tokens (or tags) for values found in the provided data structure and report any errors and warnings encountered during substitution.

This function always produces results, as in a fully substituted/rendered template, it never halts on errors. It simply reports them in the first part of the tuple. Sites with errors are usually substituted with empty string.

The second value in the tuple is a template rendered with errors ignored. Therefore if you must enforce that there were no errors during substitution you must check that the error list in the first tuple value is empty.

data SubstitutionError Source #

Type of errors we may encounter during substitution.

Constructors

VariableNotFound [Key]

The template contained a variable for which there was no data counterpart in the current context

InvalidImplicitSectionContextType String

When substituting an implicit section the current context had an unsubstitutable type

InvertedImplicitSection

Inverted implicit sections should never occur

SectionTargetNotFound [Key]

The template contained a section for which there was no data counterpart in the current context

PartialNotFound FilePath

The template contained a partial for which there was no data counterpart in the current context

DirectlyRenderedValue Value

A complex value such as an Object or Array was directly rendered into the template (warning)

Working with Context

data Context α Source #

Representation of stateful context for the substitution process

Constructors

Context [α] α 

Instances

search :: Context Value -> [Key] -> Maybe Value Source #

Search for a key in the current context.

The search is conducted inside out mening the current focus is searched first. If the key is not found the outer scopes are recursively searched until the key is found, then innerSearch is called on the result.

innerSearch :: [Key] -> Value -> Maybe Value Source #

Searches nested scopes navigating inward. Fails if it encunters something other than an object before the key is expended.

Util

toString :: Value -> Substitution Text Source #

Converts values to Text as required by the mustache standard