-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Mustache templates for Haskell -- -- Mustache templates for Haskell. @package stache @version 2.2.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: -- -- newtype Key Key :: [Text] -> Key [unKey] :: Key -> [Text] -- | Pretty-print a key, this is helpful, for example, if you want to -- display an error message. showKey :: Key -> Text -- | Identifier for partials. Note that with the OverloadedStrings -- extension you can use just string literals to create values of this -- type. newtype PName PName :: Text -> PName [unPName] :: PName -> Text -- | Exception that is thrown when parsing of a template fails or -- referenced values are not provided. newtype MustacheException -- | Template parser has failed. This contains the parse error. -- -- Before version 0.2.0 it was called MustacheException. -- -- The Text field was added in version 1.0.0. MustacheParserException :: ParseErrorBundle Text Void -> MustacheException -- | Warning that may be generated during rendering of a Template. data MustacheWarning -- | The template contained a variable for which there was no data -- counterpart in the current context. MustacheVariableNotFound :: Key -> MustacheWarning -- | A complex value such as an Object or Array was -- directly rendered into the template. MustacheDirectlyRenderedValue :: Key -> MustacheWarning -- | Pretty-print a MustacheWarning. displayMustacheWarning :: MustacheWarning -> String instance GHC.Generics.Generic Text.Mustache.Type.MustacheWarning instance GHC.Show.Show Text.Mustache.Type.MustacheWarning instance GHC.Classes.Eq Text.Mustache.Type.MustacheWarning instance GHC.Generics.Generic Text.Mustache.Type.MustacheException instance GHC.Show.Show Text.Mustache.Type.MustacheException instance GHC.Classes.Eq Text.Mustache.Type.MustacheException instance GHC.Generics.Generic Text.Mustache.Type.Template instance Data.Data.Data Text.Mustache.Type.Template instance GHC.Show.Show Text.Mustache.Type.Template instance GHC.Classes.Ord Text.Mustache.Type.Template instance GHC.Classes.Eq Text.Mustache.Type.Template instance GHC.Generics.Generic Text.Mustache.Type.Node instance Data.Data.Data Text.Mustache.Type.Node instance GHC.Show.Show Text.Mustache.Type.Node instance GHC.Classes.Ord Text.Mustache.Type.Node instance GHC.Classes.Eq Text.Mustache.Type.Node instance GHC.Generics.Generic Text.Mustache.Type.PName instance Data.Data.Data Text.Mustache.Type.PName instance GHC.Show.Show Text.Mustache.Type.PName instance GHC.Classes.Ord Text.Mustache.Type.PName instance GHC.Classes.Eq Text.Mustache.Type.PName instance GHC.Generics.Generic Text.Mustache.Type.Key instance Data.Data.Data Text.Mustache.Type.Key instance GHC.Base.Monoid Text.Mustache.Type.Key instance GHC.Base.Semigroup Text.Mustache.Type.Key instance GHC.Show.Show Text.Mustache.Type.Key instance GHC.Classes.Ord Text.Mustache.Type.Key instance GHC.Classes.Eq Text.Mustache.Type.Key instance GHC.Exception.Type.Exception Text.Mustache.Type.MustacheException instance GHC.Base.Semigroup Text.Mustache.Type.Template instance Language.Haskell.TH.Syntax.Lift Text.Mustache.Type.Template instance Language.Haskell.TH.Syntax.Lift Text.Mustache.Type.Node instance Data.String.IsString Text.Mustache.Type.PName instance Control.DeepSeq.NFData Text.Mustache.Type.PName instance Language.Haskell.TH.Syntax.Lift Text.Mustache.Type.PName instance Control.DeepSeq.NFData Text.Mustache.Type.Key instance Language.Haskell.TH.Syntax.Lift Text.Mustache.Type.Key -- | Functions for rendering Mustache templates. 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.Render -- | 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) -- | Megaparsec parser for Mustache templates. 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.Parser -- | Parse a given Mustache template. parseMustache :: FilePath -> Text -> Either (ParseErrorBundle Text Void) [Node] -- | Mustache Template creation from file or a Text value. -- 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.Compile -- | 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. -- -- Note that each template/partial will get an identifier which consists -- of the name of corresponding template file with extension -- .mustache dropped. This is important for e.g. selecting -- active template after loading (the first argument). -- -- The action can throw MustacheParserException and the same -- exceptions as getDirectoryContents, and readFile. -- --
--   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 MustacheParserException and 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 bundle -> putStrLn (errorBundlePretty bundle)
--       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: -- -- module Text.Mustache -- | 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: -- -- newtype Key Key :: [Text] -> Key [unKey] :: Key -> [Text] -- | Identifier for partials. Note that with the OverloadedStrings -- extension you can use just string literals to create values of this -- type. newtype PName PName :: Text -> PName [unPName] :: PName -> Text -- | Exception that is thrown when parsing of a template fails or -- referenced values are not provided. newtype MustacheException -- | Template parser has failed. This contains the parse error. -- -- Before version 0.2.0 it was called MustacheException. -- -- The Text field was added in version 1.0.0. MustacheParserException :: ParseErrorBundle Text Void -> MustacheException -- | Warning that may be generated during rendering of a Template. data MustacheWarning -- | The template contained a variable for which there was no data -- counterpart in the current context. MustacheVariableNotFound :: Key -> MustacheWarning -- | A complex value such as an Object or Array was -- directly rendered into the template. MustacheDirectlyRenderedValue :: Key -> MustacheWarning -- | Pretty-print a MustacheWarning. displayMustacheWarning :: MustacheWarning -> String -- | 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. -- -- Note that each template/partial will get an identifier which consists -- of the name of corresponding template file with extension -- .mustache dropped. This is important for e.g. selecting -- active template after loading (the first argument). -- -- The action can throw MustacheParserException and the same -- exceptions as getDirectoryContents, and readFile. -- --
--   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 MustacheParserException and 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)