This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "snap".

The branch, master has been updated
       via  1bd7d9d8dacc837ee5c25fd0145f8f2d0e930969 (commit)
       via  16ce56b7a2df005838b2e585afe2cfdd45d5b2fe (commit)
      from  be5d4eeb3571cafb8ee35a55046da0fa17e26d3f (commit)


Summary of changes:
 snap.cabal                       |    5 +--
 src/Snap/Extension/Heist.hs      |   14 +++++++++--
 src/Snap/Extension/Heist/Impl.hs |   44 ++++++++++++++++++++++++-------------
 src/Snap/Heist.hs                |   44 --------------------------------------
 4 files changed, 41 insertions(+), 66 deletions(-)
 delete mode 100644 src/Snap/Heist.hs

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 1bd7d9d8dacc837ee5c25fd0145f8f2d0e930969
Author: Mighty Byte <[email protected]>
Date:   Sat Feb 5 12:43:02 2011 -0500

    Updated to work with Heist 0.5.

diff --git a/snap.cabal b/snap.cabal
index 69b9d29..e83c7a4 100644
--- a/snap.cabal
+++ b/snap.cabal
@@ -54,7 +54,7 @@ Library
     filepath >= 1.1 && <1.3,
     MonadCatchIO-transformers >= 0.2.1 && < 0.3,
     snap-core == 0.4.*,
-    heist >= 0.4 && < 0.5,
+    heist >= 0.5 && < 0.6,
     hint >= 0.3.3.1 && < 0.4,
     template-haskell >= 2.3 && < 2.6,
     time >= 1.0 && < 1.3
diff --git a/src/Snap/Extension/Heist.hs b/src/Snap/Extension/Heist.hs
index bd9a719..470c3c9 100644
--- a/src/Snap/Extension/Heist.hs
+++ b/src/Snap/Extension/Heist.hs
@@ -30,6 +30,7 @@ module Snap.Extension.Heist
 import           Control.Applicative
 import           Data.ByteString (ByteString)
 import qualified Data.ByteString.Char8 as B
+import           Data.Text (Text)
 import           Snap.Types
 import           Snap.Util.FileServe
 import           Text.Templating.Heist
@@ -72,7 +73,7 @@ class (Monad n, MonadSnap m) => MonadHeist n m | m -> n where
 renderWithSplices 
   :: (MonadHeist n m) 
   => ByteString                 -- ^ Template to render
-  -> [(ByteString, Splice n)]   -- ^ Splice mapping
+  -> [(Text, Splice n)]   -- ^ Splice mapping
   -> m ()
 renderWithSplices t sps = heistLocal bsps $ render t
   where bsps = bindSplices sps
diff --git a/src/Snap/Extension/Heist/Impl.hs b/src/Snap/Extension/Heist/Impl.hs
index ba1c5a3..47e9932 100644
--- a/src/Snap/Extension/Heist/Impl.hs
+++ b/src/Snap/Extension/Heist/Impl.hs
@@ -63,7 +63,9 @@ module Snap.Extension.Heist.Impl
 
 import           Control.Concurrent.MVar
 import           Control.Monad.Reader
-import qualified Data.ByteString as B
+import           Data.ByteString (ByteString)
+import           Data.Maybe
+import           Data.Text (Text)
 import           Snap.Extension
 import           Snap.Extension.Heist
 import           Snap.Types
@@ -141,15 +143,13 @@ instance MonadSnap m => InitializerState (HeistState m) 
where
 
 ------------------------------------------------------------------------------
 instance HasHeistState (SnapExtend s) s => MonadHeist (SnapExtend s) 
(SnapExtend s) where
-    render = renderAs "text/html; charset=utf-8"
+    render t = do
+        hs <- asks getHeistState
+        renderHelper hs Nothing t
 
     renderAs c t = do
-        (HeistState _ _ tsMVar _ modifier) <- asks getHeistState
-        ts <- liftIO $ fmap modifier $ readMVar tsMVar
-        renderTemplate ts t >>= maybe pass (\ctnt -> do
-            modifyResponse $ setContentType c
-            modifyResponse $ setContentLength (fromIntegral $ B.length ctnt)
-            writeBS ctnt)
+        hs <- asks getHeistState
+        renderHelper hs (Just c) t
 
     heistLocal f = local $ modifyHeistState $ \s ->
         s { _modifier = f . _modifier s }
