snap-0.4.3: Snap: A Haskell Web Framework: project starter executable and glue code library

Snap.Extension.Heist

Description

Snap.Extension.Heist exports the MonadHeist interface which allows you to integrate Heist templates into your Snap application. The interface's operations are heistServe, heistServeSingle, heistLocal and render. As a convenience, we also provide renderWithSplices that combines heistLocal and render into a single function call.

Snap.Extension.Heist.Impl contains the only implementation of this interface and can be used to turn your application's monad into a MonadHeist.

MonadHeist is unusual among Snap extensions in that it's a multi-parameter typeclass. The last parameter is your application's monad, and the first is the monad you want the TemplateState to use. This is usually, but not always, also your application's monad.

This module should not be used directly. Instead, import Snap.Extension.Heist.Impl in your application.

Synopsis

Documentation

class (Monad n, MonadSnap m) => MonadHeist n m | m -> n whereSource

The MonadHeist type class. Minimal complete definition: render, heistLocal.

Methods

render :: ByteString -> m ()Source

Renders a template as text/html. If the given template is not found, this returns empty.

renderAs :: ByteString -> ByteString -> m ()Source

Renders a template as the given content type. If the given template is not found, this returns empty.

heistLocal :: (TemplateState n -> TemplateState n) -> m a -> m aSource

Runs an action with a modified TemplateState. You might want to use this if you had a set of splices which were customised for a specific action. To do that you would do:

 heistLocal (bindSplices mySplices) $ render "myTemplate"

heistServe :: m ()Source

Analogous to fileServe. If the template specified in the request path is not found, it returns empty.

heistServeSingle :: ByteString -> m ()Source

Analogous to fileServeSingle. If the given template is not found, this throws an error.

renderWithSplicesSource

Arguments

:: MonadHeist n m 
=> ByteString

Template to render

-> [(Text, Splice n)]

Splice mapping

-> m () 

Helper function for common use case: Render a template with a given set of splices.