Copyright | (c) 2019-2021 Vaclav Svejcar |
---|---|
License | BSD-3-Clause |
Maintainer | vaclav.svejcar@gmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
Module providing interface for working with template files in extensible way.
Supported template is represented by the Template
type class.
Synopsis
- class Template a where
- templateExtensions :: NonEmpty Text
- parseTemplate :: MonadThrow m => Maybe Text -> Text -> m a
- renderTemplate :: MonadThrow m => Variables -> a -> m Text
- rawTemplate :: a -> Text
- emptyTemplate :: (MonadThrow m, Template a) => m a
- data TemplateError
Extendable Template Support
class Template a where Source #
Type class representing supported template file.
Returns list of supported file extensions for this template type.
:: MonadThrow m | |
=> Maybe Text | name of the template (optional) |
-> Text | raw template text |
-> m a | parsed template |
Parses template from given raw text.
:: MonadThrow m | |
=> Variables | values of variables to replace |
-> a | parsed template to render |
-> m Text | rendered template text |
Renders parsed template and replaces all variables with actual values.
:: a | template for which to return raw template text |
-> Text | raw template text |
Returns the raw text of the template, same that has been parsed by
parseTemplate
method.
Instances
Template Mustache Source # | Support for Mustache templates. |
Defined in Headroom.Template.Mustache templateExtensions :: NonEmpty Text Source # parseTemplate :: MonadThrow m => Maybe Text -> Text -> m Mustache Source # renderTemplate :: MonadThrow m => Variables -> Mustache -> m Text Source # rawTemplate :: Mustache -> Text Source # |
Helper Functions
emptyTemplate :: (MonadThrow m, Template a) => m a Source #
Returns empty template of selected type.
Error Data Types
data TemplateError Source #
Error during processing template.
MissingVariables Text [Text] | missing variable values |
ParseError Text | error parsing raw template text |
Instances
Eq TemplateError Source # | |
Defined in Headroom.Template (==) :: TemplateError -> TemplateError -> Bool # (/=) :: TemplateError -> TemplateError -> Bool # | |
Show TemplateError Source # | |
Defined in Headroom.Template showsPrec :: Int -> TemplateError -> ShowS # show :: TemplateError -> String # showList :: [TemplateError] -> ShowS # | |
Exception TemplateError Source # | |
Defined in Headroom.Template |