[Use Text.XHtml in some of the examples. bjorn@bringert.net**20060608053502] { hunk ./examples/cookie.hs 2 +import Text.XHtml hunk ./examples/cookie.hs 7 +firstTime :: CGI [Html] +firstTime = do setCounterCookie 1 + return [h1 << "Welcome!"] + +returnVisitor :: Int -> CGI [Html] +returnVisitor c = + do setCounterCookie (c + 1) + return [h1 << "Welcome back!", + p << ("I have seen you " ++ show c ++ " times before.")] + +cgiMain :: CGI CGIResult hunk ./examples/cookie.hs 19 - case mc of - Nothing -> do setCounterCookie 1 - output "Welcome!" - Just c -> do setCounterCookie (read c + 1) - output $ "Welcome back! You have been here " - ++ c ++ " times before." + h <- maybe firstTime (returnVisitor . read) mc + output $ renderHtml $ header << thetitle << "Cookie example" + +++ body << h hunk ./examples/cookie.hs 23 +main :: IO () hunk ./examples/upload.hs 10 +import Text.XHtml hunk ./examples/upload.hs 14 -cgiMain = do m <- getInputFilename "file" - case m of - Just n -> saveFile n - Nothing -> output form - hunk ./examples/upload.hs 15 - do - cont <- liftM fromJust $ getInputFPS "file" - let p = dir ++ "/" ++ basename n - liftIO $ BS.writeFile p cont - output $ "Saved as " ++ p ++ "." + do cont <- liftM fromJust $ getInputFPS "file" + let p = dir ++ "/" ++ basename n + liftIO $ BS.writeFile p cont + return $ paragraph << ("Saved as " +++ anchor ! [href p] << p +++ ".") + +fileForm = form ! [method "post", enctype "multipart/form-data"] + << [afile "file", submit "" "Upload"] hunk ./examples/upload.hs 23 -form = concat ["
", - "
", - "", - "
"] hunk ./examples/upload.hs 26 +cgiMain = + do mn <- getInputFilename "file" + h <- maybe (return fileForm) saveFile mn + output $ renderHtml $ header << thetitle << "Upload example" + +++ body << h + }