mustache-2.4.2: A mustache template parser library.

Copyright | (c) Justus Adam 2015
License | BSD3
Maintainer | dev@justus.science
Stability | experimental
Portability | POSIX
Safe Haskell | Safe-Inferred
Language | Haskell2010

Text.Mustache.Types

Contents

- Types for the Parser / Template
- Types for the Substitution / Data
  - Converting
  - Representation

Description

Synopsis

- type ASTree α = [Node α]
- type STree = ASTree Text
- data Node α
  - = TextBlock α
  - | Section DataIdentifier (ASTree α)
  - | InvertedSection DataIdentifier (ASTree α)
  - | Variable Bool DataIdentifier
  - | Partial (Maybe α) FilePath
- data DataIdentifier
  - = NamedData [Key]
  - | Implicit
- data Template = Template {
  - name :: String
  - ast :: STree
  - partials :: TemplateCache
  }
- type TemplateCache = HashMap String Template
- data Value
  - = Object !Object
  - | Array !Array
  - | Number !Scientific
  - | String !Text
  - | Lambda (STree -> SubM STree)
  - | Bool !Bool
  - | Null
- type Key = Text
- object :: [Pair] -> Value
- (~>) :: ToMustache ω => Text -> ω -> Pair
- (↝) :: ToMustache ω => Text -> ω -> Pair
- (~=) :: ToJSON ι => Text -> ι -> Pair
- (⥱) :: ToJSON ι => Text -> ι -> Pair
- class ToMustache ω
- toMustache :: ToMustache ω => ω -> Value
- mFromJSON :: ToJSON ι => ι -> Value
- integralToMustache :: Integral ω => ω -> Value
- type Array = Vector Value
- type Object = HashMap Text Value
- type Pair = (Text, Value)
- data SubM a
- askContext :: SubM (Context Value)
- askPartials :: SubM TemplateCache
- data Context α = Context {
  - ctxtParents :: [α]
  - ctxtFocus :: α
  }

# Types for the Parser / Template

type ASTree α = [Node α] Source #

type STree = ASTree Text Source #

Syntax tree for a mustache template

data Node α Source #

Basic values composing the STree

Constructors

TextBlock α |
Section DataIdentifier (ASTree α) |
InvertedSection DataIdentifier (ASTree α) |
Variable Bool DataIdentifier |
Partial (Maybe α) FilePath |

#### Instances

Instances details

Lift α => Lift (Node α :: Type) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods lift :: Quote m => Node α -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => Node α -> Code m (Node α) Source #
Show α => Show (Node α) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods showsPrec :: Int -> Node α -> ShowS Source # show :: Node α -> String Source # showList :: [Node α] -> ShowS Source #
Eq α => Eq (Node α) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods (==) :: Node α -> Node α -> Bool Source # (/=) :: Node α -> Node α -> Bool Source #
ToMustache (Context Value -> STree -> STree) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (Context Value -> STree -> STree) -> Value Source # listToMustache :: [Context Value -> STree -> STree] -> Value
ToMustache (Context Value -> STree -> Text) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (Context Value -> STree -> Text) -> Value Source # listToMustache :: [Context Value -> STree -> Text] -> Value
ToMustache (Context Value -> STree -> Text) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (Context Value -> STree -> Text) -> Value Source # listToMustache :: [Context Value -> STree -> Text] -> Value
ToMustache (Context Value -> STree -> String) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (Context Value -> STree -> String) -> Value Source # listToMustache :: [Context Value -> STree -> String] -> Value
ToMustache (STree -> SubM STree) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: (STree -> SubM STree) -> Value Source # listToMustache :: [STree -> SubM STree] -> Value
ToMustache (STree -> SubM Text) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (STree -> SubM Text) -> Value Source # listToMustache :: [STree -> SubM Text] -> Value

data DataIdentifier Source #

Kinds of identifiers for Variables and sections

Constructors

NamedData [Key] |
Implicit |

#### Instances

Instances details

Show DataIdentifier Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods showsPrec :: Int -> DataIdentifier -> ShowS Source # show :: DataIdentifier -> String Source # showList :: [DataIdentifier] -> ShowS Source #
Eq DataIdentifier Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods (==) :: DataIdentifier -> DataIdentifier -> Bool Source # (/=) :: DataIdentifier -> DataIdentifier -> Bool Source #
Lift DataIdentifier Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods lift :: Quote m => DataIdentifier -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => DataIdentifier -> Code m DataIdentifier Source #

