mustache-2.2.3: A mustache template parser library.

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

Text.Mustache.Types

Contents

Description

 

Synopsis

Types for the Parser / Template

type ASTree α = [Node α] #

type STree = ASTree Text #

Syntax tree for a mustache template

data Node α #

Basic values composing the STree

Instances

Eq α => Eq (Node α) # 

Methods

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

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

Show α => Show (Node α) # 

Methods

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

show :: Node α -> String #

showList :: [Node α] -> ShowS #

Lift α0 => Lift (Node α0) # 

Methods

lift :: Node α0 -> Q Exp #

ToMustache (STree -> SubM STree) # 

data DataIdentifier #

Kinds of identifiers for Variables and sections

Constructors

NamedData [Key] 
Implicit 

data Template #

A compiled Template with metadata.

Constructors

Template 

type TemplateCache = HashMap String Template #

A collection of templates with quick access via their hashed names

Types for the Substitution / Data

type Key = Text #

Type of key used for retrieving data from Values

Converting

object :: [Pair] -> Value #

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 infixr 8 #

Map keys to values that provide a ToMustache instance

Recommended in conjunction with the OverloadedStrings extension.

(↝) :: ToMustache ω => Text -> ω -> Pair infixr 8 #

Unicode version of ~>

(~=) :: ToJSON ι => Text -> ι -> Pair infixr 8 #

Map keys to values that provide a ToJSON instance

Recommended in conjunction with the OverloadedStrings extension.

(⥱) :: ToJSON ι => Text -> ι -> Pair infixr 8 #

Unicode version of ~=

class ToMustache ω where #

Conversion class

Minimal complete definition

toMustache

Methods

toMustache :: ω -> Value #

Instances

ToMustache Bool # 
ToMustache Char # 
ToMustache Double # 
ToMustache Float # 
ToMustache Int # 
ToMustache Integer # 
ToMustache () # 

Methods

toMustache :: () -> Value #

listToMustache :: [()] -> Value

ToMustache Scientific # 
ToMustache Text # 
ToMustache Value # 
ToMustache Text # 
ToMustache Value # 
ToMustache α => ToMustache [α] # 

Methods

toMustache :: [α] -> Value #

listToMustache :: [[α]] -> Value

ToMustache ω => ToMustache (Maybe ω) # 

Methods

toMustache :: Maybe ω -> Value #

listToMustache :: [Maybe ω] -> Value

ToMustache ω => ToMustache (Seq ω) # 

Methods

toMustache :: Seq ω -> Value #

listToMustache :: [Seq ω] -> Value

ToMustache ω => ToMustache (Set ω) # 

Methods

toMustache :: Set ω -> Value #

listToMustache :: [Set ω] -> Value

ToMustache ω => ToMustache (HashSet ω) # 
ToMustache ω => ToMustache (Vector ω) # 

Methods

toMustache :: Vector ω -> Value #

listToMustache :: [Vector ω] -> Value

ToMustache (STree -> SubM STree) # 
(ToMustache α, ToMustache β) => ToMustache (α, β) # 

Methods

toMustache :: (α, β) -> Value #

listToMustache :: [(α, β)] -> Value

ToMustache ω => ToMustache (HashMap String ω) # 
ToMustache ω => ToMustache (HashMap Text ω) # 
ToMustache ω => ToMustache (HashMap Text ω) # 
ToMustache ω => ToMustache (Map String ω) # 
ToMustache ω => ToMustache (Map Text ω) # 

Methods

toMustache :: Map Text ω -> Value #

listToMustache :: [Map Text ω] -> Value

ToMustache ω => ToMustache (Map Text ω) # 

Methods

toMustache :: Map Text ω -> Value #

listToMustache :: [Map Text ω] -> Value

(ToMustache α, ToMustache β, ToMustache γ) => ToMustache (α, β, γ) # 

Methods

toMustache :: (α, β, γ) -> Value #

listToMustache :: [(α, β, γ)] -> Value

(ToMustache α, ToMustache β, ToMustache γ, ToMustache δ) => ToMustache (α, β, γ, δ) # 

Methods

toMustache :: (α, β, γ, δ) -> Value #

listToMustache :: [(α, β, γ, δ)] -> Value

(ToMustache α, ToMustache β, ToMustache γ, ToMustache δ, ToMustache ε) => ToMustache (α, β, γ, δ, ε) # 

Methods

toMustache :: (α, β, γ, δ, ε) -> Value #

listToMustache :: [(α, β, γ, δ, ε)] -> Value

(ToMustache α, ToMustache β, ToMustache γ, ToMustache δ, ToMustache ε, ToMustache ζ) => ToMustache (α, β, γ, δ, ε, ζ) # 

Methods

toMustache :: (α, β, γ, δ, ε, ζ) -> Value #

listToMustache :: [(α, β, γ, δ, ε, ζ)] -> Value

(ToMustache α, ToMustache β, ToMustache γ, ToMustache δ, ToMustache ε, ToMustache ζ, ToMustache η) => ToMustache (α, β, γ, δ, ε, ζ, η) # 

Methods

toMustache :: (α, β, γ, δ, ε, ζ, η) -> Value #

listToMustache :: [(α, β, γ, δ, ε, ζ, η)] -> Value

(ToMustache α, ToMustache β, ToMustache γ, ToMustache δ, ToMustache ε, ToMustache ζ, ToMustache η, ToMustache θ) => ToMustache (α, β, γ, δ, ε, ζ, η, θ) # 

Methods

toMustache :: (α, β, γ, δ, ε, ζ, η, θ) -> Value #

listToMustache :: [(α, β, γ, δ, ε, ζ, η, θ)] -> Value

toMustache :: ToMustache ω => ω -> Value #

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

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

Representation

type Array = Vector Value #

A list-like structure used in Value

type Object = HashMap Text Value #

A map-like structure used in Value

type Pair = (Text, Value) #

Source type for constructing Objects

data SubM a #

Instances

Monad SubM # 

Methods

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

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

return :: a -> SubM a #

fail :: String -> SubM a #

Functor SubM # 

Methods

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

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

Applicative SubM # 

Methods

pure :: a -> SubM a #

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

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

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

ToMustache (STree -> SubM STree) # 
MonadReader (Context Value, TemplateCache) SubM # 

data Context α #

Representation of stateful context for the substitution process

Constructors

Context 

Fields

Instances

Eq α => Eq (Context α) # 

Methods

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

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

Ord α => Ord (Context α) # 

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 α #

Show α => Show (Context α) # 

Methods

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

show :: Context α -> String #

showList :: [Context α] -> ShowS #

MonadReader (Context Value, TemplateCache) SubM #