mysnapsession-example 0.3.1 → 0.4
raw patch · 3 files changed
+44/−38 lines, 3 filesdep +textdep ~heistdep ~mysnapsessiondep ~snap
Dependencies added: text
Dependency ranges changed: heist, mysnapsession, snap, snap-core, snap-server
Files
- animalgame/src/Site.hs +30/−25
- clientcount/src/Site.hs +2/−2
- mysnapsession-example.cabal +12/−11
animalgame/src/Site.hs view
@@ -2,23 +2,25 @@ module Site (site) where -import Paths_mysnapsession_example+import Paths_mysnapsession_example -import Data.ByteString.Char8 (ByteString)-import Control.Applicative-import Control.Monad-import Control.Monad.Trans-import Snap.Extension.Heist-import Snap.Extension.Session-import Snap.Dialogues-import Snap.Util.FileServe-import Snap.Types-import Text.Templating.Heist+import Data.ByteString.Char8 (ByteString)+import Data.Text (Text)+import qualified Data.Text.Encoding as T+import Control.Applicative+import Control.Monad+import Control.Monad.Trans+import Snap.Extension.Heist+import Snap.Extension.Session+import Snap.Dialogues+import Snap.Util.FileServe+import Snap.Types+import Text.Templating.Heist -import Application+import Application -data DiKey = Answer ByteString- | Question ByteString DiKey DiKey+data DiKey = Answer Text+ | Question Text DiKey DiKey startingKey :: DiKey startingKey = Answer "elephant"@@ -49,55 +51,58 @@ rulePage :: MonadHeist n m => Dlg m () rulePage = showPage build parse where- build t = heistLocal (bindStrings [("dlgid", t)]) $ render "rules"+ build t = heistLocal (bindStrings [("dlgid", T.decodeUtf8 t)]) $ render "rules" parse = return () conclusionPage :: MonadHeist n m => Dlg m () conclusionPage = showPage build parse where- build t = heistLocal (bindStrings [("dlgid", t)]) $ render "conclusion"+ build t = heistLocal (bindStrings [("dlgid", T.decodeUtf8 t)]) $ render "conclusion" parse = return () goAgainPage :: MonadHeist n m => Dlg m Bool goAgainPage = showPage build parse where- build t = heistLocal (bindStrings [("dlgid", t)]) $ render "goAgain"+ build t = heistLocal (bindStrings [("dlgid", T.decodeUtf8 t)]) $ render "goAgain" parse = do p <- getParam "answer" case p of Just "yes" -> return True _ -> return False -guessPage :: MonadHeist n m => ByteString -> Dlg m Bool+guessPage :: MonadHeist n m => Text -> Dlg m Bool guessPage animal = showPage build parse where build t = heistLocal (bindStrings- [("dlgid", t), ("animal", animal)]) $ render "guess"+ [("dlgid", T.decodeUtf8 t),+ ("animal", animal)]) $ render "guess" parse = do p <- getParam "answer" case p of Just "yes" -> return True _ -> return False -questionPage :: MonadHeist n m => ByteString -> Dlg m Bool+questionPage :: MonadHeist n m => Text -> Dlg m Bool questionPage q = showPage build parse where build t = heistLocal (bindStrings- [("dlgid", t), ("question", q)]) $ render "question"+ [("dlgid", T.decodeUtf8 t),+ ("question", q)]) $ render "question" parse = do p <- getParam "answer" case p of Just "yes" -> return True _ -> return False detailsPage :: MonadHeist n m- => ByteString- -> Dlg m (ByteString, ByteString, Bool)+ => Text+ -> Dlg m (Text, Text, Bool) detailsPage oldAnimal = showPage build parse where build t = heistLocal (bindStrings- [("dlgid", t), ("oldAnimal", oldAnimal)]) $ render "details"+ [("dlgid", T.decodeUtf8 t),+ ("oldAnimal", oldAnimal)]) $ render "details" parse = do newAnimal <- getParam "newAnimal" >>= maybe mzero return newQuestion <- getParam "question" >>= maybe mzero return answerStr <- getParam "answer" >>= maybe mzero return let answer = case answerStr of "yes" -> True _ -> False- return (newAnimal, newQuestion, answer)+ return (T.decodeUtf8 newAnimal, T.decodeUtf8 newQuestion, answer) site :: App () site = do
clientcount/src/Site.hs view
@@ -12,7 +12,7 @@ import Snap.Types import Text.Templating.Heist -import qualified Data.ByteString.Char8 as B+import qualified Data.Text as T import Application @@ -20,7 +20,7 @@ index = do i <- getSession setSession (i+1)- heistLocal (bindString "num" (B.pack $ show i)) $ render "index"+ heistLocal (bindString "num" (T.pack $ show i)) $ render "index" site :: App () site = do
mysnapsession-example.cabal view
@@ -1,5 +1,5 @@ Name: mysnapsession-example-Version: 0.3.1+Version: 0.4 Synopsis: Example projects using mysnapsession Description: This is a collection of simple web applications that use the mysnapsession package for stateful HTTP.@@ -29,12 +29,13 @@ Build-depends: base >= 4 && < 5, bytestring >= 0.9.1 && < 0.10,- heist >= 0.4 && < 0.5,+ heist >= 0.5 && < 0.6, mtl >= 2 && < 3,- snap >= 0.3 && < 0.4,- snap-core >= 0.3 && < 0.4,- snap-server >= 0.3 && <0.4,- mysnapsession == 0.3.1,+ snap >= 0.4 && < 0.5,+ snap-core >= 0.4 && < 0.5,+ snap-server >= 0.4 && <0.5,+ text >= 0.11 && < 0.12,+ mysnapsession == 0.4, clientsession == 0.4.* Ghc-options: -threaded -Wall -fwarn-tabs -funbox-strict-fields@@ -48,13 +49,13 @@ Build-depends: base >= 4 && < 5, bytestring >= 0.9.1 && < 0.10,- heist >= 0.4 && < 0.5,+ heist >= 0.5 && < 0.6, mtl >= 2 && < 3,- snap >= 0.3 && < 0.4,- snap-core >= 0.3 && < 0.4,- snap-server >= 0.3 && <0.4,+ snap >= 0.4 && < 0.5,+ snap-core >= 0.4 && < 0.5,+ snap-server >= 0.4 && <0.5, time >= 1.1 && < 1.3,- mysnapsession == 0.3.*+ mysnapsession == 0.4 Ghc-options: -threaded -Wall -fwarn-tabs -funbox-strict-fields -fno-warn-orphans