-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Mustache templates for Haskell -- -- Mustache templates for Haskell. @package stache @version 2.0.0 -- | Types used in the package. You don't usually need to import the -- module, because Text.Mustache re-exports everything you may -- need, import that module instead. module Text.Mustache.Type -- | Mustache template as name of “top-level” template and a collection of -- all available templates (partials). -- -- Template is a Semigroup. This means that you can combine -- Templates (and their caches) using the -- (<>) operator, the resulting Template -- will have the same currently selected template as the left one. Union -- of caches is also left-biased. data Template Template :: PName -> Map PName [Node] -> Template -- | Name of currently “selected” template (top-level one). [templateActual] :: Template -> PName -- | Collection of all templates that are available for interpolation (as -- partials). The top-level one is also contained here and the “focus” -- can be switched easily by modifying templateActual. [templateCache] :: Template -> Map PName [Node] -- | Structural element of template. data Node -- | Plain text contained between tags TextBlock :: Text -> Node -- | HTML-escaped variable EscapedVar :: Key -> Node -- | Unescaped variable UnescapedVar :: Key -> Node -- | Mustache section Section :: Key -> [Node] -> Node -- | Inverted section InvertedSection :: Key -> [Node] -> Node -- | Partial with indentation level (Nothing means it was inlined) Partial :: PName -> (Maybe Pos) -> Node -- | Identifier for values to interpolate. -- -- The representation is the following: -- --
-- compileMustacheDir = complieMustacheDir' isMustacheFile --compileMustacheDir :: MonadIO m => PName -> FilePath -> m Template -- | The same as compileMustacheDir, but allows using a custom -- predicate for template selection. compileMustacheDir' :: MonadIO m => (FilePath -> Bool) -> PName -> FilePath -> m Template -- | Return a list of templates found in given directory. The returned -- paths are absolute. getMustacheFilesInDir :: MonadIO m => FilePath -> m [FilePath] -- | Return a list of templates found via a predicate in given directory. -- The returned paths are absolute. getMustacheFilesInDir' :: MonadIO m => (FilePath -> Bool) -> FilePath -> m [FilePath] -- | The default Mustache file predicate. isMustacheFile :: FilePath -> Bool -- | Compile a single Mustache template and select it. -- -- The action can throw the same exceptions as readFile. compileMustacheFile :: MonadIO m => FilePath -> m Template -- | Compile Mustache template from a lazy Text value. The cache -- will contain only this template named according to given PName. compileMustacheText :: PName -> Text -> Either (ParseErrorBundle Text Void) Template -- | Template Haskell helpers to compile Mustache templates at compile -- time. This module is not imported as part of Text.Mustache, so -- you need to import it yourself. Qualified import is recommended, but -- not necessary. -- -- At the moment, functions in this module only work with GHC 8 (they -- require at least template-haskell-2.11). module Text.Mustache.Compile.TH -- | Compile all templates in specified directory and select one. Template -- files should have the extension mustache, (e.g. -- foo.mustache) to be recognized. This function does not -- scan the directory recursively. -- -- This version compiles the templates at compile time. -- --
-- compileMustacheDir = compileMustacheDir' isMustacheFile --compileMustacheDir :: PName -> FilePath -> Q Exp -- | The same as compileMustacheDir, but allows using a custom -- predicate for template selection. -- -- This version compiles the templates at compile time. compileMustacheDir' :: (FilePath -> Bool) -> PName -> FilePath -> Q Exp -- | Compile single Mustache template and select it. -- -- This version compiles the template at compile time. compileMustacheFile :: FilePath -> Q Exp -- | Compile Mustache template from Text value. The cache will -- contain only this template named according to given Key. -- -- This version compiles the template at compile time. compileMustacheText :: PName -> Text -> Q Exp -- | Compile Mustache using QuasiQuoter. Usage: -- --
-- {-# LANGUAGE QuasiQuotes #-}
-- import Text.Mustache.Compile.TH (mustache)
--
-- foo :: Template
-- foo = [mustache|This is my inline {{ template }}.|]
--
--
-- Name of created partial is set to "quasi-quoted". You can
-- extend cache of Template created this way using
-- (<>) and so work with partials as usual.
mustache :: QuasiQuoter
-- | This is a Haskell implementation of Mustache templates. The
-- implementation conforms to the version 1.1.3 of official Mustache
-- specification https://github.com/mustache/spec. It is extremely
-- simple and straightforward to use with minimal but complete API—three
-- functions to compile templates (from directory, from file, and from
-- lazy text) and one to render them.
--
-- The implementation uses Megaparsec parsing library to parse the
-- templates which results in superior quality of error messages.
--
-- For rendering you only need to create Aeson's Value where you
-- put the data to interpolate. Since the library re-uses Aeson's
-- instances and most data types in the Haskell ecosystem are instances
-- of classes like ToJSON, the whole process is very simple for
-- the end user.
--
-- Template Haskell helpers for compilation of templates at compile time
-- are available in the Text.Mustache.Compile.TH module. The
-- helpers currently work only with GHC 8 and later.
--
-- One feature that is not currently supported is lambdas. The feature is
-- marked as optional in the spec and can be emulated via processing of
-- parsed template representation. The decision to drop lambdas is
-- intentional, for the sake of simplicity and better integration with
-- Aeson.
--
-- Here is an example of basic usage:
--
--
-- {-# LANGUAGE OverloadedStrings #-}
--
-- module Main (main) where
--
-- import Data.Aeson
-- import Data.Text
-- import Text.Megaparsec
-- import Text.Mustache
-- import qualified Data.Text.Lazy.IO as TIO
--
-- main :: IO ()
-- main = do
-- let res = compileMustacheText "foo"
-- "Hi, {{name}}! You have:\n{{#things}}\n * {{.}}\n{{/things}}\n"
-- case res of
-- Left err -> putStrLn (parseErrorPretty err)
-- Right template -> TIO.putStr $ renderMustache template $ object
-- [ "name" .= ("John" :: Text)
-- , "things" .= ["pen" :: Text, "candle", "egg"]
-- ]
--
--
-- If I run the program, it prints the following:
--
-- -- Hi, John! You have: -- * pen -- * candle -- * egg ---- -- For more information about Mustache templates the following links may -- be helpful: -- --
-- compileMustacheDir = complieMustacheDir' isMustacheFile --compileMustacheDir :: MonadIO m => PName -> FilePath -> m Template -- | The same as compileMustacheDir, but allows using a custom -- predicate for template selection. compileMustacheDir' :: MonadIO m => (FilePath -> Bool) -> PName -> FilePath -> m Template -- | Compile a single Mustache template and select it. -- -- The action can throw the same exceptions as readFile. compileMustacheFile :: MonadIO m => FilePath -> m Template -- | Compile Mustache template from a lazy Text value. The cache -- will contain only this template named according to given PName. compileMustacheText :: PName -> Text -> Either (ParseErrorBundle Text Void) Template -- | Render a Mustache Template using Aeson's Value to get -- actual values for interpolation. renderMustache :: Template -> Value -> Text -- | Like renderMustache, but also returns a collection of warnings. renderMustacheW :: Template -> Value -> ([MustacheWarning], Text)