Safe Haskell | Safe-Inferred |
---|---|
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
Synopsis
- newtype Template = Template {}
- fromText :: Text -> Either String Template
- readTemplateFile :: FilePath -> IO (Either String Template)
- addTag :: Template -> Text -> Text -> Maybe Template
- tagsOf :: Template -> [Token]
- tagsRename :: [(Text, Text)] -> Template -> Template
- isFinal :: Template -> Bool
- toText :: Template -> Text
- toFinalText :: Template -> Text
- compress :: Template -> Template
- writeTemplateFile :: FilePath -> Template -> IO ()
- insertTemplate :: Template -> Token -> Template -> Maybe Template
- insertManyTemplates :: Template -> [(Token, Template)] -> Maybe Template
- newtype 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
- join :: Context -> Context -> Either Context 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
toFinalText :: Template -> Text Source #
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 [("tag","replacement"), ("theme","Haskell")] context Context {variables = fromList [("etc.","..."),("theme","Haskell"),("tag","replacement"),("name","")]}
deleteVariables :: [Text] -> Context -> Context Source #
Delete variables from a Context
by these names.
λ>deleteVariables ["tag"] context Context {variables = fromList [("etc.","..."),("theme","Haskell"),("name","")]}
JSON Context
file
writeContextFile :: FilePath -> Context -> IO () Source #
Write a Context
to a file.
{ "tag": "replacement", "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","")]}}