    {-# LANGUAGE GeneralizedNewtypeDeriving #-}
    {-# LANGUAGE OverloadedStrings          #-}
    {-# LANGUAGE MultiParamTypeClasses      #-}
    {-# LANGUAGE NoMonomorphismRestriction  #-}
    {-# LANGUAGE FlexibleInstances          #-}
    {-# LANGUAGE FlexibleContexts           #-}
    {-# LANGUAGE FunctionalDependencies     #-}
    {-# LANGUAGE TypeSynonymInstances       #-}

    {-|

    This module implements the Heist snaplet without using type classes.  It is
    provided mainly as an example of how snaplets can be written with and without
    a type class for convenience.

    -}
    module Snap.Snaplet.HeistNoClass
      ( Heist
      , DefaultMode(..)
      , heistInit
      , heistInit'
      , heistReloader
      , setInterpreted
      , getCurHeistConfig
      , clearHeistCache

      , addTemplates
      , addTemplatesAt
      , getHeistState
      , modifyHeistState
      , modifyHeistState'
      , withHeistState
      , withHeistState'

      , gRender
      , gRenderAs
      , gHeistServe
      , gHeistServeSingle
      , chooseMode

      , addConfig
      , cRender
      , cRenderAs
      , cHeistServe
      , cHeistServeSingle

      , render
      , renderAs
      , heistServe
      , heistServeSingle
      , heistLocal
      , withSplices
      , renderWithSplices
      , heistLocal'
      , withSplices'
      , renderWithSplices'

      , SnapletHeist
      , SnapletISplice
      , SnapletCSplice
      ) where

    import           Prelude hiding ((.), id)
    import           Control.Applicative
    import           Control.Category
    import           Control.Lens
    import           Control.Monad.Reader
    import           Control.Monad.State
    import           Data.ByteString (ByteString)
    import qualified Data.ByteString.Char8 as B
    import           Data.DList (DList)
    import qualified Data.HashMap.Strict as Map
    import           Data.IORef
    import           Data.Maybe
    import qualified Data.Text as T
    import           Data.Text.Encoding
    import           System.FilePath.Posix
    import           Heist
    import qualified Heist.Compiled as C
    import qualified Heist.Interpreted as I
    import           Heist.Splices.Cache

    #if !MIN_VERSION_base(4,8,0)
    import           Data.Monoid
    #endif

    import           Snap.Snaplet
    import           Snap.Snaplet.Heist.Internal
    import           Snap.Core
    import           Snap.Util.FileServe

    ------------------------------------------------------------------------------
    changeState :: (HeistState (Handler a a) -> HeistState (Handler a a))
                -> Heist a
                -> Heist a
    changeState :: (HeistState (Handler a a) -> HeistState (Handler a a))
    -> Heist a -> Heist a
    changeState _ (Configuring _)  =
        [Char] -> Heist a
    forall a. HasCallStack => [Char] -> a
    error "changeState: HeistState has not been initialized"
    changeState f :: HeistState (Handler a a) -> HeistState (Handler a a)
    f (Running hc :: HeistConfig (Handler a a)
    hc hs :: HeistState (Handler a a)
    hs cts :: CacheTagState
    cts dm :: DefaultMode
    dm) = HeistConfig (Handler a a)
    -> HeistState (Handler a a)
    -> CacheTagState
    -> DefaultMode
    -> Heist a
    forall b.
    HeistConfig (Handler b b)
    -> HeistState (Handler b b)
    -> CacheTagState
    -> DefaultMode
    -> Heist b
    Running HeistConfig (Handler a a)
    hc (HeistState (Handler a a) -> HeistState (Handler a a)
    f HeistState (Handler a a)
    hs) CacheTagState
    cts DefaultMode
    dm

    ------------------------------------------------------------------------------
    -- | Clears data stored by the cache tag.  The cache tag automatically reloads
    -- its data when the specified TTL expires, but sometimes you may want to
    -- trigger a manual reload.  This function lets you do that.
    clearHeistCache :: Heist b -> IO ()
    clearHeistCache :: Heist b -> IO ()
    clearHeistCache = CacheTagState -> IO ()
    clearCacheTagState (CacheTagState -> IO ())
    -> (Heist b -> CacheTagState) -> Heist b -> IO ()
    forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
    Category cat =>
    cat b c -> cat a b -> cat a c
    . Heist b -> CacheTagState
    forall b. Heist b -> CacheTagState
    _heistCTS

                             -----------------------------
                             -- SnapletSplice functions --
                             -----------------------------

    ------------------------------------------------------------------------------
    -- | This instance is here because we don't want the heist package to depend
    -- on anything from snap packages.
    instance MonadSnap m => MonadSnap (HeistT n m) where
        liftSnap :: Snap a -> HeistT n m a
    liftSnap = m a -> HeistT n m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m a -> HeistT n m a) -> (Snap a -> m a) -> Snap a -> HeistT n m a
    forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
    Category cat =>
    cat b c -> cat a b -> cat a c
    . Snap a -> m a
    forall (m :: * -> *) a. MonadSnap m => Snap a -> m a
    liftSnap

    type SnapletHeist b m a = HeistT (Handler b b) m a
    type SnapletCSplice b = SnapletHeist b IO (DList (Chunk (Handler b b)))
    type SnapletISplice b = SnapletHeist b (Handler b b) Template

                              ---------------------------
                              -- Initializer functions --
                              ---------------------------

    ------------------------------------------------------------------------------
    -- | The 'Initializer' for 'Heist'. This function is a convenience wrapper
    -- around `heistInit'` that uses defaultHeistState and sets up routes for all
    -- the templates.  It sets up a \"heistReload\" route that reloads the heist
    -- templates when you request it from localhost.
    heistInit :: FilePath
                  -- ^ Path to templates
              -> SnapletInit b (Heist b)
    heistInit :: [Char] -> SnapletInit b (Heist b)
    heistInit = Handler b (Heist b) () -> [Char] -> SnapletInit b (Heist b)
    forall b.
    Handler b (Heist b) () -> [Char] -> SnapletInit b (Heist b)
    gHeistInit Handler b (Heist b) ()
    forall b. Handler b (Heist b) ()
    heistServe

    ------------------------------------------------------------------------------
    -- | A lower level 'Initializer' for 'Heist'.  This initializer requires you
    -- to specify the initial HeistConfig.  It also does not add any routes for
    -- templates, allowing you complete control over which templates get routed.
    heistInit' :: FilePath
                   -- ^ Path to templates
               -> HeistConfig (Handler b b)
                   -- ^ Initial HeistConfig
               -> SnapletInit b (Heist b)
    heistInit' :: [Char] -> HeistConfig (Handler b b) -> SnapletInit b (Heist b)
    heistInit' templateDir :: [Char]
    templateDir initialConfig :: HeistConfig (Handler b b)
    initialConfig =
        Text
    -> Text
    -> Maybe (IO [Char])
    -> Initializer b (Heist b) (Heist b)
    -> SnapletInit b (Heist b)
    forall b v.
    Text
    -> Text
    -> Maybe (IO [Char])
    -> Initializer b v v
    -> SnapletInit b v
    makeSnaplet "heist" "" Maybe (IO [Char])
    forall a. Maybe a
    Nothing (Initializer b (Heist b) (Heist b) -> SnapletInit b (Heist b))
    -> Initializer b (Heist b) (Heist b) -> SnapletInit b (Heist b)
    forall a b. (a -> b) -> a -> b
    $ [Char]
    -> HeistConfig (Handler b b) -> Initializer b (Heist b) (Heist b)
    forall b.
    [Char]
    -> HeistConfig (Handler b b) -> Initializer b (Heist b) (Heist b)
    heistInitWorker [Char]
    templateDir HeistConfig (Handler b b)
    initialConfig

    ------------------------------------------------------------------------------
    -- | Sets the snaplet to default to interpreted mode.  Initially, the
    -- initializer sets the value to compiled mode.  This function allows you to
    -- override that setting.  Note that this is just a default.  It only has an
    -- effect if you use one of the generic functions: 'gRender', 'gRenderAs',
    -- 'gHeistServe', or 'gHeistServeSingle'.  If you call the non-generic
    -- versions directly, then this value will not be checked and you will get the
    -- mode implemented by the function you called.
    setInterpreted :: Snaplet (Heist b) -> Initializer b v ()
    setInterpreted :: Snaplet (Heist b) -> Initializer b v ()
    setInterpreted h :: Snaplet (Heist b)
    h =
        IO () -> Initializer b v ()
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO () -> Initializer b v ()) -> IO () -> Initializer b v ()
    forall a b. (a -> b) -> a -> b
    $ IORef (HeistConfig (Handler b b), DefaultMode)
    -> ((HeistConfig (Handler b b), DefaultMode)
        -> ((HeistConfig (Handler b b), DefaultMode), ()))
    -> IO ()
    forall a b. IORef a -> (a -> (a, b)) -> IO b
    atomicModifyIORef (Heist b -> IORef (HeistConfig (Handler b b), DefaultMode)
    forall b. Heist b -> IORef (HeistConfig (Handler b b), DefaultMode)
    _heistConfig (Heist b -> IORef (HeistConfig (Handler b b), DefaultMode))
    -> Heist b -> IORef (HeistConfig (Handler b b), DefaultMode)
    forall a b. (a -> b) -> a -> b
    $ Getting (Heist b) (Snaplet (Heist b)) (Heist b)
    -> Snaplet (Heist b) -> Heist b
    forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
    view Getting (Heist b) (Snaplet (Heist b)) (Heist b)
    forall s. Lens' (Snaplet s) s
    snapletValue Snaplet (Heist b)
    h)
            (\(hc :: HeistConfig (Handler b b)
    hc,_) -> ((HeistConfig (Handler b b)
    hc,DefaultMode
    Interpreted),()))

    ------------------------------------------------------------------------------
    -- | Adds templates to the Heist HeistConfig.  Other snaplets should use
    -- this function to add their own templates.  The templates are automatically
    -- read from the templates directory in the current snaplet's filesystem root.
    addTemplates :: Snaplet (Heist b)
                 -> ByteString
                     -- ^ The url prefix for the template routes
                 -> Initializer b (Heist b) ()
    addTemplates :: Snaplet (Heist b) -> ByteString -> Initializer b (Heist b) ()
    addTemplates h :: Snaplet (Heist b)
    h urlPrefix :: ByteString
    urlPrefix = do
        [Char]
    snapletPath <- Initializer b (Heist b) [Char]
    forall (m :: * -> * -> * -> *) b v.
    (Monad (m b v), MonadSnaplet m) =>
    m b v [Char]
    getSnapletFilePath
        Snaplet (Heist b)
    -> ByteString -> [Char] -> Initializer b (Heist b) ()
    forall b.
    Snaplet (Heist b)
    -> ByteString -> [Char] -> Initializer b (Heist b) ()
    addTemplatesAt Snaplet (Heist b)
    h ByteString
    urlPrefix ([Char]
    snapletPath [Char] -> [Char] -> [Char]
    </> "templates")

    ------------------------------------------------------------------------------
    -- | Adds templates to the Heist HeistConfig, and lets you specify where
    -- they are found in the filesystem.  Note that the path to the template
    -- directory is an absolute path.  This allows you more flexibility in where
    -- your templates are located, but means that you have to explicitly call
    -- getSnapletFilePath if you want your snaplet to use templates within its
    -- normal directory structure.
    addTemplatesAt :: Snaplet (Heist b)
                   -> ByteString
                       -- ^ URL prefix for template routes
                   -> FilePath
                       -- ^ Path to templates
                   -> Initializer b (Heist b) ()
    addTemplatesAt :: Snaplet (Heist b)
    -> ByteString -> [Char] -> Initializer b (Heist b) ()
    addTemplatesAt h :: Snaplet (Heist b)
    h urlPrefix :: ByteString
    urlPrefix templateDir :: [Char]
    templateDir = do
        ByteString
    rootUrl <- Initializer b (Heist b) ByteString
    forall (m :: * -> * -> * -> *) b v.
    (Monad (m b v), MonadSnaplet m) =>
    m b v ByteString
    getSnapletRootURL
        let fullPrefix :: [Char]
    fullPrefix = (Text -> [Char]
    T.unpack (Text -> [Char]) -> Text -> [Char]
    forall a b. (a -> b) -> a -> b
    $ ByteString -> Text
    decodeUtf8 ByteString
    rootUrl) [Char] -> [Char] -> [Char]
    </>
                         (Text -> [Char]
    T.unpack (Text -> [Char]) -> Text -> [Char]
    forall a b. (a -> b) -> a -> b
    $ ByteString -> Text
    decodeUtf8 ByteString
    urlPrefix)
            addPrefix :: TemplateRepo -> TemplateRepo
    addPrefix = ByteString -> TemplateRepo -> TemplateRepo
    addTemplatePathPrefix
                          (Text -> ByteString
    encodeUtf8 (Text -> ByteString) -> Text -> ByteString
    forall a b. (a -> b) -> a -> b
    $ [Char] -> Text
    T.pack [Char]
    fullPrefix)
        TemplateRepo
    ts <- IO TemplateRepo -> Initializer b (Heist b) TemplateRepo
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO TemplateRepo -> Initializer b (Heist b) TemplateRepo)
    -> IO TemplateRepo -> Initializer b (Heist b) TemplateRepo
    forall a b. (a -> b) -> a -> b
    $ ([Char] -> IO (Either [[Char]] TemplateRepo)
    loadTemplates [Char]
    templateDir) IO (Either [[Char]] TemplateRepo)
    -> (Either [[Char]] TemplateRepo -> IO TemplateRepo)
    -> IO TemplateRepo
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>=
                       ([[Char]] -> IO TemplateRepo)
    -> (TemplateRepo -> IO TemplateRepo)
    -> Either [[Char]] TemplateRepo
    -> IO TemplateRepo
    forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
    either ([Char] -> IO TemplateRepo
    forall a. HasCallStack => [Char] -> a
    error ([Char] -> IO TemplateRepo)
    -> ([[Char]] -> [Char]) -> [[Char]] -> IO TemplateRepo
    forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
    Category cat =>
    cat b c -> cat a b -> cat a c
    . [[Char]] -> [Char]
    forall (t :: * -> *) a. Foldable t => t [a] -> [a]
    concat) TemplateRepo -> IO TemplateRepo
    forall (m :: * -> *) a. Monad m => a -> m a
    return
        Text -> Initializer b (Heist b) ()
    forall b v. Text -> Initializer b v ()
    printInfo (Text -> Initializer b (Heist b) ())
    -> Text -> Initializer b (Heist b) ()
    forall a b. (a -> b) -> a -> b
    $ [Char] -> Text
    T.pack ([Char] -> Text) -> [Char] -> Text
    forall a b. (a -> b) -> a -> b
    $ [[Char]] -> [Char]
    unwords
            [ "...adding"
            , (Int -> [Char]
    forall a. Show a => a -> [Char]
    show (Int -> [Char]) -> Int -> [Char]
    forall a b. (a -> b) -> a -> b
    $ TemplateRepo -> Int
    forall k v. HashMap k v -> Int
    Map.size TemplateRepo
    ts)
            , "templates from"
            , [Char]
    templateDir
            , "with route prefix"
            , [Char]
    fullPrefix [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ "/"
            ]
        let locations :: [IO (Either [[Char]] TemplateRepo)]
    locations = [(TemplateRepo -> TemplateRepo)
    -> Either [[Char]] TemplateRepo -> Either [[Char]] TemplateRepo
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap TemplateRepo -> TemplateRepo
    addPrefix (Either [[Char]] TemplateRepo -> Either [[Char]] TemplateRepo)
    -> IO (Either [[Char]] TemplateRepo)
    -> IO (Either [[Char]] TemplateRepo)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [Char] -> IO (Either [[Char]] TemplateRepo)
    loadTemplates [Char]
    templateDir]
            add :: (HeistConfig (Handler b b), DefaultMode)
    -> ((HeistConfig (Handler b b), DefaultMode), ())
    add (hc :: HeistConfig (Handler b b)
    hc, dm :: DefaultMode
    dm) =
              ((ASetter
      (HeistConfig (Handler b b))
      (HeistConfig (Handler b b))
      [IO (Either [[Char]] TemplateRepo)]
      [IO (Either [[Char]] TemplateRepo)]
    -> ([IO (Either [[Char]] TemplateRepo)]
        -> [IO (Either [[Char]] TemplateRepo)])
    -> HeistConfig (Handler b b)
    -> HeistConfig (Handler b b)
    forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
    over ASetter
      (HeistConfig (Handler b b))
      (HeistConfig (Handler b b))
      [IO (Either [[Char]] TemplateRepo)]
      [IO (Either [[Char]] TemplateRepo)]
    forall (f :: * -> *) (m :: * -> *).
    Functor f =>
    ([IO (Either [[Char]] TemplateRepo)]
     -> f [IO (Either [[Char]] TemplateRepo)])
    -> HeistConfig m -> f (HeistConfig m)
    hcTemplateLocations ([IO (Either [[Char]] TemplateRepo)]
    -> [IO (Either [[Char]] TemplateRepo)]
    -> [IO (Either [[Char]] TemplateRepo)]
    forall a. Monoid a => a -> a -> a
    mappend [IO (Either [[Char]] TemplateRepo)]
    locations) HeistConfig (Handler b b)
    hc, DefaultMode
    dm), ())
        IO () -> Initializer b (Heist b) ()
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO () -> Initializer b (Heist b) ())
    -> IO () -> Initializer b (Heist b) ()
    forall a b. (a -> b) -> a -> b
    $ IORef (HeistConfig (Handler b b), DefaultMode)
    -> ((HeistConfig (Handler b b), DefaultMode)
        -> ((HeistConfig (Handler b b), DefaultMode), ()))
    -> IO ()
    forall a b. IORef a -> (a -> (a, b)) -> IO b
    atomicModifyIORef (Heist b -> IORef (HeistConfig (Handler b b), DefaultMode)
    forall b. Heist b -> IORef (HeistConfig (Handler b b), DefaultMode)
    _heistConfig (Heist b -> IORef (HeistConfig (Handler b b), DefaultMode))
    -> Heist b -> IORef (HeistConfig (Handler b b), DefaultMode)
    forall a b. (a -> b) -> a -> b
    $ Getting (Heist b) (Snaplet (Heist b)) (Heist b)
    -> Snaplet (Heist b) -> Heist b
    forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
    view Getting (Heist b) (Snaplet (Heist b)) (Heist b)
    forall s. Lens' (Snaplet s) s
    snapletValue Snaplet (Heist b)
    h) (HeistConfig (Handler b b), DefaultMode)
    -> ((HeistConfig (Handler b b), DefaultMode), ())
    add

    getCurHeistConfig :: Snaplet (Heist b)
                      -> Initializer b v (HeistConfig (Handler b b))
    getCurHeistConfig :: Snaplet (Heist b) -> Initializer b v (HeistConfig (Handler b b))
    getCurHeistConfig h :: Snaplet (Heist b)
    h = case Getting (Heist b) (Snaplet (Heist b)) (Heist b)
    -> Snaplet (Heist b) -> Heist b
    forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
    view Getting (Heist b) (Snaplet (Heist b)) (Heist b)
    forall s. Lens' (Snaplet s) s
    snapletValue Snaplet (Heist b)
    h of
        Configuring ref :: IORef (HeistConfig (Handler b b), DefaultMode)
    ref -> do
            (hc :: HeistConfig (Handler b b)
    hc, _) <- IO (HeistConfig (Handler b b), DefaultMode)
    -> Initializer b v (HeistConfig (Handler b b), DefaultMode)
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO (HeistConfig (Handler b b), DefaultMode)
     -> Initializer b v (HeistConfig (Handler b b), DefaultMode))
    -> IO (HeistConfig (Handler b b), DefaultMode)
    -> Initializer b v (HeistConfig (Handler b b), DefaultMode)
    forall a b. (a -> b) -> a -> b
    $ IORef (HeistConfig (Handler b b), DefaultMode)
    -> IO (HeistConfig (Handler b b), DefaultMode)
    forall a. IORef a -> IO a
    readIORef IORef (HeistConfig (Handler b b), DefaultMode)
    ref
            HeistConfig (Handler b b)
    -> Initializer b v (HeistConfig (Handler b b))
    forall (m :: * -> *) a. Monad m => a -> m a
    return HeistConfig (Handler b b)
    hc
        Running _ _ _ _ ->
            [Char] -> Initializer b v (HeistConfig (Handler b b))
    forall a. HasCallStack => [Char] -> a
    error "Can't get HeistConfig after heist is initialized."

    ------------------------------------------------------------------------------
    getHeistState :: SnapletLens (Snaplet b) (Heist b)
                  -> Handler b v (HeistState (Handler b b))
    getHeistState :: SnapletLens (Snaplet b) (Heist b)
    -> Handler b v (HeistState (Handler b b))
    getHeistState heist :: SnapletLens (Snaplet b) (Heist b)
    heist = SnapletLens (Snaplet b) (Heist b)
    -> Handler b (Heist b) (HeistState (Handler b b))
    -> Handler b v (HeistState (Handler b b))
    forall (m :: * -> * -> * -> *) b v' a v.
    MonadSnaplet m =>
    SnapletLens (Snaplet b) v' -> m b v' a -> m b v a
    withTop' SnapletLens (Snaplet b) (Heist b)
    heist (Handler b (Heist b) (HeistState (Handler b b))
     -> Handler b v (HeistState (Handler b b)))
    -> Handler b (Heist b) (HeistState (Handler b b))
    -> Handler b v (HeistState (Handler b b))
    forall a b. (a -> b) -> a -> b
    $ (Heist b -> HeistState (Handler b b))
    -> Handler b (Heist b) (HeistState (Handler b b))
    forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
    gets Heist b -> HeistState (Handler b b)
    forall b. Heist b -> HeistState (Handler b b)
    _heistState

    ------------------------------------------------------------------------------
    modifyHeistState' :: SnapletLens (Snaplet b) (Heist b)
                      -> (HeistState (Handler b b) -> HeistState (Handler b b))
                      -> Initializer b v ()
    modifyHeistState' :: SnapletLens (Snaplet b) (Heist b)
    -> (HeistState (Handler b b) -> HeistState (Handler b b))
    -> Initializer b v ()
    modifyHeistState' heist :: SnapletLens (Snaplet b) (Heist b)
    heist f :: HeistState (Handler b b) -> HeistState (Handler b b)
    f = do
        SnapletLens (Snaplet b) (Heist b)
    -> Initializer b (Heist b) () -> Initializer b v ()
    forall (m :: * -> * -> * -> *) b v' a v.
    MonadSnaplet m =>
    SnapletLens (Snaplet b) v' -> m b v' a -> m b v a
    withTop' SnapletLens (Snaplet b) (Heist b)
    heist (Initializer b (Heist b) () -> Initializer b v ())
    -> Initializer b (Heist b) () -> Initializer b v ()
    forall a b. (a -> b) -> a -> b
    $ (Heist b -> IO (Either Text (Heist b)))
    -> Initializer b (Heist b) ()
    forall v b. (v -> IO (Either Text v)) -> Initializer b v ()
    addPostInitHook ((Heist b -> IO (Either Text (Heist b)))
     -> Initializer b (Heist b) ())
    -> (Heist b -> IO (Either Text (Heist b)))
    -> Initializer b (Heist b) ()
    forall a b. (a -> b) -> a -> b
    $ Either Text (Heist b) -> IO (Either Text (Heist b))
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Either Text (Heist b) -> IO (Either Text (Heist b)))
    -> (Heist b -> Either Text (Heist b))
    -> Heist b
    -> IO (Either Text (Heist b))
    forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
    Category cat =>
    cat b c -> cat a b -> cat a c
    . Heist b -> Either Text (Heist b)
    forall a b. b -> Either a b
    Right (Heist b -> Either Text (Heist b))
    -> (Heist b -> Heist b) -> Heist b -> Either Text (Heist b)
    forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
    Category cat =>
    cat b c -> cat a b -> cat a c
    . (HeistState (Handler b b) -> HeistState (Handler b b))
    -> Heist b -> Heist b
    forall a.
    (HeistState (Handler a a) -> HeistState (Handler a a))
    -> Heist a -> Heist a
    changeState HeistState (Handler b b) -> HeistState (Handler b b)
    f

    ------------------------------------------------------------------------------
    modifyHeistState :: SnapletLens b (Heist b)
                     -> (HeistState (Handler b b) -> HeistState (Handler b b))
                     -> Initializer b v ()
    modifyHeistState :: SnapletLens b (Heist b)
    -> (HeistState (Handler b b) -> HeistState (Handler b b))
    -> Initializer b v ()
    modifyHeistState heist :: SnapletLens b (Heist b)
    heist f :: HeistState (Handler b b) -> HeistState (Handler b b)
    f = SnapletLens (Snaplet b) (Heist b)
    -> (HeistState (Handler b b) -> HeistState (Handler b b))
    -> Initializer b v ()
    forall b v.
    SnapletLens (Snaplet b) (Heist b)
    -> (HeistState (Handler b b) -> HeistState (Handler b b))
    -> Initializer b v ()
    modifyHeistState' (SnapletLens b (Heist b) -> SnapletLens (Snaplet b) (Heist b)
    forall a b. SnapletLens a b -> SnapletLens (Snaplet a) b
    subSnaplet SnapletLens b (Heist b)
    heist) HeistState (Handler b b) -> HeistState (Handler b b)
    f

    ------------------------------------------------------------------------------
    withHeistState' :: SnapletLens (Snaplet b) (Heist b)
                    -> (HeistState (Handler b b) -> a)
                    -> Handler b v a
    withHeistState' :: SnapletLens (Snaplet b) (Heist b)
    -> (HeistState (Handler b b) -> a) -> Handler b v a
    withHeistState' heist :: SnapletLens (Snaplet b) (Heist b)
    heist f :: HeistState (Handler b b) -> a
    f = do
        HeistState (Handler b b)
    hs <- SnapletLens (Snaplet b) (Heist b)
    -> Handler b (Heist b) (HeistState (Handler b b))
    -> Handler b v (HeistState (Handler b b))
    forall (m :: * -> * -> * -> *) b v' a v.
    MonadSnaplet m =>
    SnapletLens (Snaplet b) v' -> m b v' a -> m b v a
    withTop' SnapletLens (Snaplet b) (Heist b)
    heist (Handler b (Heist b) (HeistState (Handler b b))
     -> Handler b v (HeistState (Handler b b)))
    -> Handler b (Heist b) (HeistState (Handler b b))
    -> Handler b v (HeistState (Handler b b))
    forall a b. (a -> b) -> a -> b
    $ (Heist b -> HeistState (Handler b b))
    -> Handler b (Heist b) (HeistState (Handler b b))
    forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
    gets Heist b -> HeistState (Handler b b)
    forall b. Heist b -> HeistState (Handler b b)
    _heistState
        a -> Handler b v a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (a -> Handler b v a) -> a -> Handler b v a
    forall a b. (a -> b) -> a -> b
    $ HeistState (Handler b b) -> a
    f HeistState (Handler b b)
    hs

    ------------------------------------------------------------------------------
    withHeistState :: SnapletLens b (Heist b)
                   -> (HeistState (Handler b b) -> a)
                   -> Handler b v a
    withHeistState :: SnapletLens b (Heist b)
    -> (HeistState (Handler b b) -> a) -> Handler b v a
    withHeistState heist :: SnapletLens b (Heist b)
    heist f :: HeistState (Handler b b) -> a
    f = SnapletLens (Snaplet b) (Heist b)
    -> (HeistState (Handler b b) -> a) -> Handler b v a
    forall b a v.
    SnapletLens (Snaplet b) (Heist b)
    -> (HeistState (Handler b b) -> a) -> Handler b v a
    withHeistState' (SnapletLens b (Heist b) -> SnapletLens (Snaplet b) (Heist b)
    forall a b. SnapletLens a b -> SnapletLens (Snaplet a) b
    subSnaplet SnapletLens b (Heist b)
    heist) HeistState (Handler b b) -> a
    f

    ------------------------------------------------------------------------------
    -- | Adds more HeistConfig data using mappend with whatever is currently
    -- there.  This is the preferred method for adding all four kinds of splices
    -- as well as new templates.
    addConfig :: Snaplet (Heist b)
              -> SpliceConfig (Handler b b)
              -> Initializer b v ()
    addConfig :: Snaplet (Heist b)
    -> SpliceConfig (Handler b b) -> Initializer b v ()
    addConfig h :: Snaplet (Heist b)
    h sc :: SpliceConfig (Handler b b)
    sc = case Getting (Heist b) (Snaplet (Heist b)) (Heist b)
    -> Snaplet (Heist b) -> Heist b
    forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
    view Getting (Heist b) (Snaplet (Heist b)) (Heist b)
    forall s. Lens' (Snaplet s) s
    snapletValue Snaplet (Heist b)
    h of
        Configuring ref :: IORef (HeistConfig (Handler b b), DefaultMode)
    ref ->
            IO () -> Initializer b v ()
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO () -> Initializer b v ()) -> IO () -> Initializer b v ()
    forall a b. (a -> b) -> a -> b
    $ IORef (HeistConfig (Handler b b), DefaultMode)
    -> ((HeistConfig (Handler b b), DefaultMode)
        -> ((HeistConfig (Handler b b), DefaultMode), ()))
    -> IO ()
    forall a b. IORef a -> (a -> (a, b)) -> IO b
    atomicModifyIORef IORef (HeistConfig (Handler b b), DefaultMode)
    ref (HeistConfig (Handler b b), DefaultMode)
    -> ((HeistConfig (Handler b b), DefaultMode), ())
    add
        Running _ _ _ _ -> do
            Text -> Initializer b v ()
    forall b v. Text -> Initializer b v ()
    printInfo "finalLoadHook called while running"
            [Char] -> Initializer b v ()
    forall a. HasCallStack => [Char] -> a
    error "this shouldn't happen"
      where
        add :: (HeistConfig (Handler b b), DefaultMode)
    -> ((HeistConfig (Handler b b), DefaultMode), ())
    add (hc :: HeistConfig (Handler b b)
    hc, dm :: DefaultMode
    dm) =
          ((ASetter
      (HeistConfig (Handler b b))
      (HeistConfig (Handler b b))
      (SpliceConfig (Handler b b))
      (SpliceConfig (Handler b b))
    -> (SpliceConfig (Handler b b) -> SpliceConfig (Handler b b))
    -> HeistConfig (Handler b b)
    -> HeistConfig (Handler b b)
    forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
    over ASetter
      (HeistConfig (Handler b b))
      (HeistConfig (Handler b b))
      (SpliceConfig (Handler b b))
      (SpliceConfig (Handler b b))
    forall (f :: * -> *) (m :: * -> *).
    Functor f =>
    (SpliceConfig m -> f (SpliceConfig m))
    -> HeistConfig m -> f (HeistConfig m)
    hcSpliceConfig (SpliceConfig (Handler b b)
    -> SpliceConfig (Handler b b) -> SpliceConfig (Handler b b)
    forall a. Monoid a => a -> a -> a
    `mappend` SpliceConfig (Handler b b)
    sc) HeistConfig (Handler b b)
    hc, DefaultMode
    dm), ())

                                -----------------------
                                -- Handler functions --
                                -----------------------

    ------------------------------------------------------------------------------
    -- | Internal helper function for rendering.
    iRenderHelper :: Maybe MIMEType
                 -> ByteString
                 -> Handler b (Heist b) ()
    iRenderHelper :: Maybe ByteString -> ByteString -> Handler b (Heist b) ()
    iRenderHelper c :: Maybe ByteString
    c t :: ByteString
    t = do
        (Running _ hs :: HeistState (Handler b b)
    hs _ _) <- Handler b (Heist b) (Heist b)
    forall s (m :: * -> *). MonadState s m => m s
    get
        SnapletLens (Snaplet b) b
    -> Handler b b () -> Handler b (Heist b) ()
    forall (m :: * -> * -> * -> *) b v' a v.
    MonadSnaplet m =>
    SnapletLens (Snaplet b) v' -> m b v' a -> m b v a
    withTop' SnapletLens (Snaplet b) b
    forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
    id (Handler b b () -> Handler b (Heist b) ())
    -> Handler b b () -> Handler b (Heist b) ()
    forall a b. (a -> b) -> a -> b
    $ HeistState (Handler b b)
    -> ByteString -> Handler b b (Maybe (Builder, ByteString))
    forall (n :: * -> *).
    Monad n =>
    HeistState n -> ByteString -> n (Maybe (Builder, ByteString))
    I.renderTemplate HeistState (Handler b b)
    hs ByteString
    t Handler b b (Maybe (Builder, ByteString))
    -> (Maybe (Builder, ByteString) -> Handler b b ())
    -> Handler b b ()
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Handler b b ()
    -> ((Builder, ByteString) -> Handler b b ())
    -> Maybe (Builder, ByteString)
    -> Handler b b ()
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe Handler b b ()
    forall (m :: * -> *) a. MonadSnap m => m a
    pass (Builder, ByteString) -> Handler b b ()
    serve
      where
        serve :: (Builder, ByteString) -> Handler b b ()
    serve (b :: Builder
    b, mime :: ByteString
    mime) = do
            (Response -> Response) -> Handler b b ()
    forall (m :: * -> *). MonadSnap m => (Response -> Response) -> m ()
    modifyResponse ((Response -> Response) -> Handler b b ())
    -> (Response -> Response) -> Handler b b ()
    forall a b. (a -> b) -> a -> b
    $ ByteString -> Response -> Response
    setContentType (ByteString -> Response -> Response)
    -> ByteString -> Response -> Response
    forall a b. (a -> b) -> a -> b
    $ ByteString -> Maybe ByteString -> ByteString
    forall a. a -> Maybe a -> a
    fromMaybe ByteString
    mime Maybe ByteString
    c
            Builder -> Handler b b ()
    forall (m :: * -> *). MonadSnap m => Builder -> m ()
    writeBuilder Builder
    b

    ------------------------------------------------------------------------------
    -- | Internal helper function for rendering.
    cRenderHelper :: Maybe MIMEType
                  -> ByteString
                  -> Handler b (Heist b) ()
    cRenderHelper :: Maybe ByteString -> ByteString -> Handler b (Heist b) ()
    cRenderHelper c :: Maybe ByteString
    c t :: ByteString
    t = do
        (Running _ hs :: HeistState (Handler b b)
    hs _ _) <- Handler b (Heist b) (Heist b)
    forall s (m :: * -> *). MonadState s m => m s
    get
        SnapletLens (Snaplet b) b
    -> Handler b b () -> Handler b (Heist b) ()
    forall (m :: * -> * -> * -> *) b v' a v.
    MonadSnaplet m =>
    SnapletLens (Snaplet b) v' -> m b v' a -> m b v a
    withTop' SnapletLens (Snaplet b) b
    forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
    id (Handler b b () -> Handler b (Heist b) ())
    -> Handler b b () -> Handler b (Heist b) ()
    forall a b. (a -> b) -> a -> b
    $ Handler b b ()
    -> ((Handler b b Builder, ByteString) -> Handler b b ())
    -> Maybe (Handler b b Builder, ByteString)
    -> Handler b b ()
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe Handler b b ()
    forall (m :: * -> *) a. MonadSnap m => m a
    pass (Handler b b Builder, ByteString) -> Handler b b ()
    serve (Maybe (Handler b b Builder, ByteString) -> Handler b b ())
    -> Maybe (Handler b b Builder, ByteString) -> Handler b b ()
    forall a b. (a -> b) -> a -> b
    $ HeistState (Handler b b)
    -> ByteString -> Maybe (Handler b b Builder, ByteString)
    forall (n :: * -> *).
    Monad n =>
    HeistState n -> ByteString -> Maybe (n Builder, ByteString)
    C.renderTemplate HeistState (Handler b b)
    hs ByteString
    t
      where
        serve :: (Handler b b Builder, ByteString) -> Handler b b ()
    serve (b :: Handler b b Builder
    b, mime :: ByteString
    mime) = do
            (Response -> Response) -> Handler b b ()
    forall (m :: * -> *). MonadSnap m => (Response -> Response) -> m ()
    modifyResponse ((Response -> Response) -> Handler b b ())
    -> (Response -> Response) -> Handler b b ()
    forall a b. (a -> b) -> a -> b
    $ ByteString -> Response -> Response
    setContentType (ByteString -> Response -> Response)
    -> ByteString -> Response -> Response
    forall a b. (a -> b) -> a -> b
    $ ByteString -> Maybe ByteString -> ByteString
    forall a. a -> Maybe a -> a
    fromMaybe ByteString
    mime Maybe ByteString
    c
            Builder -> Handler b b ()
    forall (m :: * -> *). MonadSnap m => Builder -> m ()
    writeBuilder (Builder -> Handler b b ())
    -> Handler b b Builder -> Handler b b ()
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< Handler b b Builder
    b

    ------------------------------------------------------------------------------
    serveURI :: Handler b (Heist b) ByteString
    serveURI :: Handler b (Heist b) ByteString
    serveURI = do
        [Char]
    p <- Handler b (Heist b) [Char]
    forall (m :: * -> *). MonadSnap m => m [Char]
    getSafePath
        -- Allows users to prefix template filenames with an underscore to prevent
        -- the template from being served.
        if Int -> [Char] -> [Char]
    forall a. Int -> [a] -> [a]
    take 1 [Char]
    p [Char] -> [Char] -> Bool
    forall a. Eq a => a -> a -> Bool
    == "_" then Handler b (Heist b) ByteString
    forall (m :: * -> *) a. MonadSnap m => m a
    pass else ByteString -> Handler b (Heist b) ByteString
    forall (m :: * -> *) a. Monad m => a -> m a
    return (ByteString -> Handler b (Heist b) ByteString)
    -> ByteString -> Handler b (Heist b) ByteString
    forall a b. (a -> b) -> a -> b
    $ [Char] -> ByteString
    B.pack [Char]
    p

    ------------------------------------------------------------------------------
    render :: ByteString
               -- ^ Name of the template
           -> Handler b (Heist b) ()
    render :: ByteString -> Handler b (Heist b) ()
    render t :: ByteString
    t = Maybe ByteString -> ByteString -> Handler b (Heist b) ()
    forall b. Maybe ByteString -> ByteString -> Handler b (Heist b) ()
    iRenderHelper Maybe ByteString
    forall a. Maybe a
    Nothing ByteString
    t

    ------------------------------------------------------------------------------
    renderAs :: ByteString
                 -- ^ Content type
             -> ByteString
                 -- ^ Name of the template
             -> Handler b (Heist b) ()
    renderAs :: ByteString -> ByteString -> Handler b (Heist b) ()
    renderAs ct :: ByteString
    ct t :: ByteString
    t = Maybe ByteString -> ByteString -> Handler b (Heist b) ()
    forall b. Maybe ByteString -> ByteString -> Handler b (Heist b) ()
    iRenderHelper (ByteString -> Maybe ByteString
    forall a. a -> Maybe a
    Just ByteString
    ct) ByteString
    t

    ------------------------------------------------------------------------------
    heistServe :: Handler b (Heist b) ()
    heistServe :: Handler b (Heist b) ()
    heistServe =
        Handler b (Heist b) () -> Handler b (Heist b) ()
    forall (m :: * -> *) a. MonadSnap m => m a -> m a
    ifTop (ByteString -> Handler b (Heist b) ()
    forall b. ByteString -> Handler b (Heist b) ()
    render "index") Handler b (Heist b) ()
    -> Handler b (Heist b) () -> Handler b (Heist b) ()
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
    <|> (ByteString -> Handler b (Heist b) ()
    forall b. ByteString -> Handler b (Heist b) ()
    render (ByteString -> Handler b (Heist b) ())
    -> Handler b (Heist b) ByteString -> Handler b (Heist b) ()
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< Handler b (Heist b) ByteString
    forall b. Handler b (Heist b) ByteString
    serveURI)

    ------------------------------------------------------------------------------
    heistServeSingle :: ByteString -> Handler b (Heist b) ()
    heistServeSingle :: ByteString -> Handler b (Heist b) ()
    heistServeSingle t :: ByteString
    t =
        ByteString -> Handler b (Heist b) ()
    forall b. ByteString -> Handler b (Heist b) ()
    render ByteString
    t Handler b (Heist b) ()
    -> Handler b (Heist b) () -> Handler b (Heist b) ()
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
    <|> [Char] -> Handler b (Heist b) ()
    forall a. HasCallStack => [Char] -> a
    error ("Template " [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ ByteString -> [Char]
    forall a. Show a => a -> [Char]
    show ByteString
    t [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ " not found.")

    ------------------------------------------------------------------------------
    cRender :: ByteString
               -- ^ Name of the template
            -> Handler b (Heist b) ()
    cRender :: ByteString -> Handler b (Heist b) ()
    cRender t :: ByteString
    t = Maybe ByteString -> ByteString -> Handler b (Heist b) ()
    forall b. Maybe ByteString -> ByteString -> Handler b (Heist b) ()
    cRenderHelper Maybe ByteString
    forall a. Maybe a
    Nothing ByteString
    t

    ------------------------------------------------------------------------------
    cRenderAs :: ByteString
                 -- ^ Content type
              -> ByteString
                 -- ^ Name of the template
              -> Handler b (Heist b) ()
    cRenderAs :: ByteString -> ByteString -> Handler b (Heist b) ()
    cRenderAs ct :: ByteString
    ct t :: ByteString
    t = Maybe ByteString -> ByteString -> Handler b (Heist b) ()
    forall b. Maybe ByteString -> ByteString -> Handler b (Heist b) ()
    cRenderHelper (ByteString -> Maybe ByteString
    forall a. a -> Maybe a
    Just ByteString
    ct) ByteString
    t

    ------------------------------------------------------------------------------
    cHeistServe :: Handler b (Heist b) ()
    cHeistServe :: Handler b (Heist b) ()
    cHeistServe =
        Handler b (Heist b) () -> Handler b (Heist b) ()
    forall (m :: * -> *) a. MonadSnap m => m a -> m a
    ifTop (ByteString -> Handler b (Heist b) ()
    forall b. ByteString -> Handler b (Heist b) ()
    cRender "index") Handler b (Heist b) ()
    -> Handler b (Heist b) () -> Handler b (Heist b) ()
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
    <|> (ByteString -> Handler b (Heist b) ()
    forall b. ByteString -> Handler b (Heist b) ()
    cRender (ByteString -> Handler b (Heist b) ())
    -> Handler b (Heist b) ByteString -> Handler b (Heist b) ()
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< Handler b (Heist b) ByteString
    forall b. Handler b (Heist b) ByteString
    serveURI)

    ------------------------------------------------------------------------------
    cHeistServeSingle :: ByteString -> Handler b (Heist b) ()
    cHeistServeSingle :: ByteString -> Handler b (Heist b) ()
    cHeistServeSingle t :: ByteString
    t =
        ByteString -> Handler b (Heist b) ()
    forall b. ByteString -> Handler b (Heist b) ()
    cRender ByteString
    t Handler b (Heist b) ()
    -> Handler b (Heist b) () -> Handler b (Heist b) ()
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
    <|> [Char] -> Handler b (Heist b) ()
    forall a. HasCallStack => [Char] -> a
    error ("Template " [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ ByteString -> [Char]
    forall a. Show a => a -> [Char]
    show ByteString
    t [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ " not found.")

    ------------------------------------------------------------------------------
    -- | Chooses between a compiled action and an interpreted action based on the
    -- configured default.
    chooseMode :: MonadState (Heist b1) m
               => m b
                   -- ^ A compiled action
               -> m b
                   -- ^ An interpreted action
               -> m b
    chooseMode :: m b -> m b -> m b
    chooseMode cAction :: m b
    cAction iAction :: m b
    iAction = do
        DefaultMode
    mode <- (Heist b1 -> DefaultMode) -> m DefaultMode
    forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
    gets Heist b1 -> DefaultMode
    forall b. Heist b -> DefaultMode
    _defMode
        case DefaultMode
    mode of
          Compiled -> m b
    cAction
          Interpreted -> m b
    iAction

    ------------------------------------------------------------------------------
    -- | Like render/cRender, but chooses between the two appropriately based on
    -- the default mode.
    gRender :: ByteString
               -- ^ Name of the template
            -> Handler b (Heist b) ()
    gRender :: ByteString -> Handler b (Heist b) ()
    gRender t :: ByteString
    t = Handler b (Heist b) ()
    -> Handler b (Heist b) () -> Handler b (Heist b) ()
    forall b1 (m :: * -> *) b.
    MonadState (Heist b1) m =>
    m b -> m b -> m b
    chooseMode (ByteString -> Handler b (Heist b) ()
    forall b. ByteString -> Handler b (Heist b) ()
    cRender ByteString
    t) (ByteString -> Handler b (Heist b) ()
    forall b. ByteString -> Handler b (Heist b) ()
    render ByteString
    t)

    ------------------------------------------------------------------------------
    -- | Like renderAs/cRenderAs, but chooses between the two appropriately based
    -- on the default mode.
    gRenderAs :: ByteString
                 -- ^ Content type
              -> ByteString
                 -- ^ Name of the template
              -> Handler b (Heist b) ()
    gRenderAs :: ByteString -> ByteString -> Handler b (Heist b) ()
    gRenderAs ct :: ByteString
    ct t :: ByteString
    t = Handler b (Heist b) ()
    -> Handler b (Heist b) () -> Handler b (Heist b) ()
    forall b1 (m :: * -> *) b.
    MonadState (Heist b1) m =>
    m b -> m b -> m b
    chooseMode (ByteString -> ByteString -> Handler b (Heist b) ()
    forall b. ByteString -> ByteString -> Handler b (Heist b) ()
    cRenderAs ByteString
    ct ByteString
    t) (ByteString -> ByteString -> Handler b (Heist b) ()
    forall b. ByteString -> ByteString -> Handler b (Heist b) ()
    renderAs ByteString
    ct ByteString
    t)

    ------------------------------------------------------------------------------
    -- | Like heistServe/cHeistServe, but chooses between the two appropriately
    -- based on the default mode.
    gHeistServe :: Handler b (Heist b) ()
    gHeistServe :: Handler b (Heist b) ()
    gHeistServe = Handler b (Heist b) ()
    -> Handler b (Heist b) () -> Handler b (Heist b) ()
    forall b1 (m :: * -> *) b.
    MonadState (Heist b1) m =>
    m b -> m b -> m b
    chooseMode Handler b (Heist b) ()
    forall b. Handler b (Heist b) ()
    cHeistServe Handler b (Heist b) ()
    forall b. Handler b (Heist b) ()
    heistServe

    ------------------------------------------------------------------------------
    -- | Like heistServeSingle/cHeistServeSingle, but chooses between the two
    -- appropriately based on the default mode.
    gHeistServeSingle :: ByteString -> Handler b (Heist b) ()
    gHeistServeSingle :: ByteString -> Handler b (Heist b) ()
    gHeistServeSingle t :: ByteString
    t = Handler b (Heist b) ()
    -> Handler b (Heist b) () -> Handler b (Heist b) ()
    forall b1 (m :: * -> *) b.
    MonadState (Heist b1) m =>
    m b -> m b -> m b
    chooseMode (ByteString -> Handler b (Heist b) ()
    forall b. ByteString -> Handler b (Heist b) ()
    cHeistServeSingle ByteString
    t) (ByteString -> Handler b (Heist b) ()
    forall b. ByteString -> Handler b (Heist b) ()
    heistServeSingle ByteString
    t)

    ------------------------------------------------------------------------------
    heistLocal' :: SnapletLens (Snaplet b) (Heist b)
                -> (HeistState (Handler b b) -> HeistState (Handler b b))
                -> Handler b v a
                -> Handler b v a
    heistLocal' :: SnapletLens (Snaplet b) (Heist b)
    -> (HeistState (Handler b b) -> HeistState (Handler b b))
    -> Handler b v a
    -> Handler b v a
    heistLocal' heist :: SnapletLens (Snaplet b) (Heist b)
    heist f :: HeistState (Handler b b) -> HeistState (Handler b b)
    f m :: Handler b v a
    m = do
        Heist b
    hs  <- SnapletLens (Snaplet b) (Heist b)
    -> Handler b (Heist b) (Heist b) -> Handler b v (Heist b)
    forall (m :: * -> * -> * -> *) b v' a v.
    MonadSnaplet m =>
    SnapletLens (Snaplet b) v' -> m b v' a -> m b v a
    withTop' SnapletLens (Snaplet b) (Heist b)
    heist Handler b (Heist b) (Heist b)
    forall s (m :: * -> *). MonadState s m => m s
    get
        SnapletLens (Snaplet b) (Heist b)
    -> Handler b (Heist b) () -> Handler b v ()
    forall (m :: * -> * -> * -> *) b v' a v.
    MonadSnaplet m =>
    SnapletLens (Snaplet b) v' -> m b v' a -> m b v a
    withTop' SnapletLens (Snaplet b) (Heist b)
    heist (Handler b (Heist b) () -> Handler b v ())
    -> Handler b (Heist b) () -> Handler b v ()
    forall a b. (a -> b) -> a -> b
    $ (Heist b -> Heist b) -> Handler b (Heist b) ()
    forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
    modify ((Heist b -> Heist b) -> Handler b (Heist b) ())
    -> (Heist b -> Heist b) -> Handler b (Heist b) ()
    forall a b. (a -> b) -> a -> b
    $ (HeistState (Handler b b) -> HeistState (Handler b b))
    -> Heist b -> Heist b
    forall a.
    (HeistState (Handler a a) -> HeistState (Handler a a))
    -> Heist a -> Heist a
    changeState HeistState (Handler b b) -> HeistState (Handler b b)
    f
        a
    res <- Handler b v a
    m
        SnapletLens (Snaplet b) (Heist b)
    -> Handler b (Heist b) () -> Handler b v ()
    forall (m :: * -> * -> * -> *) b v' a v.
    MonadSnaplet m =>
    SnapletLens (Snaplet b) v' -> m b v' a -> m b v a
    withTop' SnapletLens (Snaplet b) (Heist b)
    heist (Handler b (Heist b) () -> Handler b v ())
    -> Handler b (Heist b) () -> Handler b v ()
    forall a b. (a -> b) -> a -> b
    $ Heist b -> Handler b (Heist b) ()
    forall s (m :: * -> *). MonadState s m => s -> m ()
    put Heist b
    hs
        a -> Handler b v a
    forall (m :: * -> *) a. Monad m => a -> m a
    return a
    res

    ------------------------------------------------------------------------------
    heistLocal :: SnapletLens b (Heist b)
               -> (HeistState (Handler b b) -> HeistState (Handler b b))
               -> Handler b v a
               -> Handler b v a
    heistLocal :: SnapletLens b (Heist b)
    -> (HeistState (Handler b b) -> HeistState (Handler b b))
    -> Handler b v a
    -> Handler b v a
    heistLocal heist :: SnapletLens b (Heist b)
    heist f :: HeistState (Handler b b) -> HeistState (Handler b b)
    f m :: Handler b v a
    m = SnapletLens (Snaplet b) (Heist b)
    -> (HeistState (Handler b b) -> HeistState (Handler b b))
    -> Handler b v a
    -> Handler b v a
    forall b v a.
    SnapletLens (Snaplet b) (Heist b)
    -> (HeistState (Handler b b) -> HeistState (Handler b b))
    -> Handler b v a
    -> Handler b v a
    heistLocal' (SnapletLens b (Heist b) -> SnapletLens (Snaplet b) (Heist b)
    forall a b. SnapletLens a b -> SnapletLens (Snaplet a) b
    subSnaplet SnapletLens b (Heist b)
    heist) HeistState (Handler b b) -> HeistState (Handler b b)
    f Handler b v a
    m

    ------------------------------------------------------------------------------
    withSplices' :: SnapletLens (Snaplet b) (Heist b)
                 -> Splices (SnapletISplice b)
                 -> Handler b v a
                 -> Handler b v a
    withSplices' :: SnapletLens (Snaplet b) (Heist b)
    -> Splices (SnapletISplice b) -> Handler b v a -> Handler b v a
    withSplices' heist :: SnapletLens (Snaplet b) (Heist b)
    heist splices :: Splices (SnapletISplice b)
    splices m :: Handler b v a
    m = do
        SnapletLens (Snaplet b) (Heist b)
    -> (HeistState (Handler b b) -> HeistState (Handler b b))
    -> Handler b v a
    -> Handler b v a
    forall b v a.
    SnapletLens (Snaplet b) (Heist b)
    -> (HeistState (Handler b b) -> HeistState (Handler b b))
    -> Handler b v a
    -> Handler b v a
    heistLocal' SnapletLens (Snaplet b) (Heist b)
    heist (Splices (SnapletISplice b)
    -> HeistState (Handler b b) -> HeistState (Handler b b)
    forall (n :: * -> *).
    Splices (Splice n) -> HeistState n -> HeistState n
    I.bindSplices Splices (SnapletISplice b)
    splices) Handler b v a
    m

    ------------------------------------------------------------------------------
    withSplices :: SnapletLens b (Heist b)
                -> Splices (SnapletISplice b)
                -> Handler b v a
                -> Handler b v a
    withSplices :: SnapletLens b (Heist b)
    -> Splices (SnapletISplice b) -> Handler b v a -> Handler b v a
    withSplices heist :: SnapletLens b (Heist b)
    heist splices :: Splices (SnapletISplice b)
    splices m :: Handler b v a
    m = SnapletLens (Snaplet b) (Heist b)
    -> Splices (SnapletISplice b) -> Handler b v a -> Handler b v a
    forall b v a.
    SnapletLens (Snaplet b) (Heist b)
    -> Splices (SnapletISplice b) -> Handler b v a -> Handler b v a
    withSplices' (SnapletLens b (Heist b) -> SnapletLens (Snaplet b) (Heist b)
    forall a b. SnapletLens a b -> SnapletLens (Snaplet a) b
    subSnaplet SnapletLens b (Heist b)
    heist) Splices (SnapletISplice b)
    splices Handler b v a
    m

    ------------------------------------------------------------------------------
    renderWithSplices' :: SnapletLens (Snaplet b) (Heist b)
                       -> ByteString
                       -> Splices (SnapletISplice b)
                       -> Handler b v ()
    renderWithSplices' :: SnapletLens (Snaplet b) (Heist b)
    -> ByteString -> Splices (SnapletISplice b) -> Handler b v ()
    renderWithSplices' heist :: SnapletLens (Snaplet b) (Heist b)
    heist t :: ByteString
    t splices :: Splices (SnapletISplice b)
    splices =
        SnapletLens (Snaplet b) (Heist b)
    -> Splices (SnapletISplice b) -> Handler b v () -> Handler b v ()
    forall b v a.
    SnapletLens (Snaplet b) (Heist b)
    -> Splices (SnapletISplice b) -> Handler b v a -> Handler b v a
    withSplices' SnapletLens (Snaplet b) (Heist b)
    heist Splices (SnapletISplice b)
    splices (Handler b v () -> Handler b v ())
    -> Handler b v () -> Handler b v ()
    forall a b. (a -> b) -> a -> b
    $ SnapletLens (Snaplet b) (Heist b)
    -> Handler b (Heist b) () -> Handler b v ()
    forall (m :: * -> * -> * -> *) b v' a v.
    MonadSnaplet m =>
    SnapletLens (Snaplet b) v' -> m b v' a -> m b v a
    withTop' SnapletLens (Snaplet b) (Heist b)
    heist (Handler b (Heist b) () -> Handler b v ())
    -> Handler b (Heist b) () -> Handler b v ()
    forall a b. (a -> b) -> a -> b
    $ ByteString -> Handler b (Heist b) ()
    forall b. ByteString -> Handler b (Heist b) ()
    render ByteString
    t

    ------------------------------------------------------------------------------
    renderWithSplices :: SnapletLens b (Heist b)
                      -> ByteString
                      -> Splices (SnapletISplice b)
                      -> Handler b v ()
    renderWithSplices :: SnapletLens b (Heist b)
    -> ByteString -> Splices (SnapletISplice b) -> Handler b v ()
    renderWithSplices heist :: SnapletLens b (Heist b)
    heist t :: ByteString
    t splices :: Splices (SnapletISplice b)
    splices =
        SnapletLens (Snaplet b) (Heist b)
    -> ByteString -> Splices (SnapletISplice b) -> Handler b v ()
    forall b v.
    SnapletLens (Snaplet b) (Heist b)
    -> ByteString -> Splices (SnapletISplice b) -> Handler b v ()
    renderWithSplices' (SnapletLens b (Heist b) -> SnapletLens (Snaplet b) (Heist b)
    forall a b. SnapletLens a b -> SnapletLens (Snaplet a) b
    subSnaplet SnapletLens b (Heist b)
    heist) ByteString
    t Splices (SnapletISplice b)
    splices