Safe Haskell | None |
---|---|
Language | Haskell98 |
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.
- data Heist b
- data DefaultMode
- heistInit :: FilePath -> SnapletInit b (Heist b)
- heistInit' :: FilePath -> HeistConfig (Handler b b) -> SnapletInit b (Heist b)
- heistReloader :: Handler b (Heist b) ()
- setInterpreted :: Snaplet (Heist b) -> Initializer b v ()
- getCurHeistConfig :: Snaplet (Heist b) -> Initializer b v (HeistConfig (Handler b b))
- clearHeistCache :: Heist b -> IO ()
- addTemplates :: Snaplet (Heist b) -> ByteString -> Initializer b (Heist b) ()
- addTemplatesAt :: Snaplet (Heist b) -> ByteString -> FilePath -> Initializer b (Heist b) ()
- getHeistState :: SnapletLens (Snaplet b) (Heist b) -> Handler b v (HeistState (Handler b b))
- modifyHeistState :: SnapletLens 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 ()
- withHeistState :: SnapletLens 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
- gRender :: ByteString -> Handler b (Heist b) ()
- gRenderAs :: ByteString -> ByteString -> Handler b (Heist b) ()
- gHeistServe :: Handler b (Heist b) ()
- gHeistServeSingle :: ByteString -> Handler b (Heist b) ()
- chooseMode :: MonadState (Heist b1) m => m b -> m b -> m b
- addConfig :: Snaplet (Heist b) -> SpliceConfig (Handler b b) -> Initializer b v ()
- cRender :: ByteString -> Handler b (Heist b) ()
- cRenderAs :: ByteString -> ByteString -> Handler b (Heist b) ()
- cHeistServe :: Handler b (Heist b) ()
- cHeistServeSingle :: ByteString -> Handler b (Heist b) ()
- render :: ByteString -> Handler b (Heist b) ()
- renderAs :: ByteString -> ByteString -> Handler b (Heist b) ()
- heistServe :: Handler b (Heist b) ()
- heistServeSingle :: ByteString -> Handler b (Heist b) ()
- heistLocal :: SnapletLens b (Heist b) -> (HeistState (Handler b b) -> HeistState (Handler b 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
- renderWithSplices :: SnapletLens b (Heist b) -> ByteString -> Splices (SnapletISplice b) -> Handler b v ()
- heistLocal' :: SnapletLens (Snaplet b) (Heist b) -> (HeistState (Handler b b) -> HeistState (Handler b 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
- renderWithSplices' :: SnapletLens (Snaplet b) (Heist b) -> ByteString -> Splices (SnapletISplice b) -> Handler b v ()
- type SnapletHeist b m a = HeistT (Handler b b) m a
- type SnapletISplice b = SnapletHeist b (Handler b b) Template
- type SnapletCSplice b = SnapletHeist b IO (DList (Chunk (Handler b b)))
Documentation
The state for the Heist snaplet. To use the Heist snaplet in your app
include this in your application state and use heistInit
to initialize
it. The type parameter b will typically be the base state type for your
application.
:: FilePath | Path to templates |
-> SnapletInit b (Heist b) |
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.
:: FilePath | Path to templates |
-> HeistConfig (Handler b b) | Initial HeistConfig |
-> SnapletInit b (Heist b) |
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.
heistReloader :: Handler b (Heist b) () Source #
Handler that triggers a template reload. For large sites, this can be desireable because it may be much quicker than the full site reload provided at the adminreload route. This allows you to reload only the heist templates This handler is automatically set up by heistInit, but if you use heistInit', then you can create your own route with it.
setInterpreted :: Snaplet (Heist b) -> Initializer b v () Source #
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.
getCurHeistConfig :: Snaplet (Heist b) -> Initializer b v (HeistConfig (Handler b b)) Source #
clearHeistCache :: Heist b -> IO () Source #
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.
:: Snaplet (Heist b) | |
-> ByteString | The url prefix for the template routes |
-> Initializer b (Heist b) () |
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.
:: Snaplet (Heist b) | |
-> ByteString | URL prefix for template routes |
-> FilePath | Path to templates |
-> Initializer b (Heist b) () |
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.
getHeistState :: SnapletLens (Snaplet b) (Heist b) -> Handler b v (HeistState (Handler b b)) Source #
modifyHeistState :: SnapletLens b (Heist b) -> (HeistState (Handler b b) -> HeistState (Handler b b)) -> Initializer b v () Source #
modifyHeistState' :: SnapletLens (Snaplet b) (Heist b) -> (HeistState (Handler b b) -> HeistState (Handler b b)) -> Initializer b v () Source #
withHeistState :: SnapletLens b (Heist b) -> (HeistState (Handler b b) -> a) -> Handler b v a Source #
withHeistState' :: SnapletLens (Snaplet b) (Heist b) -> (HeistState (Handler b b) -> a) -> Handler b v a Source #
:: ByteString | Name of the template |
-> Handler b (Heist b) () |
Like render/cRender, but chooses between the two appropriately based on the default mode.
:: ByteString | Content type |
-> ByteString | Name of the template |
-> Handler b (Heist b) () |
Like renderAs/cRenderAs, but chooses between the two appropriately based on the default mode.
gHeistServe :: Handler b (Heist b) () Source #
Like heistServe/cHeistServe, but chooses between the two appropriately based on the default mode.
gHeistServeSingle :: ByteString -> Handler b (Heist b) () Source #
Like heistServeSingle/cHeistServeSingle, but chooses between the two appropriately based on the default mode.
:: MonadState (Heist b1) m | |
=> m b | A compiled action |
-> m b | An interpreted action |
-> m b |
Chooses between a compiled action and an interpreted action based on the configured default.
addConfig :: Snaplet (Heist b) -> SpliceConfig (Handler b b) -> Initializer b v () Source #
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.
:: ByteString | Content type |
-> ByteString | Name of the template |
-> Handler b (Heist b) () |
cHeistServe :: Handler b (Heist b) () Source #
cHeistServeSingle :: ByteString -> Handler b (Heist b) () Source #
:: ByteString | Content type |
-> ByteString | Name of the template |
-> Handler b (Heist b) () |
heistServe :: Handler b (Heist b) () Source #
heistServeSingle :: ByteString -> Handler b (Heist b) () Source #
heistLocal :: SnapletLens b (Heist b) -> (HeistState (Handler b b) -> HeistState (Handler b b)) -> Handler b v a -> Handler b v a Source #
withSplices :: SnapletLens b (Heist b) -> Splices (SnapletISplice b) -> Handler b v a -> Handler b v a Source #
renderWithSplices :: SnapletLens b (Heist b) -> ByteString -> Splices (SnapletISplice b) -> Handler b v () Source #
heistLocal' :: SnapletLens (Snaplet b) (Heist b) -> (HeistState (Handler b b) -> HeistState (Handler b b)) -> Handler b v a -> Handler b v a Source #
withSplices' :: SnapletLens (Snaplet b) (Heist b) -> Splices (SnapletISplice b) -> Handler b v a -> Handler b v a Source #
renderWithSplices' :: SnapletLens (Snaplet b) (Heist b) -> ByteString -> Splices (SnapletISplice b) -> Handler b v () Source #
type SnapletHeist b m a = HeistT (Handler b b) m a Source #
type SnapletISplice b = SnapletHeist b (Handler b b) Template Source #
type SnapletCSplice b = SnapletHeist b IO (DList (Chunk (Handler b b))) Source #