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  81af465e7b13c51af771748d5e7d92d21c0d5e49 (commit)
      from  202ec897c93d8c40a2538c140ba66b1e4c06efaa (commit)


Summary of changes:
 project_template/hint/resources/templates/echo.tpl |   14 ++++++
 .../hint/resources/templates/index.tpl             |    6 ++
 project_template/hint/src/Site.hs                  |   49 ++++++++++++++++---
 snap.cabal                                         |    1 +
 4 files changed, 62 insertions(+), 8 deletions(-)
 create mode 100644 project_template/hint/resources/templates/echo.tpl

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 81af465e7b13c51af771748d5e7d92d21c0d5e49
Author: Carl Howells <[email protected]>
Date:   Thu Jul 1 17:57:47 2010 -0700

    Expand the hint template site a bit, and document it better

diff --git a/project_template/hint/resources/templates/echo.tpl 
b/project_template/hint/resources/templates/echo.tpl
new file mode 100644
index 0000000..a9a3181
--- /dev/null
+++ b/project_template/hint/resources/templates/echo.tpl
@@ -0,0 +1,14 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
+<html xmlns="http://www.w3.org/1999/xhtml";>
+  <head>
+    <title>Echo Page</title>
+  </head>
+  <body>
+    <div id="content">
+      <h1>Is there an echo in here?</h1>
+    </div>
+    <p>You wanted me to say this?</p>
+    <p>"<message/>"</p>
+    <p><a href="/">Return</a></p>
+  </body>
+</html>
diff --git a/project_template/hint/resources/templates/index.tpl 
b/project_template/hint/resources/templates/index.tpl
index ee70bc2..c643d16 100644
--- a/project_template/hint/resources/templates/index.tpl
+++ b/project_template/hint/resources/templates/index.tpl
@@ -12,6 +12,12 @@
         <a href="http://snapframework.com/docs/tutorials/heist";>Heist</a>
         and the <a href="http://snapframework.com/";>Snap</a> web framework.
       </p>
+      <p>
+        Echo test:
+        <a href="/echo/cats">cats</a>
+        <a href="/echo/dogs">dogs</a>
+        <a href="/echo/fish">fish</a>
+      </p>
       <table id="info">
         <tr>
           <td>Config generated at:</td>
diff --git a/project_template/hint/src/Site.hs 
b/project_template/hint/src/Site.hs
index 1d143ba..5d122a5 100644
--- a/project_template/hint/src/Site.hs
+++ b/project_template/hint/src/Site.hs
@@ -1,23 +1,31 @@
 {-# LANGUAGE OverloadedStrings #-}
 module Site where
 
+------------------------------------------------------------------------------
 import           AppState
 
-import           Control.Arrow ((&&&))
-import           Control.Monad (msum)
-import           Control.Monad.Trans (liftIO)
+import           Control.Applicative
+import           Control.Arrow
+import           Control.Monad.Trans
 
 import qualified Data.ByteString.Char8 as S
+import           Data.Maybe
 import           Data.Time.Clock
 
 import           Snap.Heist
 
-import           Snap.Util.FileServe (fileServe)
+import           Snap.Util.FileServe
 import           Snap.Types
 
 import           Text.Templating.Heist
 
 
+------------------------------------------------------------------------------
+-- Renders the front page of the sample site.
+--
+-- The 'ifTop' is required to limit this to the top of a route.
+-- Otherwise, the way the route table is currently set up, this action
+-- would be given every request.
 frontPage :: StateSnap ()
 frontPage = ifTop $ do
     time <- liftIO getCurrentTime
@@ -30,12 +38,37 @@ frontPage = ifTop $ do
     renderHtml ts' "index"
 
 
+------------------------------------------------------------------------------
+-- Renders the echo page
+echo :: StateSnap ()
+echo = do
+    message <- fromMaybe "" <$> getParam "stuff"
+    ts <- asks templateState
+    let ts' = bindStrings [ ("message", message) ] ts
+    renderHtml ts' "echo"
+
+
+------------------------------------------------------------------------------
+-- serves static resources
 staticResources :: StateSnap ()
 staticResources = fileServe "resources/static"
 
 
-site :: AppState -> Snap ()
-site = runStateSnap $ do
-    msum [ frontPage
-         , staticResources
+------------------------------------------------------------------------------
+-- contains the routing table.  Be aware that routes are prefix
+-- matches.  The 'frontPage' action contains logic to only render if
+-- it's served from exactly "/"
+routes :: StateSnap ()
+routes = route
+         [ ("/", frontPage)
+         , ("/echo/:stuff", echo)
          ]
+
+
+------------------------------------------------------------------------------
+-- The main entry point handler.  It converts from StateSnap to Snap,
+-- and sets the first-pass resolution rules.  In particular, the logic
+-- that static resources take priority over routes comes from this
+-- function.
+site :: AppState -> Snap ()
+site = runStateSnap $ staticResources <|> routes
diff --git a/snap.cabal b/snap.cabal
index 9bd337f..a7f2d73 100644
--- a/snap.cabal
+++ b/snap.cabal
@@ -34,6 +34,7 @@ extra-source-files:
   project_template/hint/log/access.log,
   project_template/hint/log/error.log,
   project_template/hint/resources/static/screen.css,
+  project_template/hint/resources/templates/echo.tpl,
   project_template/hint/resources/templates/index.tpl,
   project_template/hint/src/AppState.hs,
   project_template/hint/src/Main.hs,
-----------------------------------------------------------------------


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

Reply via email to