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


-- | A template DSL library
--   
--   A minimalistic, Mustache-like syntax, truly logic-less, pure Text
--   template DSL library
@package glabrous
@version 0.3.5

module Text.Glabrous.Types
data Token
Tag :: !Text -> Token
Literal :: !Text -> Token
data Template
Template :: ![Token] -> Template
[content] :: Template -> ![Token]
data Context
Context :: !(HashMap Text Text) -> Context
[variables] :: Context -> !(HashMap Text Text)
type Tag = Text
data Result
Final :: !Text -> Result
Partial :: !Template -> !Context -> Result
[template] :: Result -> !Template
[context] :: Result -> !Context
instance GHC.Show.Show Text.Glabrous.Types.Result
instance GHC.Classes.Eq Text.Glabrous.Types.Result
instance GHC.Show.Show Text.Glabrous.Types.Context
instance GHC.Classes.Eq Text.Glabrous.Types.Context
instance GHC.Generics.Generic Text.Glabrous.Types.Template
instance GHC.Show.Show Text.Glabrous.Types.Template
instance GHC.Classes.Eq Text.Glabrous.Types.Template
instance GHC.Generics.Generic Text.Glabrous.Types.Token
instance GHC.Show.Show Text.Glabrous.Types.Token
instance GHC.Classes.Eq Text.Glabrous.Types.Token
instance Data.Aeson.Types.ToJSON.ToJSON Text.Glabrous.Types.Context
instance Data.Aeson.Types.FromJSON.FromJSON Text.Glabrous.Types.Context
instance Data.Serialize.Serialize Text.Glabrous.Types.Template
instance Data.Serialize.Serialize Text.Glabrous.Types.Token


-- | A minimalistic Mustache-like syntax, truly logic-less, pure
--   <a>Text</a> template library
--   
--   <ul>
--   <li>Use only the simplest Mustache tag {{name}} called a
--   variable.</li>
--   <li>HTML agnostic</li>
--   </ul>
module Text.Glabrous
data Template
Template :: ![Token] -> Template
[content] :: Template -> ![Token]
type Tag = Text

-- | Build a <a>Template</a> from a <a>Text</a>.
--   
--   <pre>
--   λ&gt;fromText "Glabrous templates use only the simplest Mustache tag: {{name}}."
--   Right (Template {content = [Literal "Glabrous templates use only the simplest Mustache tag: ",Tag "name",Literal "."]})
--   </pre>
fromText :: Text -> Either String Template

-- | Get a <a>Template</a> from a file.
readTemplateFile :: FilePath -> IO (Either String Template)

-- | Get the list of <a>Tag</a>s in the given <a>Template</a>.
tagsOf :: Template -> [Tag]
tagsRename :: [(Text, Text)] -> Template -> Template

-- | <a>True</a> if a <a>Template</a> has no more <a>Tag</a> inside and can
--   be used as a final <a>Text</a>.
isFinal :: Template -> Bool

-- | Output the content of the given <a>Template</a> as it is, with its
--   <a>Tag</a>s, if they exist.
toText :: Template -> Text

-- | Output the content of the given <a>Template</a> with all its
--   <a>Tag</a>s removed.
toFinalText :: Template -> Text

-- | Optimize a <a>Template</a> content after (many)
--   <a>partialProcess</a>(') rewriting(s).
compress :: Template -> Template

-- | Write a <a>Template</a> to a file.
writeTemplateFile :: FilePath -> Template -> IO ()
data Context
Context :: !(HashMap Text Text) -> Context
[variables] :: Context -> !(HashMap Text Text)

-- | Build an empty <a>Context</a>.
initContext :: Context

-- | Build an unset <a>Context</a> from a list of <a>Tag</a>s.
--   
--   <pre>
--   λ&gt;fromTagsList ["tag","etc."]
--   Context {variables = fromList [("etc.",""),("tag","")]}
--   </pre>
fromTagsList :: [Text] -> Context

-- | Build a <a>Context</a> from a list of <a>Tag</a>s and replacement
--   <a>Text</a>s.
--   
--   <pre>
--   λ&gt;fromList [("tag","replacement"), ("etc.","...")]
--   Context {variables = fromList [("etc.","..."),("tag","replacement")]}
--   </pre>
fromList :: [(Text, Text)] -> Context

-- | Build an unset ad hoc <a>Context</a> from the given <a>Template</a>.
fromTemplate :: Template -> Context

-- | Populate with variables and/or update variables in the given
--   <a>Context</a>.
--   
--   <pre>
--   λ&gt;setVariables [("tag","replacement"), ("theme","Haskell")] context
--   Context {variables = fromList [("etc.","..."),("theme","Haskell"),("tag","replacement"),("name","")]}
--   </pre>
setVariables :: [(Text, Text)] -> Context -> Context

-- | Delete variables from a <a>Context</a> by these names.
--   
--   <pre>
--   λ&gt;deleteVariables ["tag"] context
--   Context {variables = fromList [("etc.","..."),("theme","Haskell"),("name","")]}
--   </pre>
deleteVariables :: [Text] -> Context -> Context

-- | Get the list of the given <a>Context</a> variables.
variablesOf :: Context -> [Text]

-- | <a>True</a> if the all variables of the given <a>Context</a> are not
--   empty.
isSet :: Context -> Bool

-- | Build <a>Just</a> a (sub)<a>Context</a> made of unset variables of the
--   given context, or <a>Nothing</a>.
--   
--   <pre>
--   λ&gt;unsetContext context
--   Just (Context {variables = fromList [("name","")]})
--   </pre>
unsetContext :: Context -> Maybe Context

-- | Get a <a>Context</a> from a JSON file.
readContextFile :: FilePath -> IO (Maybe Context)

-- | Write a <a>Context</a> to a file.
--   
--   <pre>
--   {
--       "tag": "replacement",
--       "etc.": "..."
--   }
--   </pre>
writeContextFile :: FilePath -> Context -> IO ()

-- | Based on the given <a>Context</a>, write a JSON <a>Context</a> file
--   with all its variables empty.
--   
--   <pre>
--   {
--       "tag": "",
--       "etc.": ""
--   }
--   </pre>
initContextFile :: FilePath -> Context -> IO ()

-- | Process, discard <a>Tag</a>s which are not in the <a>Context</a> and
--   replace them with nothing in the final <a>Text</a>.
process :: Template -> Context -> Text

-- | Process and replace missing variables in <a>Context</a> with the given
--   default replacement <a>Text</a>.
processWithDefault :: Text -> Template -> Context -> Text

-- | Process a (sub)<a>Context</a> present in the given template, leaving
--   untouched, if they exist, other <a>Tag</a>s, to obtain a new template.
partialProcess :: Template -> Context -> Template
data Result
Final :: !Text -> Result
Partial :: !Template -> !Context -> Result
[template] :: Result -> !Template
[context] :: Result -> !Context

-- | Process a (sub)<a>Context</a> present in the given template, and get
--   either a <a>Final</a> <a>Text</a> or a new <a>Template</a> with its
--   unset ad hoc <a>Context</a>.
--   
--   <pre>
--   λ&gt;partialProcess' template context
--   Partial {template = Template {content = [Literal "Some ",Tag "tags",Literal " are unused in this ",Tag "text",Literal "."]}, context = Context {variables = fromList [("text",""),("tags","")]}}
--   </pre>
partialProcess' :: Template -> Context -> Result
