gitit-0.10.3.1: Wiki using happstack, git or darcs, and pandoc.

Safe Haskell | None

Network.Gitit

Contents

- Wiki handlers
- Initialization
- Configuration
- Types
- Tools for building handlers

Description

Functions for embedding a gitit wiki into a Happstack application.

The following is a minimal standalone wiki program:

     import Network.Gitit
     import Happstack.Server.SimpleHTTP

     main = do
       conf <- getDefaultConfig
       createStaticIfMissing conf
       createTemplateIfMissing conf
       createRepoIfMissing conf
       initializeGititState 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:

     import Network.Gitit
     import Control.Monad
     import Text.XHtml hiding (dir)
     import Happstack.Server.SimpleHTTP

     type WikiSpec = (String, FileStoreType, PageType)

     wikis = [ ("markdownWiki", Git, Markdown)
             , ("latexWiki", Darcs, LaTeX) ]

     -- custom authentication
     myWithUser :: Handler -> Handler
     myWithUser handler = do
       -- replace the following with a function that retrieves
       -- the logged in user for your happstack app:
       user <- return "testuser"
       localRq (setHeader "REMOTE_USER" user) handler

     myAuthHandler = msum
       [ dir "_login"  $ seeOther "/your/login/url"  $ toResponse ()
       , dir "_logout" $ seeOther "/your/logout/url" $ toResponse () ]

     handlerFor :: Config -> WikiSpec -> ServerPart Response
     handlerFor conf (path', fstype, pagetype) = dir path' $
       wiki conf{ repositoryPath = path'
                , repositoryType = fstype
                , defaultPageType = pagetype}

     indexPage :: ServerPart Response
     indexPage = ok $ toResponse $
       (p << "Wiki index") +++
       ulist << map (\(path', _, _) -> li << hotlink (path' ++ "/") << path') wikis

     main = do
       conf <- getDefaultConfig
       let conf' = conf{authHandler = myAuthHandler, withUser = myWithUser}
       forM wikis $ \(path', fstype, pagetype) -> do
         let conf'' = conf'{ repositoryPath = path'
                           , repositoryType = fstype
                           , defaultPageType = pagetype
                           }
         createStaticIfMissing conf''
         createRepoIfMissing conf''
       createTemplateIfMissing conf'
       initializeGititState conf'
       simpleHTTP nullConf{port = 5001} $
         (nullDir >> indexPage) `mplus` msum (map (handlerFor conf') wikis)

Synopsis

- wiki :: Config -> ServerPart Response
- reloadTemplates :: ServerPart Response
- runHandler :: WikiState -> Handler -> ServerPart Response
- module Network.Gitit.Initialize
- module Network.Gitit.Config
- loginUserForm :: Handler
- module Network.Gitit.Types
- module Network.Gitit.Framework
- module Network.Gitit.Layout
- module Network.Gitit.ContentTransformer
- stringToPage :: Config -> String -> String -> Page
- pageToString :: Config -> Page -> String
- readCategories :: FilePath -> IO [String]
- getFileStore :: GititServerPart FileStore
- getUser :: String -> GititServerPart (Maybe User)
- getConfig :: GititServerPart Config
- queryGititState :: MonadIO m => (GititState -> a) -> m a
- updateGititState :: MonadIO m => (GititState -> GititState) -> m ()

# Wiki handlers

wiki :: Config -> ServerPart Response

Happstack handler for a gitit wiki.

reloadTemplates :: ServerPart Response

Recompiles the gitit templates.

runHandler :: WikiState -> Handler -> ServerPart Response

Converts a gitit Handler into a standard happstack ServerPart.

# Initialization

module Network.Gitit.Initialize

# Configuration

module Network.Gitit.Config

loginUserForm :: Handler

# Types

module Network.Gitit.Types

# Tools for building handlers

module Network.Gitit.Framework

module Network.Gitit.Layout

module Network.Gitit.ContentTransformer

stringToPage :: Config -> String -> String -> Page

Read a string (the contents of a page file) and produce a Page object, using defaults except when overridden by metadata.

pageToString :: Config -> Page -> String

Write a string (the contents of a page file) corresponding to a Page object, using explicit metadata only when needed.

readCategories :: FilePath -> IO [String]

Read categories from metadata strictly.

getFileStore :: GititServerPart FileStore

getUser :: String -> GititServerPart (Maybe User)

getConfig :: GititServerPart Config

queryGititState :: MonadIO m => (GititState -> a) -> m a

updateGititState :: MonadIO m => (GititState -> GititState) -> m ()