-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple string substitution -- -- Simple string substitution library that supports "$"-based -- substitution. Meant to be used when Text.Printf or string -- concatenation would lead to code that is hard to read but when a full -- blown templating system might be overkill. @package template @version 0.1.1.1 -- | A simple string substitution library that supports "$"-based -- substitution. Substitution uses the following rules: -- --
-- import qualified Data.ByteString.Lazy.Char8 as B
-- import Text.Template
--
-- context = Map.fromList . map packPair
-- where packPair (x, y) = (B.pack x, B.pack y)
--
-- helloTemplate = B.pack "Hello, $name! Want some ${fruit}s?"
-- helloContext = context [("name", "Johan"), ("fruit", "banana")]
--
-- main = B.putStrLn $ substitute helloTemplate helloContext
--
--
-- If you render the same template multiple times it's faster to first
-- convert it to a more efficient representation using template
-- and then rendering it using render. In fact, all that
-- substitute does is to combine these two steps.
module Text.Template
-- | A repesentation of a ByteString template, supporting efficient
-- rendering.
data Template
-- | A mapping with keys that match the placeholders in the template.
type Context = Map ByteString ByteString
-- | Creates a template from a template string.
template :: ByteString -> Template
-- | Performs the template substitution, returning a new ByteString.
--
-- If a key is not found in the context an error is raised.
render :: Template -> Context -> ByteString
-- | Performs the template substitution, returning a new ByteString.
-- Note that
--
-- -- substitute tmpl ctx == render (template tmpl) ctx ---- -- If a key is not found in the context an error is raised. substitute :: ByteString -> Context -> ByteString -- | Shows the template string. showTemplate :: Template -> ByteString -- | Reads a template from a file lazily. Use 'text mode' on Windows to -- interpret newlines readTemplate :: FilePath -> IO Template -- | Renders and writes a template to a file. This is more efficient than -- first rendering the template to a ByteString and then -- writing it to a file using -- Data.ByteString.Lazy.Char8.writeFile. renderToFile :: FilePath -> Template -> Context -> IO () -- | Renders and writes a template to a Handle. This is more -- efficient than first rendering the template to a -- ByteString and then writing it to a Handle using -- Data.ByteString.Lazy.Char8.hPutStr. hRender :: Handle -> Template -> Context -> IO () instance Show Frag instance Show Template instance Eq Template