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  3f647d34df945113bb9c440b6adc8e47dac181a2 (commit)
      from  7a7136da40fe90f557d22aec3547deb8aec299a5 (commit)


Summary of changes:
 TODO                              |    3 ---
 project_template/hint/src/Site.hs |    2 +-
 src/Snap/Heist.hs                 |   23 ++++++++++++++++-------
 3 files changed, 17 insertions(+), 11 deletions(-)

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 3f647d34df945113bb9c440b6adc8e47dac181a2
Author: Carl Howells <[email protected]>
Date:   Sat Jun 26 20:00:07 2010 -0700

    Make the error case when rendering Heist templates more robust

diff --git a/TODO b/TODO
index 35bf76d..815bf69 100644
--- a/TODO
+++ b/TODO
@@ -1,9 +1,6 @@
 TODO
 ----
 
-Change Snap.Heist to create a fresh response and use finishWith, in
-the error case.  Not sure about the success case.
-
 Move Server out of the template projects into snap-server
 
 Handle local persistent state.
diff --git a/project_template/hint/src/Site.hs 
b/project_template/hint/src/Site.hs
index e9a9e24..cc55423 100644
--- a/project_template/hint/src/Site.hs
+++ b/project_template/hint/src/Site.hs
@@ -26,7 +26,7 @@ frontPage config = ifTop $ do
         ts' = bindStrings [ ("loadTime", loadS)
                           , ("renderTime", renderS)
                           ] ts
-    render ts' "index"
+    renderHtml ts' "index"
 
 
 staticResources :: Snap ()
diff --git a/src/Snap/Heist.hs b/src/Snap/Heist.hs
index fa4c674..c631d5e 100644
--- a/src/Snap/Heist.hs
+++ b/src/Snap/Heist.hs
@@ -3,21 +3,30 @@ module Snap.Heist where
 
 import qualified Data.ByteString.Char8 as S
 
+import           Snap.Iteratee
 import           Snap.Types
+
 import           Text.Templating.Heist
 
 
-render :: TemplateState Snap -> S.ByteString -> Snap ()
-render ts template = do
+renderHtml :: TemplateState Snap -> S.ByteString -> Snap ()
+renderHtml = render "text/html; charset=utf-8"
+
+
+render :: S.ByteString -> TemplateState Snap -> S.ByteString -> Snap ()
+render contentType ts template = do
     bytes <- renderTemplate ts template
     flip (maybe missingTemplate) bytes $ \x -> do
-        modifyResponse $ setContentType "text/html; charset=utf-8"
+        modifyResponse $ setContentType contentType
                        . setContentLength (fromIntegral $ S.length x)
         writeBS x
   where
     missingTemplate = do
         let msg = S.append "Unable to load template: " template
-        modifyResponse $ setContentType "text/plain; charset=utf-8"
-                       . setContentLength (fromIntegral $ S.length msg)
-                       . setResponseStatus 500 "Internal Server Error"
-        writeBS msg
+            rsp = setContentType "text/plain; charset=utf-8"
+                . setContentLength (fromIntegral $ S.length msg)
+                . setResponseStatus 500 "Internal Server Error"
+                . modifyResponseBody (>. enumBS msg)
+                $ emptyResponse
+
+        finishWith rsp
-----------------------------------------------------------------------


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

Reply via email to