Safe Haskell | None |
---|---|
Language | Haskell98 |
A module exporting only generic functions that choose between compiled and interpreted mode based on the setting specified in the initializer. This module is most useful for writitng general snaplets that use Heist and are meant to be used in applications that might use either interpreted or compiled templates.
Synopsis
- data Heist b
- class HasHeist b where
- heistLens :: SnapletLens (Snaplet b) (Heist b)
- type SnapletHeist b m a = HeistT (Handler b b) m a
- type SnapletCSplice b = SnapletHeist b IO (DList (Chunk (Handler b b)))
- addTemplates :: HasHeist b => Snaplet (Heist b) -> ByteString -> Initializer b v ()
- addTemplatesAt :: HasHeist b => Snaplet (Heist b) -> ByteString -> FilePath -> Initializer b v ()
- addConfig :: Snaplet (Heist b) -> SpliceConfig (Handler b b) -> Initializer b v ()
- getHeistState :: HasHeist b => Handler b v (HeistState (Handler b b))
- modifyHeistState :: HasHeist b => (HeistState (Handler b b) -> HeistState (Handler b b)) -> Initializer b v ()
- withHeistState :: HasHeist b => (HeistState (Handler b b) -> a) -> Handler b v a
- gRender :: HasHeist b => ByteString -> Handler b v ()
- gRenderAs :: HasHeist b => ByteString -> ByteString -> Handler b v ()
- gHeistServe :: HasHeist b => Handler b v ()
- gHeistServeSingle :: HasHeist b => ByteString -> Handler b v ()
- chooseMode :: HasHeist b => Handler b v a -> Handler b v a -> Handler b v a
- clearHeistCache :: Heist b -> IO ()
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.
class HasHeist b where Source #
A single snaplet should never need more than one instance of Heist as a subsnaplet. This type class allows you to make it easy for other snaplets to get the lens that identifies the heist snaplet. Here's an example of how the heist snaplet might be declared:
data App = App { _heist :: Snaplet (Heist App) } makeLenses ''App instance HasHeist App where heistLens = subSnaplet heist appInit = makeSnaplet "app" "" Nothing $ do h <- nestSnaplet "heist" heist $ heistInit "templates" addConfig h heistConfigWithMyAppSplices return $ App h
type SnapletHeist b m a = HeistT (Handler b b) m a Source #
type SnapletCSplice b = SnapletHeist b IO (DList (Chunk (Handler b b))) Source #
Initializer Functions
:: HasHeist b | |
=> Snaplet (Heist b) | |
-> ByteString | The url prefix for the template routes |
-> Initializer b v () |
Adds templates to the Heist HeistState. 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.
:: HasHeist b | |
=> Snaplet (Heist b) | |
-> ByteString | URL prefix for template routes |
-> FilePath | Path to templates |
-> Initializer b v () |
Adds templates to the Heist HeistState, 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.
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.
getHeistState :: HasHeist b => Handler b v (HeistState (Handler b b)) Source #
More general function allowing arbitrary HeistState modification.
:: HasHeist b | |
=> (HeistState (Handler b b) -> HeistState (Handler b b)) | HeistState modifying function |
-> Initializer b v () |
More general function allowing arbitrary HeistState modification.
:: HasHeist b | |
=> (HeistState (Handler b b) -> a) | HeistState function to run |
-> Handler b v a |
Runs a function on with the Heist snaplet's HeistState
.
Handler Functions
:: HasHeist b | |
=> ByteString | Template name |
-> Handler b v () |
Generic version of 'render'/'cRender'.
:: HasHeist b | |
=> ByteString | Content type to render with |
-> ByteString | Template name |
-> Handler b v () |
Generic version of 'renderAs'/'cRenderAs'.
gHeistServe :: HasHeist b => Handler b v () Source #
Generic version of 'heistServe'/'cHeistServe'.
:: HasHeist b | |
=> ByteString | Template name |
-> Handler b v () |
Generic version of 'heistServeSingle'/'cHeistServeSingle'.
:: HasHeist b | |
=> Handler b v a | A compiled action |
-> Handler b v a | An interpreted action |
-> Handler b v a |
Chooses between a compiled action and an interpreted action based on the configured default.
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.