data Template Source #

A compiled Template with metadata.

Constructors

Template |

Fields

- name :: String
- ast :: STree
- partials :: TemplateCache

#### Instances

Instances details

Show Template Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods showsPrec :: Int -> Template -> ShowS Source # show :: Template -> String Source # showList :: [Template] -> ShowS Source #
Lift Template Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods lift :: Quote m => Template -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => Template -> Code m Template Source #
MonadReader (Context Value, TemplateCache) SubM Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods ask :: SubM (Context Value, TemplateCache) Source # local :: ((Context Value, TemplateCache) -> (Context Value, TemplateCache)) -> SubM a -> SubM a Source # reader :: ((Context Value, TemplateCache) -> a) -> SubM a Source #

type TemplateCache = HashMap String Template Source #

A collection of templates with quick access via their hashed names

# Types for the Substitution / Data

data Value Source #

Internal value representation

Constructors

Object !Object |
Array !Array |
Number !Scientific |
String !Text |
Lambda (STree -> SubM STree) |
Bool !Bool |
Null |

#### Instances

Instances details

Show Value Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods showsPrec :: Int -> Value -> ShowS Source # show :: Value -> String Source # showList :: [Value] -> ShowS Source #
ToMustache Value Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Value -> Value Source # listToMustache :: [Value] -> Value
ToMustache (Context Value -> STree -> STree) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (Context Value -> STree -> STree) -> Value Source # listToMustache :: [Context Value -> STree -> STree] -> Value
ToMustache (Context Value -> STree -> Text) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (Context Value -> STree -> Text) -> Value Source # listToMustache :: [Context Value -> STree -> Text] -> Value
ToMustache (Context Value -> STree -> Text) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (Context Value -> STree -> Text) -> Value Source # listToMustache :: [Context Value -> STree -> Text] -> Value
ToMustache (Context Value -> STree -> String) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (Context Value -> STree -> String) -> Value Source # listToMustache :: [Context Value -> STree -> String] -> Value
MonadReader (Context Value, TemplateCache) SubM Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods ask :: SubM (Context Value, TemplateCache) Source # local :: ((Context Value, TemplateCache) -> (Context Value, TemplateCache)) -> SubM a -> SubM a Source # reader :: ((Context Value, TemplateCache) -> a) -> SubM a Source #

type Key = Text Source #

Type of key used for retrieving data from `Value`s

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

Expand

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

Map keys to values that provide a `ToMustache` instance

Recommended in conjunction with the `OverloadedStrings` extension.

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

Unicode version of `~>`

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

Map keys to values that provide a `ToJSON` instance

Recommended in conjunction with the `OverloadedStrings` extension.

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

Unicode version of `~=`

class ToMustache ω Source #

Conversion class

Minimal complete definition

toMustache

#### Instances

Instances details

