Copyright | (c) Justus Adam 2015 |
---|---|
License | BSD3 |
Maintainer | dev@justus.science |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- substitute :: ToMustache k => Template -> k -> Text
- substituteValue :: Template -> Value -> Text
- checkedSubstitute :: ToMustache k => Template -> k -> ([SubstitutionError], Text)
- checkedSubstituteValue :: Template -> Value -> ([SubstitutionError], Text)
- data SubstitutionError
- data Context α = Context {
- ctxtParents :: [α]
- ctxtFocus :: α
- search :: [Key] -> SubM (Maybe Value)
- innerSearch :: [Key] -> Value -> Maybe Value
- data SubM a
- substituteNode :: Node Text -> SubM ()
- substituteAST :: STree -> SubM ()
- catchSubstitute :: SubM a -> SubM (a, Text)
- toString :: Value -> SubM Text
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.
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
Show SubstitutionError Source # | |
Defined in Text.Mustache.Internal.Types showsPrec :: Int -> SubstitutionError -> ShowS # show :: SubstitutionError -> String # showList :: [SubstitutionError] -> ShowS # |
Working with Context
Representation of stateful context for the substitution process
Context | |
|
Instances
Eq α => Eq (Context α) Source # | |
Ord α => Ord (Context α) Source # | |
Defined in Text.Mustache.Internal.Types | |
Show α => Show (Context α) Source # | |
ToMustache (Context Value -> STree -> Text) Source # | |
Defined in Text.Mustache.Render | |
ToMustache (Context Value -> STree -> Text) Source # | |
Defined in Text.Mustache.Render | |
ToMustache (Context Value -> STree -> String) Source # | |
Defined in Text.Mustache.Render | |
ToMustache (Context Value -> STree -> STree) Source # | |
Defined in Text.Mustache.Render | |
MonadReader (Context Value, TemplateCache) SubM Source # | |
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.
Instances
Monad SubM Source # | |
Functor SubM Source # | |
Applicative SubM Source # | |
ToMustache (STree -> SubM Text) Source # | |
Defined in Text.Mustache.Render | |
ToMustache (STree -> SubM STree) Source # | |
Defined in Text.Mustache.Internal.Types | |
MonadReader (Context Value, TemplateCache) SubM Source # | |
Defined in Text.Mustache.Internal.Types |
catchSubstitute :: SubM a -> SubM (a, Text) Source #
Catch the results of running the inner substitution.