mustache-0.1.0.0: A mustache template parser library.

Copyright(c) Justus Adam, 2015
LicenseLGPL-3
Maintainerdevelopment@justusadam.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Text.Mustache.Types

Contents

Description

 

Synopsis

Types for the Parser / Template

type MustacheAST = [MustacheNode Text] Source

Abstract syntax tree for a mustache template

data MustacheTemplate Source

A compiled Template with metadata.

Types for the Substitution / Data

Converting

object :: [(Text, Value)] -> 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 m => Text -> m -> KeyValuePair Source

Map keys to values that provide a ToMustache instance

Recommended in conjunction with the OverloadedStrings extension.

(~=) :: ToJSON j => Text -> j -> KeyValuePair Source

Map keys to values that provide a ToJSON instance

Recommended in conjunction with the OverloadedStrings extension.

(~~>) :: (Conversion t Text, ToMustache m) => t -> m -> KeyValuePair Source

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

(~~=) :: (Conversion t Text, ToJSON j) => t -> j -> KeyValuePair Source

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

toMustacheText :: Conversion t Text => t -> Value Source

Converts arbitrary String-likes to Values

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

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

Representation