| Copyright | (c) Justus Adam, 2015 |
|---|---|
| License | LGPL-3 |
| Maintainer | dev@justus.science |
| Stability | experimental |
| Portability | POSIX |
| Safe Haskell | None |
| Language | Haskell2010 |
Text.Mustache.Types
Description
- type STree = [Node Text]
- data Template = Template {}
- data Node α
- data DataIdentifier
- data Value
- type Key = Text
- object :: [Pair] -> Value
- (~>) :: ToMustache ω => Text -> ω -> Pair
- (↝) :: ToMustache ω => Text -> ω -> Pair
- (~=) :: ToJSON ι => Text -> ι -> Pair
- (⥱) :: ToJSON ι => Text -> ι -> Pair
- class ToMustache ω where
- toMustache :: ω -> Value
- mFromJSON :: ToJSON ι => ι -> Value
- type Array = Vector Value
- type Object = HashMap Text Value
- type Pair = (Text, Value)
- data Context α = Context [α] α
- type TemplateCache = HashMap String Template
Types for the Parser / Template
A compiled Template with metadata.
Basic values composing the STree
Constructors
| TextBlock α | |
| Section DataIdentifier STree | |
| InvertedSection DataIdentifier STree | |
| Variable Bool DataIdentifier | |
| Partial (Maybe α) FilePath |
Instances
| Eq α => Eq (Node α) Source | |
| Show α => Show (Node α) Source | |
| ToMustache (Context Value -> STree -> String) Source | |
| ToMustache (Context Value -> STree -> Text) Source | |
| ToMustache (Context Value -> STree -> Text) Source | |
| ToMustache (Context Value -> STree -> STree) Source | |
| ToMustache (STree -> Text) Source | |
| ToMustache (STree -> STree) Source |
Types for the Substitution / Data
Internal value representation
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 infixr 8 Source
Map keys to values that provide a ToMustache instance
Recommended in conjunction with the OverloadedStrings extension.
(~=) :: ToJSON ι => Text -> ι -> Pair infixr 8 Source
Map keys to values that provide a ToJSON instance
Recommended in conjunction with the OverloadedStrings extension.
class ToMustache ω where Source
Conversion class
Methods
toMustache :: ω -> Value Source
Instances
mFromJSON :: ToJSON ι => ι -> Value Source
Converts a value that can be represented as JSON to a Value.
Representation
Representation of stateful context for the substitution process
Constructors
| Context [α] α |
Instances
| Eq α => Eq (Context α) Source | |
| Ord α => Ord (Context α) Source | |
| Show α => Show (Context α) Source | |
| ToMustache (Context Value -> STree -> String) Source | |
| ToMustache (Context Value -> STree -> Text) Source | |
| ToMustache (Context Value -> STree -> Text) Source | |
| ToMustache (Context Value -> STree -> STree) Source |
type TemplateCache = HashMap String Template Source
A collection of templates with quick access via their hashed names