mustache-0.3.0.0: A mustache template parser library.

Copyright(c) Justus Adam, 2015
LicenseLGPL-3
Maintainerdev@justus.science
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Text.Mustache.Types

Contents

Description

 

Synopsis

Types for the Parser / Template

type AST = [Node Text] Source

Abstract syntax tree for a mustache template

data Template Source

A compiled Template with metadata.

Constructors

Template 

Instances

data DataIdentifier Source

Kinds of identifiers for Variables and sections

Constructors

NamedData [Key] 
Implicit 

Types for the Substitution / Data

type Key = Text Source

Type of key used for retrieving data from Values

Converting

object :: [Pair] -> Value Source

Convenience function for creating Object values.

This function is supposed to be used in conjuction with the ~> and ~= operators.

Examples

  data Address = Address { ... }

  instance Address ToJSON where
    ...

  data Person = Person { name :: String, address :: Address }

  instance ToMustache Person where
    toMustache (Person { name, address }) = object
      [ "name" ~> name
      , "address" ~= address
      ]

Here we can see that we can use the ~> operator for values that have themselves a ToMustache instance, or alternatively if they lack such an instance but provide an instance for the ToJSON typeclass we can use the ~= operator.

(~>) :: ToMustache ω => Text -> ω -> Pair Source

Map keys to values that provide a ToMustache instance

Recommended in conjunction with the OverloadedStrings extension.

(↝) :: ToMustache ω => Text -> ω -> Pair Source

Unicode version of ~>

(~=) :: ToJSON ι => Text -> ι -> Pair Source

Map keys to values that provide a ToJSON instance

Recommended in conjunction with the OverloadedStrings extension.

(⥱) :: ToJSON ι => Text -> ι -> Pair Source

Unicode version of ~=

(~~>) :: (Conversion ζ Text, ToMustache ω) => ζ -> ω -> Pair Source

Conceptually similar to ~> but uses arbitrary String-likes as keys.

(~↝) :: (Conversion ζ Text, ToMustache ω) => ζ -> ω -> Pair Source

Unicde version of ~~>

(~~=) :: (Conversion ζ Text, ToJSON ι) => ζ -> ι -> Pair Source

Conceptually similar to ~= but uses arbitrary String-likes as keys.

(~⥱) :: (Conversion ζ Text, ToJSON ι) => ζ -> ι -> Pair Source

Unicode version of ~~=

class ToMustache ω where Source

Conversion class

Note that some instances of this class overlap delierately to provide maximum flexibility instances while preserving maximum efficiency.

Methods

toMustache :: ω -> Value Source

toTextBlock :: Conversion ζ Text => ζ -> Value Source

Converts arbitrary String-likes to Values

mFromJSON :: ToJSON ι => ι -> Value Source

Converts a value that can be represented as JSON to a Value.

Representation

type Array = Vector Value Source

A list-like structure used in Value

type Object = HashMap Text Value Source

A map-like structure used in Value

type Pair = (Text, Value) Source

Source type for constructing Objects

data Context α Source

Representation of stateful context for the substitution process

Constructors

Context [α] α 

Instances

type TemplateCache = HashMap String Template Source

A collection of templates with quick access via their hashed names