| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Text.Glabrous
Contents
Description
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
- tagsOf :: Template -> [Tag]
- isFinal :: Template -> Bool
- writeTemplateFile :: FilePath -> Template -> IO ()
- data Context = Context {}
- initContext :: Context
- fromList :: [(Text, Text)] -> Context
- fromTemplate :: Template -> Context
- setVariables :: [(Text, Text)] -> Context -> Context
- deleteVariables :: [Text] -> Context -> Context
- 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
Context
Get a Context
initContext :: Context Source #
Build an empty Context.
fromTemplate :: Template -> 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 the list
of its Tags.
λ>partialProcess' template context
Partial {template = Template {content = [Literal "Some ",Tag "tags",Literal " are unused in this ",Tag "text",Literal "."]}, tags = ["tags","text"]}