ToMustache Value Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Value -> Value0 Source # listToMustache :: [Value] -> Value0
ToMustache Int16 Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Int16 -> Value Source # listToMustache :: [Int16] -> Value
ToMustache Int32 Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Int32 -> Value Source # listToMustache :: [Int32] -> Value
ToMustache Int64 Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Int64 -> Value Source # listToMustache :: [Int64] -> Value
ToMustache Int8 Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Int8 -> Value Source # listToMustache :: [Int8] -> Value
ToMustache Word16 Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Word16 -> Value Source # listToMustache :: [Word16] -> Value
ToMustache Word32 Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Word32 -> Value Source # listToMustache :: [Word32] -> Value
ToMustache Word64 Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Word64 -> Value Source # listToMustache :: [Word64] -> Value
ToMustache Word8 Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Word8 -> Value Source # listToMustache :: [Word8] -> Value
ToMustache Value Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Value -> Value Source # listToMustache :: [Value] -> Value
ToMustache Scientific Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Scientific -> Value Source # listToMustache :: [Scientific] -> Value
ToMustache Text Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Text -> Value Source # listToMustache :: [Text] -> Value
ToMustache Text Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Text -> Value Source # listToMustache :: [Text] -> Value
ToMustache Integer Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Integer -> Value Source # listToMustache :: [Integer] -> Value
ToMustache Natural Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Natural -> Value Source # listToMustache :: [Natural] -> Value
ToMustache () Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: () -> Value Source # listToMustache :: [()] -> Value
ToMustache Bool Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Bool -> Value Source # listToMustache :: [Bool] -> Value
ToMustache Char Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Char -> Value Source # listToMustache :: [Char] -> Value
ToMustache Double Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Double -> Value Source # listToMustache :: [Double] -> Value
ToMustache Float Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Float -> Value Source # listToMustache :: [Float] -> Value
ToMustache Int Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Int -> Value Source # listToMustache :: [Int] -> Value
ToMustache Word Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Word -> Value Source # listToMustache :: [Word] -> Value
ToMustache ω => ToMustache (Seq ω) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Seq ω -> Value Source # listToMustache :: [Seq ω] -> Value
ToMustache ω => ToMustache (Set ω) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Set ω -> Value Source # listToMustache :: [Set ω] -> Value
ToMustache ω => ToMustache (HashSet ω) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: HashSet ω -> Value Source # listToMustache :: [HashSet ω] -> Value
ToMustache ω => ToMustache (Vector ω) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Vector ω -> Value Source # listToMustache :: [Vector ω] -> Value
ToMustache ω => ToMustache (Maybe ω) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Maybe ω -> Value Source # listToMustache :: [Maybe ω] -> Value
ToMustache α => ToMustache [α] Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: [α] -> Value Source # listToMustache :: [[α]] -> Value
ToMustache ω => ToMustache (Map Text ω) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Map Text ω -> Value Source # listToMustache :: [Map Text ω] -> Value
ToMustache ω => ToMustache (Map Text ω) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Map Text ω -> Value Source # listToMustache :: [Map Text ω] -> Value
ToMustache ω => ToMustache (Map String ω) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: Map String ω -> Value Source # listToMustache :: [Map String ω] -> Value
ToMustache ω => ToMustache (HashMap Text ω) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: HashMap Text ω -> Value Source # listToMustache :: [HashMap Text ω] -> Value
ToMustache ω => ToMustache (HashMap Text ω) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: HashMap Text ω -> Value Source # listToMustache :: [HashMap Text ω] -> Value
ToMustache ω => ToMustache (HashMap String ω) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: HashMap String ω -> Value Source # listToMustache :: [HashMap String ω] -> Value
ToMustache (Context Value -> STree -> STree) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (Context Value -> STree -> STree) -> Value Source # listToMustache :: [Context Value -> STree -> STree] -> Value
ToMustache (Context Value -> STree -> Text) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (Context Value -> STree -> Text) -> Value Source # listToMustache :: [Context Value -> STree -> Text] -> Value
ToMustache (Context Value -> STree -> Text) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (Context Value -> STree -> Text) -> Value Source # listToMustache :: [Context Value -> STree -> Text] -> Value
ToMustache (Context Value -> STree -> String) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (Context Value -> STree -> String) -> Value Source # listToMustache :: [Context Value -> STree -> String] -> Value
ToMustache (STree -> SubM STree) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: (STree -> SubM STree) -> Value Source # listToMustache :: [STree -> SubM STree] -> Value
ToMustache (STree -> SubM Text) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (STree -> SubM Text) -> Value Source # listToMustache :: [STree -> SubM Text] -> Value
(ToMustache α, ToMustache β) => ToMustache (α, β) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: (α, β) -> Value Source # listToMustache :: [(α, β)] -> Value
(ToMustache α, ToMustache β, ToMustache γ) => ToMustache (α, β, γ) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: (α, β, γ) -> Value Source # listToMustache :: [(α, β, γ)] -> Value
(ToMustache α, ToMustache β, ToMustache γ, ToMustache δ) => ToMustache (α, β, γ, δ) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: (α, β, γ, δ) -> Value Source # listToMustache :: [(α, β, γ, δ)] -> Value
(ToMustache α, ToMustache β, ToMustache γ, ToMustache δ, ToMustache ε) => ToMustache (α, β, γ, δ, ε) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: (α, β, γ, δ, ε) -> Value Source # listToMustache :: [(α, β, γ, δ, ε)] -> Value
(ToMustache α, ToMustache β, ToMustache γ, ToMustache δ, ToMustache ε, ToMustache ζ) => ToMustache (α, β, γ, δ, ε, ζ) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: (α, β, γ, δ, ε, ζ) -> Value Source # listToMustache :: [(α, β, γ, δ, ε, ζ)] -> Value
(ToMustache α, ToMustache β, ToMustache γ, ToMustache δ, ToMustache ε, ToMustache ζ, ToMustache η) => ToMustache (α, β, γ, δ, ε, ζ, η) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: (α, β, γ, δ, ε, ζ, η) -> Value Source # listToMustache :: [(α, β, γ, δ, ε, ζ, η)] -> Value
(ToMustache α, ToMustache β, ToMustache γ, ToMustache δ, ToMustache ε, ToMustache ζ, ToMustache η, ToMustache θ) => ToMustache (α, β, γ, δ, ε, ζ, η, θ) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: (α, β, γ, δ, ε, ζ, η, θ) -> Value Source # listToMustache :: [(α, β, γ, δ, ε, ζ, η, θ)] -> Value

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

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

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

