Safe Haskell | None |
---|---|
Language | Haskell2010 |
A minimalistic Mustache-like syntax, truly logic-less,
pure Text
template library
- Use only the simplest Mustache tag {{name}} called a variable.
- HTML agnostic
- data Template = Template {}
- type Tag = Text
- fromText :: Text -> Either String Template
- readTemplateFile :: FilePath -> IO (Either String Template)
- toText :: Template -> Text
- isFinal :: Template -> Bool
- tagsOf :: Template -> [Tag]
- tagsRename :: [(Text, Text)] -> Template -> Template
- compress :: Template -> Template
- writeTemplateFile :: FilePath -> Template -> IO ()
- data Context = Context {}
- initContext :: Context
- fromTagsList :: [Text] -> Context
- fromList :: [(Text, Text)] -> Context
- fromTemplate :: Template -> Context
- setVariables :: [(Text, Text)] -> Context -> Context
- deleteVariables :: [Text] -> Context -> Context
- variablesOf :: Context -> [Text]
- isSet :: Context -> Bool
- unsetContext :: Context -> Maybe Context
- readContextFile :: FilePath -> IO (Maybe Context)
- writeContextFile :: FilePath -> Context -> IO ()
- initContextFile :: FilePath -> Context -> IO ()
- process :: Template -> Context -> Text
- processWithDefault :: Text -> Template -> Context -> Text
- partialProcess :: Template -> Context -> Template
- data Result
- partialProcess' :: Template -> Context -> Result
Template
Get a Template
Template
operations
compress :: Template -> Template Source #
Optimize a Template
content after (many) partialProcess
(') rewriting(s).
Context
Get a Context
initContext :: Context Source #
Build an empty Context
.
fromTagsList :: [Text] -> Context Source #
Context
operations
setVariables :: [(Text, Text)] -> Context -> Context Source #
Populate with variables and/or update variables in the given Context
.
λ>setVariables [("something","something new"), ("about","Haskell")] context Context {variables = fromList [("etc.","..."),("about","Haskell"),("something","something new"),("name","")]}
deleteVariables :: [Text] -> Context -> Context Source #
Delete variables from a Context
by these names.
λ>deleteVariables ["something"] context Context {variables = fromList [("etc.","..."),("about","Haskell"),("name","")]}
JSON Context
file
writeContextFile :: FilePath -> Context -> IO () Source #
Write a Context
to a file.
{ "something": "something else", "etc.": "..." }
Processing
partialProcess' :: Template -> Context -> Result Source #
Process a (sub)Context
present in the given template, and
get either a Final
Text
or a new Template
with its unset
ad hoc Context
.
λ>partialProcess' template context Partial {template = Template {content = [Literal "Some ",Tag "tags",Literal " are unused in this ",Tag "text",Literal "."]}, context = Context {variables = fromList [("text",""),("tags","")]}}