-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Pandoc-style document templates
--   
--   Please see README.md
@package doctemplates
@version 0.1.0.2


-- | A simple templating system with variable substitution and
--   conditionals. This module was formerly part of pandoc and is used for
--   pandoc's templates. The following program illustrates its use:
--   
--   <pre>
--   import Data.Text
--   import Data.Aeson
--   import Text.DocTemplates
--   
--   data Employee = Employee { firstName :: String
--                            , lastName  :: String
--                            , salary    :: Maybe Int }
--   instance ToJSON Employee where
--     toJSON e = object [ "name" .= object [ "first" .= firstName e
--                                          , "last"  .= lastName e ]
--                       , "salary" .= salary e ]
--   
--   template :: Text
--   template = "$for(employee)$Hi, $employee.name.first$. $if(employee.salary)$You make $employee.salary$.$else$No salary data.$endif$$sep$\n$endfor$"
--   
--   main = case compileTemplate template of
--            Left e    -&gt; error e
--            Right t   -&gt; putStrLn $ renderTemplate t $ object
--                           ["employee" .=
--                             [ Employee "John" "Doe" Nothing
--                             , Employee "Omar" "Smith" (Just 30000)
--                             , Employee "Sara" "Chen" (Just 60000) ]
--                           ]
--   </pre>
--   
--   A slot for an interpolated variable is a variable name surrounded by
--   dollar signs. To include a literal <tt>$</tt> in your template, use
--   <tt>$$</tt>. Variable names must begin with a letter and can contain
--   letters, numbers, <tt>_</tt>, <tt>-</tt>, and <tt>.</tt>.
--   
--   The values of variables are determined by a JSON object that is passed
--   as a parameter to <tt>renderTemplate</tt>. So, for example,
--   <tt>title</tt> will return the value of the <tt>title</tt> field, and
--   <tt>employee.salary</tt> will return the value of the <tt>salary</tt>
--   field of the object that is the value of the <tt>employee</tt> field.
--   
--   The value of a variable will be indented to the same level as the
--   variable.
--   
--   A conditional begins with <tt>$if(variable_name)$</tt> and ends with
--   <tt>$endif$</tt>. It may optionally contain an <tt>$else$</tt>
--   section. The if section is used if <tt>variable_name</tt> has a
--   non-null value, otherwise the else section is used.
--   
--   Conditional keywords should not be indented, or unexpected spacing
--   problems may occur.
--   
--   The <tt>$for$</tt> keyword can be used to iterate over an array. If
--   the value of the associated variable is not an array, a single
--   iteration will be performed on its value.
--   
--   You may optionally specify separators using <tt>$sep$</tt>, as in the
--   example above.
module Text.DocTemplates

-- | Render a compiled template using <tt>context</tt> to resolve
--   variables.
renderTemplate :: (ToJSON a, TemplateTarget b) => Template -> a -> b

-- | Combines <a>renderTemplate</a> and <a>compileTemplate</a>.
applyTemplate :: (ToJSON a, TemplateTarget b) => Text -> a -> Either String b
class TemplateTarget a
toTarget :: TemplateTarget a => Text -> a

-- | A convenience function for passing in an association list of string
--   values instead of a JSON <a>Value</a>.
varListToJSON :: [(String, String)] -> Value

-- | Compile a template.
compileTemplate :: Text -> Either String Template

-- | A <a>Template</a> is essentially a function that takes a JSON
--   <a>Value</a> and produces <a>Text</a>.
data Template
instance GHC.Base.Monoid Text.DocTemplates.Template
instance Text.DocTemplates.TemplateTarget Data.Text.Internal.Text
instance Text.DocTemplates.TemplateTarget GHC.Base.String
instance Text.DocTemplates.TemplateTarget Data.ByteString.Lazy.Internal.ByteString
instance Text.DocTemplates.TemplateTarget Text.Blaze.Html.Html
