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  c3e685c6a26015786308e188f645742cb9efbae5 (commit)
      from  facdc93bf63358f3e0e8004300ed48ffe2563496 (commit)


Summary of changes:
 project_template/hint/src/Glue.hs |   25 +++++++++++++++++++++++++
 project_template/hint/src/Site.hs |   10 +++-------
 snap.cabal                        |    1 +
 3 files changed, 29 insertions(+), 7 deletions(-)
 create mode 100644 project_template/hint/src/Glue.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 c3e685c6a26015786308e188f645742cb9efbae5
Author: Carl Howells <[email protected]>
Date:   Tue Jun 22 16:41:19 2010 -0700

    Keep part of the previous Glue.hs

diff --git a/project_template/hint/src/Glue.hs 
b/project_template/hint/src/Glue.hs
new file mode 100644
index 0000000..d7b6f7b
--- /dev/null
+++ b/project_template/hint/src/Glue.hs
@@ -0,0 +1,25 @@
+{-# LANGUAGE OverloadedStrings #-}
+module Glue where
+
+import qualified Data.ByteString.Char8 as S
+
+import           Snap.Types
+import           Text.Templating.Heist
+
+
+render :: TemplateState Snap -> S.ByteString -> Snap ()
+render ts template = do
+    bytes <- renderTemplate ts template
+    flip (maybe missingTemplate) bytes $ \x -> do
+        modifyResponse $ setContentType "text/html; charset=utf-8"
+                       . 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
+
+
diff --git a/project_template/hint/src/Site.hs 
b/project_template/hint/src/Site.hs
index e8289b7..056d9a6 100644
--- a/project_template/hint/src/Site.hs
+++ b/project_template/hint/src/Site.hs
@@ -9,6 +9,8 @@ import           Control.Monad.Trans (liftIO)
 import qualified Data.ByteString.Char8 as S
 import           Data.Time.Clock
 
+import           Glue
+
 import           Snap.Util.FileServe (fileServe)
 import           Snap.Types
 
@@ -17,8 +19,6 @@ import           Text.Templating.Heist
 
 frontPage :: Config -> Snap ()
 frontPage config = ifTop $ do
-    modifyResponse $ setContentType "text/html; charset=utf-8"
-
     time <- liftIO getCurrentTime
 
     let [loadS, renderS] = map (S.pack . show) [loadTime config, time]
@@ -26,11 +26,7 @@ frontPage config = ifTop $ do
         ts' = bindStrings [ ("loadTime", loadS)
                           , ("renderTime", renderS)
                           ] ts
-
-    Just rendered <- renderTemplate ts' "index"
-    writeBS rendered
-    let len = fromIntegral . S.length $ rendered
-    modifyResponse . setContentLength $ len
+    render ts' "index"
 
 
 staticResources :: Snap ()
diff --git a/snap.cabal b/snap.cabal
index 00410d7..914873a 100644
--- a/snap.cabal
+++ b/snap.cabal
@@ -36,6 +36,7 @@ extra-source-files:
   project_template/hint/resources/static/screen.css,
   project_template/hint/resources/templates/index.tpl,
   project_template/hint/src/Config.hs,
+  project_template/hint/src/Glue.hs,
   project_template/hint/src/Main.hs,
   project_template/hint/src/Site.hs
 
-----------------------------------------------------------------------


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

Reply via email to