[tutorial text, working on monoid stuff thomashartman1@gmail.com**20080621125351] hunk ./src/ControllerBasic.hs 7 - +import Data.Monoid hunk ./src/ControllerBasic.hs 17 +A HAppS Server is generally a list of ServerPartTs. When the wrapped functions are run, +either they result in NoHandle or a valid response. If there's a valid response, it gets +displayed. If NoHandle, control is passed to the next ServerPartT/handler in the list. +If all the handlers produce NoHandle as a result, the result is a 404. + hunk ./src/ControllerBasic.hs 37 -simpleHandlers = {- debugFilter -} [ +simpleHandlers = debugFilter [ hunk ./src/ControllerBasic.hs 43 - else noHandle, + else noHandle hunk ./src/ControllerBasic.hs 45 - h1,h2,hmulti - -- ,hsequence + , simplematch "1" + , simplematch "2" hunk ./src/ControllerBasic.hs 48 + -- RequestHandlerTs are monoids, + -- instance (Monad m) => Monoid (ServerPartT m a) + -- they can be added with mappend and sequenced with mconcat, + -- and have a "zero" or "empty" handler which results in a 404 page for any request. + -- The way "handler addition" works is... for h1 `mconcat` h2 ... + -- if h1 rq is anything other than NoHandle, return that. + -- if it is noHandle, return h2 rq + , mconcat [simplematch "3", simplematch "4"] hunk ./src/ControllerBasic.hs 57 - , exactdir "simpleRequestHandler2" [ msgToSp "simpleRequesthandler2" ] + -- the exactdir handler builder is more useful than simplematch + -- exactdir :: (Monad m) => String -> [ServerPartT m a] -> ServerPartT m a + -- given a url path (for the part of the path after the domain) and a list of handlers + -- exactdir will attempt to run the handlers against the request + -- if the url doesn't match but all the handlers produce NoHandle (or mempty) when run + -- control is passed to the next handler hunk ./src/ControllerBasic.hs 64 + -- zero handler using mempty from the monoid instance, and the same thing again spelled out explicitly + , exactdir "simplematch5" [mempty] + , exactdir "simplematch6" [ ServerPartT $ \rq -> WebT $ return NoHandle ] + + + , exactdir "simpleRequestHandler2" [ msgToSp "simpleRequesthandler2" ] hunk ./src/ControllerBasic.hs 92 - - - - - -- fileserve handles all possible requests, not that this is necessarily a good thing - -- , msgToSp "Sorry, we can't find that page." - hunk ./src/ControllerBasic.hs 94 -h1 = simplematch "1" -h2 = simplematch "2" -hmulti = multi [simplematch "3", simplematch "4"] -hsequence = sequence [simplematch "5",simplematch "6"] - +-- pretty much useless little server part constructor, for demo purposes +simplematch :: String -> TutHandler hunk ./src/ControllerBasic.hs 98 - if (traceMsg "ru: " ru) == ( traceMsg "sm: " $ "/simplematch" ++ u) - then ( ( return . toResponse ) ( "matched " ++ u) :: TutWebT ) - else noHandle + if ru == ("/simplematch" ++ u) + then ( return . toResponse ) ( "matched " ++ u) + else noHandle :: TutWebT hunk ./src/Misc.hs 61 - - - - - hunk ./templates/basic-url-handling.st 22 +
  • simplematch5
  • +
  • simplematch6
  • + addfile ./templates/main-function.st hunk ./templates/main-function.st 1 - +asdf hunk ./templates/start-tutorial.st 7 -

    Getting on with the tutorial proper, our first lesson explains how to do basic url handling.

    +

    Getting on with the tutorial proper, our first examines the main function in a HAppS program. hunk ./templates/start-tutorial.st 9 +

    The second lesson explains how to do basic url handling.

    hunk ./templates/start-tutorial.st 11 +

    More lessons are planned. This is a work in progress. Stay tuned.

    + +$!

    Lesson 2 is using templates !$ hunk ./templates/start-tutorial.st 15 +$!

    Lesson 3 is managing state

    !$ +