Skip to content
Browse files

Add modules for only compiled or interpreted heist functionality.

  • Loading branch information...
1 parent 07b6825 commit 04cd435a770a0afd3b192a0d841242a0c4828f47 @mightybyte mightybyte committed Jan 21, 2013
Showing with 117 additions and 0 deletions.
  1. +80 −0 src/Snap/Snaplet/Heist/Compiled.hs
  2. +37 −0 src/Snap/Snaplet/Heist/Interpreted.hs
View
80 src/Snap/Snaplet/Heist/Compiled.hs
@@ -0,0 +1,80 @@
+{- | A module exporting only functions for using compiled templates. If you
+ - import the main Snap.Snaplet.Heist module, it's easy to accidentally use
+ - the interpreted render function even when you're using compiled Heist.
+ - Importing only this module will make it harder to make mistakes like that.
+ -}
+module Snap.Snaplet.Heist.Compiled
+ ( H.Heist
+ , H.HasHeist(..)
+ , H.SnapletHeist
+ , H.SnapletCSplice
+
+ -- * Initializer Functions
+ -- $initializerSection
+ , H.heistInit
+ , H.heistInit'
+ , H.addTemplates
+ , H.addTemplatesAt
+ , H.addConfig
+ , H.modifyHeistState
+ , H.withHeistState
+
+ -- * Handler Functions
+ -- $handlerSection
+ , render
+ , renderAs
+ , heistServe
+ , heistServeSingle
+
+ , H.clearHeistCache
+ ) where
+
+import Data.ByteString (ByteString)
+import Snap.Snaplet
+import qualified Snap.Snaplet.Heist as H
+
+
+------------------------------------------------------------------------------
+-- | Renders a compiled template as text\/html. If the given template is not
+-- found, this returns 'empty'.
+render :: H.HasHeist b
+ => ByteString
+ -- ^ Template name
+ -> Handler b v ()
+render = H.cRender
+
+
+------------------------------------------------------------------------------
+-- | Renders a compiled template as the given content type. If the given
+-- template is not found, this returns 'empty'.
+renderAs :: H.HasHeist b
+ => ByteString
+ -- ^ Content type to render with
+ -> ByteString
+ -- ^ Template name
+ -> Handler b v ()
+renderAs = H.cRenderAs
+
+
+------------------------------------------------------------------------------
+-- | A handler that serves all the templates (similar to 'serveDirectory').
+-- If the template specified in the request path is not found, it returns
+-- 'empty'. Also, this function does not serve any templates beginning with
+-- an underscore. This gives you a way to prevent some templates from being
+-- served. For example, you might have a template that contains only the
+-- navbar of your pages, and you probably wouldn't want that template to be
+-- visible to the user as a standalone template. So if you put it in a file
+-- called \"_nav.tpl\", this function won't serve it.
+heistServe :: H.HasHeist b => Handler b v ()
+heistServe = H.cHeistServe
+
+
+------------------------------------------------------------------------------
+-- | Handler for serving a single template (similar to 'fileServeSingle'). If
+-- the given template is not found, this throws an error.
+heistServeSingle :: H.HasHeist b
+ => ByteString
+ -- ^ Template name
+ -> Handler b v ()
+heistServeSingle = H.cHeistServeSingle
+
View
37 src/Snap/Snaplet/Heist/Interpreted.hs
@@ -0,0 +1,37 @@
+{- | A module exporting only functions for using interpreted templates. If
+ - you import the main Snap.Snaplet.Heist module, it's easy to accidentally
+ - use the compiled render function even when you're using interpreted Heist.
+ - Importing only this module will make it harder to make mistakes like that.
+ -}
+module Snap.Snaplet.Heist.Interpreted
+ ( Heist
+ , HasHeist(..)
+ , SnapletHeist
+ , SnapletISplice
+
+ -- * Initializer Functions
+ -- $initializerSection
+ , heistInit
+ , heistInit'
+ , addTemplates
+ , addTemplatesAt
+ , addConfig
+ , modifyHeistState
+ , withHeistState
+ , addSplices
+
+ -- * Handler Functions
+ -- $handlerSection
+ , render
+ , renderAs
+ , heistServe
+ , heistServeSingle
+ , heistLocal
+ , withSplices
+ , renderWithSplices
+
+ , clearHeistCache
+ ) where
+
+import Snap.Snaplet.Heist
+

0 comments on commit 04cd435

Please sign in to comment.
Something went wrong with that request. Please try again.