integralToMustache :: Integral ω => ω -> Value Source #

## 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 `Object`s

data SubM a Source #

#### Instances

Instances details

Applicative SubM Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods pure :: a -> SubM a Source # (<*>) :: SubM (a -> b) -> SubM a -> SubM b Source # liftA2 :: (a -> b -> c) -> SubM a -> SubM b -> SubM c Source # (*>) :: SubM a -> SubM b -> SubM b Source # (<*) :: SubM a -> SubM b -> SubM a Source #
Functor SubM Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods fmap :: (a -> b) -> SubM a -> SubM b Source # (<$) :: a -> SubM b -> SubM a Source #
Monad SubM Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods (>>=) :: SubM a -> (a -> SubM b) -> SubM b Source # (>>) :: SubM a -> SubM b -> SubM b Source # return :: a -> SubM a Source #
ToMustache (STree -> SubM STree) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods toMustache :: (STree -> SubM STree) -> Value Source # listToMustache :: [STree -> SubM STree] -> Value
ToMustache (STree -> SubM Text) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (STree -> SubM Text) -> Value Source # listToMustache :: [STree -> SubM Text] -> Value
MonadReader (Context Value, TemplateCache) SubM Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods ask :: SubM (Context Value, TemplateCache) Source # local :: ((Context Value, TemplateCache) -> (Context Value, TemplateCache)) -> SubM a -> SubM a Source # reader :: ((Context Value, TemplateCache) -> a) -> SubM a Source #

askContext :: SubM (Context Value) Source #

askPartials :: SubM TemplateCache Source #

data Context α Source #

Representation of stateful context for the substitution process

Constructors

Context |

Fields

- ctxtParents :: [α]
- ctxtFocus :: α

#### Instances

Instances details

Show α => Show (Context α) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods showsPrec :: Int -> Context α -> ShowS Source # show :: Context α -> String Source # showList :: [Context α] -> ShowS Source #
Eq α => Eq (Context α) Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods (==) :: Context α -> Context α -> Bool Source # (/=) :: Context α -> Context α -> Bool Source #
Ord α => Ord (Context α) Source # |

Instance details

Defined in Text.Mustache.Internal.Types

Methods

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

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

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

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

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

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

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

ToMustache (Context Value -> STree -> STree) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (Context Value -> STree -> STree) -> Value Source # listToMustache :: [Context Value -> STree -> STree] -> Value
ToMustache (Context Value -> STree -> Text) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (Context Value -> STree -> Text) -> Value Source # listToMustache :: [Context Value -> STree -> Text] -> Value
ToMustache (Context Value -> STree -> Text) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (Context Value -> STree -> Text) -> Value Source # listToMustache :: [Context Value -> STree -> Text] -> Value
ToMustache (Context Value -> STree -> String) Source # |
Instance details Defined in Text.Mustache.Render Methods toMustache :: (Context Value -> STree -> String) -> Value Source # listToMustache :: [Context Value -> STree -> String] -> Value
MonadReader (Context Value, TemplateCache) SubM Source # |
Instance details Defined in Text.Mustache.Internal.Types Methods ask :: SubM (Context Value, TemplateCache) Source # local :: ((Context Value, TemplateCache) -> (Context Value, TemplateCache)) -> SubM a -> SubM a Source # reader :: ((Context Value, TemplateCache) -> a) -> SubM a Source #