Permalink
Browse files

Remove deprecated TemplateState.

  • Loading branch information...
1 parent 1e3cfe3 commit 0d7576855c9a398c922f2f082d04f92ed7beaa92 @gregorycollins gregorycollins committed Dec 10, 2011
Showing with 36 additions and 36 deletions.
  1. +13 −13 src/Snap/Snaplet/Heist.hs
  2. +23 −23 src/Snap/Snaplet/HeistNoClass.hs
@@ -85,7 +85,7 @@ class HasHeist b where
------------------------------------------------------------------------------
--- | Adds templates to the Heist TemplateState. Other snaplets should use
+-- | 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.
addTemplates :: HasHeist b
@@ -96,7 +96,7 @@ addTemplates pfx = withTop' heistLens (Unclassed.addTemplates pfx)
------------------------------------------------------------------------------
--- | Adds templates to the Heist TemplateState, and lets you specify where
+-- | Adds templates to the Heist HeistState, and lets you specify where
-- they are found in the filesystem.
addTemplatesAt :: HasHeist b
=> ByteString
@@ -117,21 +117,21 @@ addSplices = Unclassed.addSplices' heistLens
------------------------------------------------------------------------------
--- | More general function allowing arbitrary TemplateState modification.
+-- | More general function allowing arbitrary HeistState modification.
-- Without this function you wouldn't be able to bind more complicated splices
-- like the cache tag.
modifyHeistTS :: (HasHeist b)
- => (TemplateState (Handler b b) -> TemplateState (Handler b b))
- -- ^ TemplateState modifying function
+ => (HeistState (Handler b b) -> HeistState (Handler b b))
+ -- ^ HeistState modifying function
-> Initializer b v ()
modifyHeistTS = Unclassed.modifyHeistTS' heistLens
------------------------------------------------------------------------------
--- | Runs a function on with the Heist snaplet's 'TemplateState'.
+-- | Runs a function on with the Heist snaplet's 'HeistState'.
withHeistTS :: (HasHeist b)
- => (TemplateState (Handler b b) -> a)
- -- ^ TemplateState function to run
+ => (HeistState (Handler b b) -> a)
+ -- ^ HeistState function to run
-> Handler b v a
withHeistTS = Unclassed.withHeistTS' heistLens
@@ -194,7 +194,7 @@ renderWithSplices = Unclassed.renderWithSplices' heistLens
------------------------------------------------------------------------------
-- | Runs an action with additional splices bound into the Heist
--- 'TemplateState'.
+-- 'HeistState'.
withSplices :: HasHeist b
=> [(Text, Unclassed.SnapletSplice b v)]
-- ^ Splices to bind
@@ -205,14 +205,14 @@ withSplices = Unclassed.withSplices' heistLens
------------------------------------------------------------------------------
--- | Runs a handler with a modified 'TemplateState'. You might want to use
+-- | Runs a handler with a modified 'HeistState'. 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) handlerThatNeedsSplices
heistLocal :: HasHeist b
- => (TemplateState (Handler b b) -> TemplateState (Handler b b))
- -- ^ TemplateState modifying function
+ => (HeistState (Handler b b) -> HeistState (Handler b b))
+ -- ^ HeistState modifying function
-> Handler b v a
-- ^ Handler to run
-> Handler b v a
@@ -221,7 +221,7 @@ heistLocal = Unclassed.heistLocal' heistLens
-- $spliceSection
-- As can be seen in the type signature of heistLocal, the internal
--- TemplateState used by the heist snaplet is parameterized by (Handler b b).
+-- HeistState used by the heist snaplet is parameterized by (Handler b b).
-- The reasons for this are beyond the scope of this discussion, but the
-- result is that 'lift' inside a splice only works with @Handler b b@
-- actions. When you're writing your own snaplets you obviously would rather
@@ -70,13 +70,13 @@ import Snap.Util.FileServe
-- application.
--
data Heist b = Heist
- { _heistTS :: TemplateState (Handler b b)
+ { _heistTS :: HeistState (Handler b b)
, _heistCTS :: CacheTagState
}
------------------------------------------------------------------------------
-changeTS :: (TemplateState (Handler a a) -> TemplateState (Handler a a))
+changeTS :: (HeistState (Handler a a) -> HeistState (Handler a a))
-> Heist a
-> Heist a
changeTS f (Heist ts cts) = Heist (f ts) cts
@@ -205,8 +205,8 @@ instance MonadSnaplet SnapletHeist where
--
bindSnapletSplices :: (Lens (Snaplet b) (Snaplet v))
-> [(Text, SnapletSplice b v)]
- -> TemplateState (Handler b b)
- -> TemplateState (Handler b b)
+ -> HeistState (Handler b b)
+ -> HeistState (Handler b b)
bindSnapletSplices l splices =
bindSplices $ map (second $ runSnapletSplice l) splices
@@ -216,44 +216,44 @@ bindSnapletSplices l splices =
---------------------------
------------------------------------------------------------------------------
--- | The 'Initializer' for 'Heist'. This function is a convenience wrapper
--- around `heistInit'` that uses the default `emptyTemplateState` from Heist
--- and sets up routes for all the templates.
+-- | The 'Initializer' for 'Heist'. This function is a convenience wrapper
+-- around `heistInit'` that uses the default `mempty` HeistState and sets up
+-- routes for all the templates.
--
heistInit :: FilePath -- ^ Path to templates
-> SnapletInit b (Heist b)
heistInit templateDir = do
makeSnaplet "heist" "" Nothing $ do
- hs <- heistInitWorker templateDir emptyTemplateState
+ hs <- heistInitWorker templateDir mempty
@mightybyte
mightybyte Dec 15, 2011 Snap Framework member

mempty is not the same thing as emptyTemplateState. emptyTemplateState was renamed to defaultHeistState to better reflect that.

@gregorycollins
gregorycollins Dec 15, 2011 Snap Framework member

OK, do you want to fix that then?

@mightybyte
mightybyte Dec 15, 2011 Snap Framework member

Already done

addRoutes [ ("", heistServe) ]
return hs
------------------------------------------------------------------------------
-- | A lower level 'Initializer' for 'Heist'. This initializer requires you
--- to specify the initial TemplateState. It also does not add any routes for
+-- to specify the initial HeistState. It also does not add any routes for
-- templates, allowing you complete control over which templates get routed.
--
heistInit' :: FilePath
-- ^ Path to templates
- -> TemplateState (Handler b b)
- -- ^ Initial TemplateState
+ -> HeistState (Handler b b)
+ -- ^ Initial HeistState
-> SnapletInit b (Heist b)
-heistInit' templateDir initialTemplateState =
+heistInit' templateDir initialHeistState =
makeSnaplet "heist" "" Nothing $
- heistInitWorker templateDir initialTemplateState
+ heistInitWorker templateDir initialHeistState
------------------------------------------------------------------------------
-- | Internal worker function used by variantsof heistInit. This is necessary
-- because of the divide between SnapletInit and Initializer.
--
heistInitWorker :: FilePath
- -> TemplateState (Handler b b)
+ -> HeistState (Handler b b)
-> Initializer b v (Heist b)
-heistInitWorker templateDir initialTemplateState = do
+heistInitWorker templateDir initialHeistState = do
(cacheFunc, cts) <- liftIO mkCacheTag
- let origTs = cacheFunc initialTemplateState
+ let origTs = cacheFunc initialHeistState
ts <- liftIO $ loadTemplates templateDir origTs >>=
either error return
printInfo $ T.pack $ unwords
@@ -281,7 +281,7 @@ addTemplatesAt :: ByteString
-- ^ Path to templates
-> Initializer b (Heist b) ()
addTemplatesAt urlPrefix templateDir = do
- ts <- liftIO $ loadTemplates templateDir emptyTemplateState
+ ts <- liftIO $ loadTemplates templateDir mempty
>>= either error return
printInfo $ T.pack $ unwords
[ "...adding"
@@ -297,7 +297,7 @@ addTemplatesAt urlPrefix templateDir = do
------------------------------------------------------------------------------
modifyHeistTS' :: (Lens (Snaplet b) (Snaplet (Heist b)))
- -> (TemplateState (Handler b b) -> TemplateState (Handler b b))
+ -> (HeistState (Handler b b) -> HeistState (Handler b b))
-> Initializer b v ()
modifyHeistTS' heist f = do
_lens <- getLens
@@ -306,21 +306,21 @@ modifyHeistTS' heist f = do
------------------------------------------------------------------------------
modifyHeistTS :: (Lens b (Snaplet (Heist b)))
- -> (TemplateState (Handler b b) -> TemplateState (Handler b b))
+ -> (HeistState (Handler b b) -> HeistState (Handler b b))
-> Initializer b v ()
modifyHeistTS heist f = modifyHeistTS' (subSnaplet heist) f
------------------------------------------------------------------------------
withHeistTS' :: (Lens (Snaplet b) (Snaplet (Heist b)))
- -> (TemplateState (Handler b b) -> a)
+ -> (HeistState (Handler b b) -> a)
-> Handler b v a
withHeistTS' heist f = withTop' heist $ gets (f . _heistTS)
------------------------------------------------------------------------------
withHeistTS :: (Lens b (Snaplet (Heist b)))
- -> (TemplateState (Handler b b) -> a)
+ -> (HeistState (Handler b b) -> a)
-> Handler b v a
withHeistTS heist f = withHeistTS' (subSnaplet heist) f
@@ -391,7 +391,7 @@ heistServeSingle t =
------------------------------------------------------------------------------
heistLocal' :: (Lens (Snaplet b) (Snaplet (Heist b)))
- -> (TemplateState (Handler b b) -> TemplateState (Handler b b))
+ -> (HeistState (Handler b b) -> HeistState (Handler b b))
-> Handler b v a
-> Handler b v a
heistLocal' heist f m = do
@@ -404,7 +404,7 @@ heistLocal' heist f m = do
------------------------------------------------------------------------------
heistLocal :: (Lens b (Snaplet (Heist b)))
- -> (TemplateState (Handler b b) -> TemplateState (Handler b b))
+ -> (HeistState (Handler b b) -> HeistState (Handler b b))
-> Handler b v a
-> Handler b v a
heistLocal heist f m = heistLocal' (subSnaplet heist) f m

0 comments on commit 0d75768

Please sign in to comment.