Safe Haskell | None |
---|---|
Language | Haskell2010 |
- compileTextFile :: FilePath -> Q Exp
- compileTextFileWithDefault :: FilePath -> DefaultScope -> Q Exp
- compileHtmlFile :: FilePath -> Q Exp
- compileHtmlFileWithDefault :: FilePath -> DefaultScope -> Q Exp
- compileText :: QuasiQuoter
- compileHtml :: QuasiQuoter
- data HeterocephalusSetting
- type DefaultScope = [(Ident, Q Exp)]
- compile :: HeterocephalusSetting -> QuasiQuoter
- compileWithDefault :: DefaultScope -> HeterocephalusSetting -> QuasiQuoter
- compileFile :: HeterocephalusSetting -> FilePath -> Q Exp
- compileFileWithDefault :: DefaultScope -> HeterocephalusSetting -> FilePath -> Q Exp
- compileFromString :: HeterocephalusSetting -> String -> Q Exp
- compileFromStringWithDefault :: DefaultScope -> HeterocephalusSetting -> String -> Q Exp
Core functions
compileTextFile :: FilePath -> Q Exp Source #
A function to compile template file.
This function DOES NOT escape template variables.
To render the compiled file, use
.Renderer
.*.renderMarkup
>>>
putStr $ renderMarkup (let as = ["<a>", "b"] in $(compileTextFile "templates/sample.txt"))
sample key: <a>, key: b,
compileTextFileWithDefault :: FilePath -> DefaultScope -> Q Exp Source #
Same as compileText
but we can specify default scope.
>>>
:set -XOverloadedStrings
>>>
:{
>>>
putStr $ renderMarkup (
>>>
let as = ["<a>", "b"]
>>>
in $(compileTextFileWithDefault "templates/sample.txt"
>>>
[("as", [| ["foo", "bar"] |])]
>>>
)
>>>
)
>>>
:}
sample key: <a>, key: b,
>>>
:{
>>>
putStr $ renderMarkup (
>>>
$(compileTextFileWithDefault "templates/sample.txt"
>>>
[("as", [| ["foo", "bar"] |])]
>>>
)
>>>
)
>>>
:}
sample key: foo, key: bar,
compileHtmlFile :: FilePath -> Q Exp Source #
Same as compileTextFile
but escapes template variables for Html.
>>>
putStr $ renderMarkup (let as = ["<a>", "b"] in $(compileHtmlFile "templates/sample.txt"))
sample key: <a>, key: b,
compileHtmlFileWithDefault :: FilePath -> DefaultScope -> Q Exp Source #
Same as compileHtmlFile
but we can specify default scope.
>>>
:set -XOverloadedStrings
>>>
:{
>>>
putStr $ renderMarkup (
>>>
let as = ["<a>", "b"]
>>>
in $(compileHtmlFileWithDefault "templates/sample.txt"
>>>
[("as", [| ["foo", "bar"] |])]
>>>
)
>>>
)
>>>
:}
sample key: <a>, key: b,
>>>
:{
>>>
putStr $ renderMarkup (
>>>
$(compileHtmlFileWithDefault "templates/sample.txt"
>>>
[("as", [| ["foo", "bar"] |])]
>>>
)
>>>
)
>>>
:}
sample key: foo, key: bar,
QuasiQuoters
compileText :: QuasiQuoter Source #
Heterocephalus quasi-quoter.
This function DOES NOT escape template variables.
To render the compiled file, use
.Renderer
.*.renderMarkup
>>>
renderMarkup (let as = ["<a>", "b"] in [compileText|sample %{ forall a <- as }key: #{a}, %{ endforall }|])
"sample key: <a>, key: b, "
>>>
renderMarkup (let num=2 in [compileText|#{num} is %{ if even num }even number.%{ else }odd number.%{ endif }|])
"2 is even number."
compileHtml :: QuasiQuoter Source #
Heterocephalus quasi-quoter for Html.
Same as compileText
but this function do escape template variables for Html.
>>>
renderMarkup (let as = ["<a>", "b"] in [compileHtml|sample %{ forall a <- as }key: #{a}, %{ endforall }|])
"sample key: <a>, key: b, "
low-level
data HeterocephalusSetting Source #
compileFile :: HeterocephalusSetting -> FilePath -> Q Exp Source #
Compile a template file.
compileFileWithDefault :: DefaultScope -> HeterocephalusSetting -> FilePath -> Q Exp Source #
Same as compileFile
but we can specify default scope.
compileFromString :: HeterocephalusSetting -> String -> Q Exp Source #