[cleaned up examples with MACID and HST Betty Diegel **20090324024734 Ignore-this: 706079bf5463e9b27cf91d29453e9416 ] hunk ./src/CounterState.hs 19 -incVal :: Update CounterState () -incVal = modify ( \( CounterState n ) -> CounterState ( n + 1 ) ) +incCount :: Update CounterState () +incCount = modify ( \( CounterState n ) -> CounterState ( n + 1 ) ) hunk ./src/CounterState.hs 22 -getVal :: Query CounterState Int -getVal = do +getCount :: Query CounterState Int +getCount = do hunk ./src/CounterState.hs 27 -$(mkMethods ''CounterState [ 'incVal, 'getVal ] ) +$(mkMethods ''CounterState [ 'incCount, 'getCount ] ) hunk ./src/main.hs 22 - -- hello world example: smartserver (Conf 8080 Nothing) "grub" (return "Hello World") stateProxy - smartserver (Conf 8080 Nothing) "grub" (simpleHandlers `mappend` counterHandler) stateProxy + smartserver (Conf 8080 Nothing) "grub" (simpleHandlers `mappend` handlerUsingMACID `mappend` handlerUsingMACIDAndHST) stateProxy + hunk ./src/main.hs 28 + hunk ./src/main.hs 34 -counterHandler :: ServerPartT IO Response -counterHandler = - exactdir "/test-counter" $ + +handlerUsingMACID :: ServerPartT IO Response +handlerUsingMACID = + exactdir "/test3" $ + liftIO $ do + count <- newCount + return . toResponse . HtmlString $ ( "Current count is: " ++ show count ) + + +handlerUsingMACIDAndHST :: ServerPartT IO Response +handlerUsingMACIDAndHST = + exactdir "/test4" $ hunk ./src/main.hs 48 - update IncVal - count <- query GetVal - let response = renderTemplateGroup templates [("counter", count)] "counter" - --return . toResponse . HtmlString $ ( "Current count is: " ++ show count ) + count <- newCount + let response = renderTemplateGroup templates [("count", count)] "counter" hunk ./src/main.hs 53 +newCount :: (MonadIO m) => m Int +newCount = liftIO $ do + update IncCount + query GetCount hunk ./templates/counter.st 1 -

Happstack Example using MACID and HStringTemplate

-

The current value of the counter is now: $ counter $ + +

Happstack example using MACID and HStringTemplate

+

The current value of the counter is now: $ count $ hunk ./templates/counter.st 5 +