Permalink
Browse files

Renamed wikiHandler -> wiki.

  • Loading branch information...
1 parent 4161f7f commit f213a5ac63423b16cd811c9cfff56c7206a40809 @jgm committed Aug 16, 2009
Showing with 15 additions and 9 deletions.
  1. +14 −8 Network/Gitit.hs
  2. +1 −1 gitit.hs
View
@@ -29,7 +29,7 @@ The following is a minimal standalone wiki program:
> createTemplateIfMissing conf
> createRepoIfMissing conf
> initializeGititState conf
-> simpleHTTP nullConf{port = 5001} $ wikiHandler conf
+> simpleHTTP nullConf{port = 5001} $ wiki conf
Here is a more complex example, which serves different wikis
under different paths, and uses a custom authentication scheme:
@@ -57,9 +57,9 @@ under different paths, and uses a custom authentication scheme:
>
> handlerFor :: Config -> WikiSpec -> ServerPart Response
> handlerFor conf (path', fstype, pagetype) = dir path' $
-> wikiHandler conf{ repositoryPath = path'
-> , repositoryType = fstype
-> , defaultPageType = pagetype}
+> wiki conf{ repositoryPath = path'
+> , repositoryType = fstype
+> , defaultPageType = pagetype}
>
> indexPage :: ServerPart Response
> indexPage = ok $ toResponse $
@@ -101,7 +101,7 @@ module Network.Gitit (
-- * Wiki handlers
, GititServerPart
, Handler
- , wikiHandler
+ , wiki
, reloadTemplates
, loginUserForm
)
@@ -118,8 +118,9 @@ import System.FilePath
import Prelude hiding (readFile)
import Codec.Binary.UTF8.String (decodeString)
-wikiHandler :: Config -> ServerPart Response
-wikiHandler conf = do
+-- | Happstack handler for a gitit wiki.
+wiki :: Config -> ServerPart Response
+wiki conf = do
let static = staticDir conf
let staticHandler = dir "_static" $ withExpiresHeaders $ msum
[ dir "css" $ fileServeStrict [] (static </> "css")
@@ -132,7 +133,7 @@ wikiHandler conf = do
if compressResponses conf
then compressedResponseFilter
else return ""
- staticHandler `mplus` (mapServerPartT (unpackReaderT ws) $ withUser conf $ msum handlers)
+ staticHandler `mplus` (runHandler ws $ withUser conf $ msum handlers)
wikiHandlers :: [Handler]
wikiHandlers =
@@ -180,11 +181,16 @@ wikiHandlers =
, createPage
]
+-- | Recompiles the gitit templates.
reloadTemplates :: ServerPart Response
reloadTemplates = do
liftIO $ recompilePageTemplate
ok $ toResponse "Page templates have been recompiled."
+-- | Converts a gitit Handler into a standard happstack ServerPart.
+runHandler :: WikiState -> Handler -> ServerPart Response
+runHandler ws = mapServerPartT (unpackReaderT ws)
+
unpackReaderT:: (Monad m)
=> c
-> (ReaderT c m) (Maybe ((Either b a), FilterFun b))
View
@@ -74,6 +74,6 @@ main = do
let serverConf = Conf { validator = Nothing, port = portNumber conf' }
-- start the server
simpleHTTP serverConf $ msum [
- wikiHandler conf'
+ wiki conf'
, dir "_reloadTemplates" reloadTemplates
]

0 comments on commit f213a5a

Please sign in to comment.