mustache-2.4.2: A mustache template parser library.
Copyright(c) Justus Adam 2015
LicenseBSD3
Maintainerdev@justus.science
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe-Inferred
LanguageHaskell2010

Text.Mustache.Render

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)

Instances

Instances details
Show SubstitutionError Source # 
Instance details

Defined in Text.Mustache.Internal.Types

Working with Context

data Context α Source #

Representation of stateful context for the substitution process

Constructors

Context 

Fields

Instances

Instances details
Show α => Show (Context α) Source # 
Instance details

Defined in Text.Mustache.Internal.Types

Methods

showsPrec :: Int -> Context α -> ShowS #

show :: Context α -> String #

showList :: [Context α] -> ShowS #

Eq α => Eq (Context α) Source # 
Instance details

Defined in Text.Mustache.Internal.Types

Methods

(==) :: Context α -> Context α -> Bool #

(/=) :: Context α -> Context α -> Bool #

Ord α => Ord (Context α) Source # 
Instance details

Defined in Text.Mustache.Internal.Types

Methods

compare :: Context α -> Context α -> Ordering #

(<) :: Context α -> Context α -> Bool #

(<=) :: Context α -> Context α -> Bool #

(>) :: Context α -> Context α -> Bool #

(>=) :: Context α -> Context α -> Bool #

max :: Context α -> Context α -> Context α #

min :: Context α -> Context α -> Context α #

ToMustache (Context Value -> STree -> STree) Source # 
Instance details

Defined in Text.Mustache.Render

ToMustache (Context Value -> STree -> Text) Source # 
Instance details

Defined in Text.Mustache.Render

ToMustache (Context Value -> STree -> Text) Source # 
Instance details

Defined in Text.Mustache.Render

ToMustache (Context Value -> STree -> String) Source # 
Instance details

Defined in Text.Mustache.Render

MonadReader (Context Value, TemplateCache) SubM Source # 
Instance details

Defined in Text.Mustache.Internal.Types

search :: [Key] -> SubM (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.

data SubM a Source #

Instances

Instances details
Applicative SubM Source # 
Instance details

Defined in Text.Mustache.Internal.Types

Methods

pure :: a -> SubM a #

(<*>) :: SubM (a -> b) -> SubM a -> SubM b #

liftA2 :: (a -> b -> c) -> SubM a -> SubM b -> SubM c #

(*>) :: SubM a -> SubM b -> SubM b #

(<*) :: SubM a -> SubM b -> SubM a #

Functor SubM Source # 
Instance details

Defined in Text.Mustache.Internal.Types

Methods

fmap :: (a -> b) -> SubM a -> SubM b #

(<$) :: a -> SubM b -> SubM a #

Monad SubM Source # 
Instance details

Defined in Text.Mustache.Internal.Types

Methods

(>>=) :: SubM a -> (a -> SubM b) -> SubM b #

(>>) :: SubM a -> SubM b -> SubM b #

return :: a -> SubM a #

ToMustache (STree -> SubM STree) Source # 
Instance details

Defined in Text.Mustache.Internal.Types

ToMustache (STree -> SubM Text) Source # 
Instance details

Defined in Text.Mustache.Render

MonadReader (Context Value, TemplateCache) SubM Source # 
Instance details

Defined in Text.Mustache.Internal.Types

substituteNode :: Node Text -> SubM () Source #

Main substitution function

substituteAST :: STree -> SubM () Source #

Substitute an entire STree rather than just a single Node

catchSubstitute :: SubM a -> SubM (a, Text) Source #

Catch the results of running the inner substitution.

Util

toString :: Value -> SubM Text Source #

Converts values to Text as required by the mustache standard

Orphan instances