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

-- | Haskell implementation of Mustache templates
--   
--   Haskell implementation of Mustache templates
--   (http://mustache.github.com/).
--   
--   See homepage for examples of usage:
--   http://github.com/lymar/hastache
@package hastache
@version 0.6.1

-- | Haskell implementation of Mustache templates
--   
--   See homepage for examples of usage:
--   http://github.com/lymar/hastache
--   
--   Simplest example:
--   
--   
--   import           Text.Hastache
--   import           Text.Hastache.Context
--   import qualified Data.Text.Lazy.IO as TL
--   
--   main = do 
--       res <- hastacheStr defaultConfig (encodeStr template)  
--           (mkStrContext context) 
--       TL.putStrLn res 
--     where 
--       template = "Hello, {{name}}!\n\nYou have {{unread}} unread messages." 
--       context "name" = MuVariable "Haskell"
--       context "unread" = MuVariable (100 :: Int)
--   
--   
--   Result:
--   
--   
--   Hello, Haskell!
--   
--   You have 100 unread messages.
--   
--   
--   Using Generics:
--   
--   
--   {-# LANGUAGE DeriveDataTypeable, OverloadedStrings #-}
--   
--   import           Text.Hastache
--   import           Text.Hastache.Context
--   import qualified Data.Text.Lazy.IO as TL
--   import           Data.Data
--   
--   data Info = Info {
--       name    :: String,
--       unread  :: Int
--       } deriving (Data, Typeable)
--   
--   main = do
--       res <- hastacheStr defaultConfig template
--           (mkGenericContext inf)
--       TL.putStrLn res
--     where
--       template = "Hello, {{name}}!\n\nYou have {{unread}} unread messages."
--       inf = Info "Haskell" 100
--   
module Text.Hastache

-- | Render Hastache template from Text
hastacheStr :: (MonadIO m) => MuConfig m -> Text -> MuContext m -> m Text

-- | Render Hastache template from file
hastacheFile :: (MonadIO m) => MuConfig m -> FilePath -> MuContext m -> m Text

-- | Render Hastache template from Text
hastacheStrBuilder :: (MonadIO m) => MuConfig m -> Text -> MuContext m -> m Builder

-- | Render Hastache template from file
hastacheFileBuilder :: (MonadIO m) => MuConfig m -> FilePath -> MuContext m -> m Builder

-- | Data for Hastache variable
type MuContext m = Text  Variable name -> m (MuType m)  Value
data MuType m
MuVariable :: a -> MuType m
MuList :: [MuContext m] -> MuType m
MuBool :: Bool -> MuType m
MuLambda :: (Text -> a) -> MuType m
MuLambdaM :: (Text -> m a) -> MuType m
MuNothing :: MuType m
data MuConfig m
MuConfig :: (Text -> Text) -> Maybe FilePath -> Maybe String -> (FilePath -> m (Maybe Text)) -> MuConfig m

-- | Escape function (htmlEscape, emptyEscape etc.)
[muEscapeFunc] :: MuConfig m -> Text -> Text

-- | Directory for search partial templates ({{>
--   templateName}})
[muTemplateFileDir] :: MuConfig m -> Maybe FilePath

-- | Partial template files extension
[muTemplateFileExt] :: MuConfig m -> Maybe String

-- | Template retrieval function. Nothing indicates that the
--   template could not be found.
[muTemplateRead] :: MuConfig m -> FilePath -> m (Maybe Text)
class Show a => MuVar a where isEmpty _ = False

-- | Convert to lazy Text
toLText :: MuVar a => a -> Text

-- | Is empty variable (empty string, zero number etc.)
isEmpty :: MuVar a => a -> Bool

-- | Left-leaning compoistion of contexts. Given contexts c1 and
--   c2, the behaviour of (c1 <> c2) x is
--   following: if c1 x produces MuNothing, then the result
--   is c2 x. Otherwise the result is c1 x. Even if
--   c1 x is MuNothing, the monadic effects of c1
--   are still to take place.
composeCtx :: (Monad m) => MuContext m -> MuContext m -> MuContext m

-- | Escape HTML symbols
htmlEscape :: Text -> Text

-- | No escape
emptyEscape :: Text -> Text

-- | Default config: HTML escape function, current directory as template
--   directory, template file extension not specified
defaultConfig :: MonadIO m => MuConfig m

-- | Convert String to Text
encodeStr :: String -> Text

-- | Convert String to Lazy Text
encodeStrLT :: String -> Text

-- | Convert Text to String
decodeStr :: Text -> String

-- | Convert Lazy Text to String
decodeStrLT :: Text -> String
instance GHC.Base.Monad m => GHC.Base.Monoid (Text.Hastache.MuContext m)
instance Text.Hastache.MuVar Data.Text.Internal.Text
instance Text.Hastache.MuVar Data.Text.Internal.Lazy.Text
instance Text.Hastache.MuVar Data.ByteString.Internal.ByteString
instance Text.Hastache.MuVar Data.ByteString.Lazy.Internal.ByteString
instance Text.Hastache.MuVar GHC.Integer.Type.Integer
instance Text.Hastache.MuVar GHC.Types.Int
instance Text.Hastache.MuVar GHC.Types.Float
instance Text.Hastache.MuVar GHC.Types.Double
instance Text.Hastache.MuVar GHC.Int.Int8
instance Text.Hastache.MuVar GHC.Int.Int16
instance Text.Hastache.MuVar GHC.Int.Int32
instance Text.Hastache.MuVar GHC.Int.Int64
instance Text.Hastache.MuVar GHC.Types.Word
instance Text.Hastache.MuVar GHC.Word.Word8
instance Text.Hastache.MuVar GHC.Word.Word16
instance Text.Hastache.MuVar GHC.Word.Word32
instance Text.Hastache.MuVar GHC.Word.Word64
instance Text.Hastache.MuVar ()
instance Text.Hastache.MuVar Data.Version.Version
instance Text.Hastache.MuVar GHC.Types.Char
instance Text.Hastache.MuVar a => Text.Hastache.MuVar [a]
instance Text.Hastache.MuVar a => Text.Hastache.MuVar (GHC.Base.Maybe a)
instance (Text.Hastache.MuVar a, Text.Hastache.MuVar b) => Text.Hastache.MuVar (Data.Either.Either a b)
instance Text.Hastache.MuVar [GHC.Types.Char]
instance GHC.Show.Show (Text.Hastache.MuType m)

-- | Hastache context helpers
module Text.Hastache.Context

-- | Make Hastache context from String -> MuType function
mkStrContext :: Monad m => (String -> MuType m) -> MuContext m

-- | Make Hastache context from monadic String -> MuType function
mkStrContextM :: Monad m => (String -> m (MuType m)) -> MuContext m

-- | Make Hastache context from Data.Data deriving type
--   
--   Supported field types:
--   
--   
--   
- ()
--   
- String
--   
- Char
--   
- Double
--   
- Float
--   
- Int
--   
- Int8
--   
- Int16
--   
- Int32
--   
- Int64
--   
- Integer
--   
- Word
--   
- Word8
--   
- Word16
--   
- Word32
--   
- Word64
--   
- Data.ByteString.ByteString
--   
- Data.ByteString.Lazy.ByteString
--   
- Data.Text.Text
--   
- Data.Text.Lazy.Text
--   
- Bool
--   
- Version
--   
- Maybe a (where a is a supported datatype)
--   
- Either a b (where a and b are
--   supported datatypes)
--   
- Data.Text.Text -> Data.Text.Text
--   
- Data.Text.Text -> Data.Text.Lazy.Text
--   
- Data.Text.Lazy.Text -> Data.Text.Lazy.Text
--   
- Data.ByteString.ByteString -> Data.ByteString.ByteString
--   
- String -> String
--   
- Data.ByteString.ByteString ->
--   Data.ByteString.Lazy.ByteString
--   
- MonadIO m => Data.Text.Text -> m Data.Text.Text
--   
- MonadIO m => Data.Text.Text -> m Data.Text.Lazy.Text
--   
- MonadIO m => Data.Text.Lazy.Text -> m
--   Data.Text.Lazy.Text
--   
- MonadIO m => Data.ByteString.ByteString -> m
--   Data.ByteString.ByteString
--   
- MonadIO m => String -> m String
--   
- MonadIO m => Data.ByteString.ByteString -> m
--   Data.ByteString.Lazy.ByteString
--   
--   
--   Example:
--   
--   
--   import Text.Hastache 
--   import Text.Hastache.Context
--   import qualified Data.Text as T
--   import qualified Data.Text.Lazy as TL
--   import qualified Data.Text.Lazy.IO as TL
--   import Data.Data 
--   import Data.Generics 
--   import Data.Char
--   
--   data InternalData = InternalData {
--       someField       :: String,
--       anotherField    :: Int
--       } deriving (Data, Typeable, Show)
--   
--   data Example = Example {
--       stringField             :: String,
--       intField                :: Int,
--       dataField               :: InternalData,
--       simpleListField         :: [String],
--       dataListField           :: [InternalData],
--       stringFunc              :: String -> String,
--       textFunc                :: T.Text -> T.Text,
--       monadicStringFunc       :: String -> IO String,
--       monadicTextFunc         :: T.Text -> IO T.Text
--       } deriving (Data, Typeable)
--   
--   example = hastacheStr defaultConfig (encodeStr template) 
--       (mkGenericContext context)
--       where
--       template = unlines [
--           "string: {{stringField}}",
--           "int: {{intField}}",
--           "data: {{dataField.someField}}, {{dataField.anotherField}}",
--           "data: {{#dataField}}{{someField}}, {{anotherField}}{{/dataField}}",
--           "simple list: {{#simpleListField}}{{.}} {{/simpleListField}}",
--           "data list:",
--           "{{#dataListField}}",
--           " * {{someField}}, {{anotherField}}. top level var: {{intField}}",
--           "{{/dataListField}}",
--           "{{#stringFunc}}upper{{/stringFunc}}",
--           "{{#textFunc}}reverse{{/textFunc}}",
--           "{{#monadicStringFunc}}upper (monadic){{/monadicStringFunc}}",
--           "{{#monadicTextFunc}}reverse (monadic){{/monadicTextFunc}}"]
--       context = Example { stringField = "string value", intField = 1, 
--           dataField = InternalData "val" 123, simpleListField = ["a","b","c"],
--           dataListField = [InternalData "aaa" 1, InternalData "bbb" 2],
--           stringFunc = map toUpper,
--           textFunc = T.reverse,
--           monadicStringFunc = return . map toUpper,
--           monadicTextFunc = return . T.reverse }
--   
--   main = example >>= TL.putStrLn
--   
--   
--   Result:
--   
--   
--   string: string value 
--   int: 1 
--   data: val, 123 
--   data: val, 123 
--   simple list: a b c  
--   data list: 
--    * aaa, 1. top level var: 1 
--    * bbb, 2. top level var: 1 
--   UPPER 
--   esrever 
--   UPPER (MONADIC)
--   )cidanom( esrever
--   
--   
--   Hastache also supports datatypes with multiple constructors:
--   
--   
--   data A = A { str :: String }
--          | B { num :: Int }
--   
--   {{#A}}
--   A : {{str}}
--   {{/A}}
--   {{#B}}
--   B : {{num}}
--   {{/B}}
--   
mkGenericContext :: (Monad m, Data a, Typeable m) => a -> MuContext m

-- | Like mkGenericContext, but apply the first function to record
--   field names when constructing the context. The second function is used
--   to constructing values for context from datatypes that are nor
--   supported as primitives in the library. The resulting value can be
--   accessed using the .DatatypeName field:
--   
--   
--   {-# LANGUAGE DeriveDataTypeable #-}
--   {-# LANGUAGE FlexibleInstances #-}
--   {-# LANGUAGE ScopedTypeVariables #-}
--   {-# LANGUAGE StandaloneDeriving #-}
--   {-# LANGUAGE TypeSynonymInstances #-}
--   import Text.Hastache 
--   import Text.Hastache.Context 
--   
--   import qualified Data.Text.Lazy as TL 
--   import qualified Data.Text.Lazy.IO as TL 
--   
--   import Data.Data (Data, Typeable)
--   import Data.Decimal
--   import Data.Generics.Aliases (extQ)
--   
--   data Test = Test {n::Int, m::Decimal} deriving (Data, Typeable)
--   deriving instance Data Decimal
--   
--   val :: Test
--   val = Test 1 (Decimal 3 1500)
--   
--   q :: Ext
--   q = defaultExt `extQ` ((i::Decimal) -> "A decimal: " ++ show i)
--   
--   r "m" = "moo"
--   r x   = x
--   
--   example :: IO TL.Text
--   example = hastacheStr defaultConfig
--                         (encodeStr template)
--                         (mkGenericContext' r q val)
--   
--   template = concat [ 
--        "{{n}}\n",
--        "{{moo.Decimal}}"
--        ] 
--   
--   main = example >>= TL.putStrLn
--   
--   
--   Result:
--   
--   
--   1
--   A decimal: 1.500
--   
mkGenericContext' :: (Monad m, Data a, Typeable m) => (String -> String) -> Ext -> a -> MuContext m
type Ext = forall b. (Data b, Typeable b) => b -> String

-- | defaultExt == gshow
defaultExt :: Ext
instance GHC.Show.Show (Text.Hastache.Context.TD m)