@@ -157,21 +157,29 @@ instance HasHeistState (SnapExtend s) s => MonadHeist 
(SnapExtend s) (SnapExtend
 
 ------------------------------------------------------------------------------
 instance HasHeistState m s => MonadHeist m (ReaderT s m) where
-    render = renderAs "text/html; charset=utf-8"
+    render t = ReaderT $ \s -> renderHelper (getHeistState s) Nothing t
 
-    renderAs c t = ReaderT $ \s -> do
-        let (HeistState _ _ tsMVar _ modifier) = getHeistState s
-        ts <- liftIO $ fmap modifier $ readMVar tsMVar
-        renderTemplate ts t >>= maybe pass (\ctnt -> do
-            modifyResponse $ setContentType c
-            modifyResponse $ setContentLength (fromIntegral $ B.length ctnt)
-            writeBS ctnt)
+    renderAs c t = ReaderT $ \s -> renderHelper (getHeistState s) (Just c) t
 
     heistLocal f = local $ modifyHeistState $ \s ->
         s { _modifier = f . _modifier s }
 
 
 ------------------------------------------------------------------------------
+renderHelper :: (MonadSnap m)
+             => HeistState m
+             -> Maybe MIMEType
+             -> ByteString
+             -> m ()
+renderHelper hs c t = do
+    let (HeistState _ _ tsMVar _ modifier) = hs
+    ts <- liftIO $ fmap modifier $ readMVar tsMVar
+    renderTemplate ts t >>= maybe pass (\(b,mime) -> do
+        modifyResponse $ setContentType $ fromMaybe mime c
+        writeBuilder b)
+
+
+------------------------------------------------------------------------------
 -- | Take your application's state and register these splices in it so
 -- that you don't have to re-list them in every handler. Should be called from
 -- inside your application's 'Initializer'.
@@ -193,7 +201,7 @@ registerSplices
   :: (MonadSnap m, MonadIO n) 
   => HeistState m   
   -- ^ Heist state that you are going to embed in your application's state.
-  -> [(B.ByteString, Splice m)]   
+  -> [(Text, Splice m)]   
   -- ^ Your splices.
   -> n ()
 registerSplices s sps = liftIO $ do
commit 16ce56b7a2df005838b2e585afe2cfdd45d5b2fe
Author: Chris Smith <[email protected]>
Date:   Sat Feb 5 10:12:47 2011 -0700

    Clean up interface

diff --git a/snap.cabal b/snap.cabal
index 0c8ebd4..69b9d29 100644
--- a/snap.cabal
+++ b/snap.cabal
@@ -38,8 +38,7 @@ Library
     Snap.Extension.Heist.Impl,
     Snap.Extension.Loader.Devel,
     Snap.Extension.Server,
-    Snap.Extension,
-    Snap.Heist
+    Snap.Extension
 
   other-modules:
     Snap.Extension.Loader.Devel.Evaluator,
diff --git a/src/Snap/Extension/Heist.hs b/src/Snap/Extension/Heist.hs
index 0fa7b7e..bd9a719 100644
--- a/src/Snap/Extension/Heist.hs
+++ b/src/Snap/Extension/Heist.hs
@@ -1,5 +1,6 @@
+{-# LANGUAGE OverloadedStrings      #-}
 {-# LANGUAGE FunctionalDependencies #-}
-{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE MultiParamTypeClasses  #-}
 
 {-|
 
@@ -28,7 +29,9 @@ module Snap.Extension.Heist
 
 import           Control.Applicative
 import           Data.ByteString (ByteString)
+import qualified Data.ByteString.Char8 as B
 import           Snap.Types
+import           Snap.Util.FileServe
 import           Text.Templating.Heist
 
 
@@ -40,6 +43,10 @@ class (Monad n, MonadSnap m) => MonadHeist n m | m -> n where
     -- this returns 'empty'.
     render     :: ByteString -> m ()
 
+    -- | Renders a template as the given content type.  If the given template
+    -- is not found, this returns 'empty'.
+    renderAs   :: ByteString -> ByteString -> m ()
+
     -- | 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:
@@ -50,7 +57,7 @@ class (Monad n, MonadSnap m) => MonadHeist n m | m -> n where
     -- | Analogous to 'fileServe'. If the template specified in the request
     -- path is not found, it returns 'empty'.
     heistServe :: m ()
-    heistServe = fmap rqPathInfo getRequest >>= render
+    heistServe = ifTop (render "index") <|> (render . B.pack =<< getSafePath)
 
     -- | Analogous to 'fileServeSingle'. If the given template is not found,
     -- this throws an error.
diff --git a/src/Snap/Extension/Heist/Impl.hs b/src/Snap/Extension/Heist/Impl.hs
index 9b58c9b..ba1c5a3 100644
--- a/src/Snap/Extension/Heist/Impl.hs
+++ b/src/Snap/Extension/Heist/Impl.hs
@@ -141,13 +141,15 @@ instance MonadSnap m => InitializerState (HeistState m) 
where
 
 ------------------------------------------------------------------------------
 instance HasHeistState (SnapExtend s) s => MonadHeist (SnapExtend s) 
(SnapExtend s) where
-    render t     = do
+    render = renderAs "text/html; charset=utf-8"
+
+    renderAs c t = do
         (HeistState _ _ tsMVar _ modifier) <- asks getHeistState
         ts <- liftIO $ fmap modifier $ readMVar tsMVar
-        renderTemplate ts t >>= maybe pass (\html -> do
-            modifyResponse $ setContentType "text/html; charset=utf-8"
-            modifyResponse $ setContentLength (fromIntegral $ B.length html)
-            writeBS html)
+        renderTemplate ts t >>= maybe pass (\ctnt -> do
+            modifyResponse $ setContentType c
+            modifyResponse $ setContentLength (fromIntegral $ B.length ctnt)
+            writeBS ctnt)
 
     heistLocal f = local $ modifyHeistState $ \s ->
         s { _modifier = f . _modifier s }
@@ -155,13 +157,15 @@ instance HasHeistState (SnapExtend s) s => MonadHeist 
(SnapExtend s) (SnapExtend
 
 ------------------------------------------------------------------------------
 instance HasHeistState m s => MonadHeist m (ReaderT s m) where
-    render t     = ReaderT $ \s -> do
+    render = renderAs "text/html; charset=utf-8"
+
+    renderAs c t = ReaderT $ \s -> do
         let (HeistState _ _ tsMVar _ modifier) = getHeistState s
         ts <- liftIO $ fmap modifier $ readMVar tsMVar
-        renderTemplate ts t >>= maybe pass (\html -> do
-            modifyResponse $ setContentType "text/html; charset=utf-8"
-            modifyResponse $ setContentLength (fromIntegral $ B.length html)
-            writeBS html)
+        renderTemplate ts t >>= maybe pass (\ctnt -> do
+            modifyResponse $ setContentType c
+            modifyResponse $ setContentLength (fromIntegral $ B.length ctnt)
+            writeBS ctnt)
 
     heistLocal f = local $ modifyHeistState $ \s ->
         s { _modifier = f . _modifier s }
diff --git a/src/Snap/Heist.hs b/src/Snap/Heist.hs
deleted file mode 100644
index e889a91..0000000
--- a/src/Snap/Heist.hs
+++ /dev/null
@@ -1,44 +0,0 @@
-{-# LANGUAGE OverloadedStrings #-}
--- | This module contains convenience functions for helping render
--- Heist templates from Snap.
-module Snap.Heist where
-
-------------------------------------------------------------------------------
-import           Control.Applicative
-import           Data.ByteString.Char8 (ByteString)
-import qualified Data.ByteString.Char8 as B
-import           Snap.Types
-import           Snap.Util.FileServe
-import           Text.Templating.Heist
-
-
-------------------------------------------------------------------------------
--- | This is a convenience function.  It calls 'render' with the
--- content type set to @text/html; charset=utf-8@.
-renderHtml :: (MonadSnap m) => TemplateState m -> ByteString -> m ()
-renderHtml = render "text/html; charset=utf-8"
-
-
-------------------------------------------------------------------------------
--- | Renders a template with the provided content type.  If the
--- template cannot be loaded, 'pass' is called and the next handler is tried.
-render :: (MonadSnap m)
-       => ByteString      -- ^ the content type to include in the response
-       -> TemplateState m -- ^ the TemplateState that contains the template
-       -> ByteString      -- ^ the name of the template
-       -> m ()
-render contentType ts template = do
-    bytes <- renderTemplate ts template
-    flip (maybe pass) bytes $ \x -> do
-        modifyResponse $ setContentType contentType
-                       . setContentLength (fromIntegral $ B.length x)
-        writeBS x
-
-
-------------------------------------------------------------------------------
--- | Handles the rendering of any template in TemplateState.
-handleAllTemplates :: (MonadSnap m)
-                   => TemplateState m -> m ()
-handleAllTemplates ts =
-    ifTop (renderHtml ts "index") <|>
-    (renderHtml ts . B.pack =<< getSafePath)
-----------------------------------------------------------------------


hooks/post-receive
-- 
snap
_______________________________________________
Snap mailing list
[email protected]
http://mailman-mail5.webfaction.com/listinfo/snap

Reply via email to