Browse files

Moved initializeGititState to Initialize.

Also folded user file reading and plugin loading into it.
  • Loading branch information...
1 parent a546834 commit ecd8882b44be8cc298ef7fb68edbbe11e1febaf3 @jgm committed Jun 16, 2009
Showing with 23 additions and 26 deletions.
  1. +0 −3 Network/Gitit.hs
  2. +22 −1 Network/Gitit/Initialize.hs
  3. +0 −10 Network/Gitit/State.hs
  4. +1 −12 gitit.hs
View
3 Network/Gitit.hs
@@ -25,8 +25,6 @@ module Network.Gitit ( initializeGititState
, User(..)
, Cache(..)
, emptyCache
- , loadPlugin
- , loadPlugins
, wikiHandler
, readMimeTypesFile
, createRepoIfMissing
@@ -38,7 +36,6 @@ import Network.Gitit.Types
import Network.Gitit.Framework
import Network.Gitit.State
import Network.Gitit.Server
-import Network.Gitit.Plugins (loadPlugin, loadPlugins)
import Network.Gitit.Handlers
import Network.Gitit.Initialize
import Network.Gitit.Config (readMimeTypesFile, getDefaultConfig)
View
23 Network/Gitit/Initialize.hs
@@ -16,12 +16,18 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
{- Functions for initializing a Gitit wiki.
-}
-module Network.Gitit.Initialize ( createStaticIfMissing, createRepoIfMissing, createTemplateIfMissing )
+module Network.Gitit.Initialize ( initializeGititState
+ , createStaticIfMissing
+ , createRepoIfMissing
+ , createTemplateIfMissing )
where
import System.FilePath ((</>), (<.>), takeExtension)
import Data.FileStore
+import qualified Data.Map as M
import Network.Gitit.Types
+import Network.Gitit.State
import Network.Gitit.Framework
+import Network.Gitit.Plugins
import Paths_gitit (getDataFileName)
import Control.Exception (throwIO, try)
import System.Directory (copyFile, createDirectoryIfMissing, doesDirectoryExist, getDirectoryContents, doesFileExist)
@@ -32,6 +38,21 @@ import Text.Pandoc
import Text.Pandoc.Shared (HTMLMathMethod(..))
import System.Log.Logger (logM, Priority(..))
+-- | Initialize Gitit State.
+initializeGititState :: FilePath
+ -> [FilePath]
+ -> IO ()
+initializeGititState userFile' pluginModules' = do
+ plugins' <- loadPlugins pluginModules'
+ userFileExists <- doesFileExist userFile'
+ users' <- if userFileExists
+ then liftM (M.fromList . read) $ readFile userFile'
+ else return M.empty
+ updateAppState $ \s -> s { sessions = Sessions M.empty
+ , users = users'
+ , cache = emptyCache
+ , plugins = plugins' }
+
-- | Create template file if it doesn't exist.
createTemplateIfMissing :: Config -> IO ()
createTemplateIfMissing conf' = do
View
10 Network/Gitit/State.hs
@@ -45,16 +45,6 @@ appstate = unsafePerformIO $ newIORef AppState { sessions = undefined
, cache = undefined
, plugins = undefined }
-initializeGititState :: MonadIO m
- => M.Map String User
- -> [Plugin]
- -> m ()
-initializeGititState users' plugins' = do
- updateAppState $ \s -> s { sessions = Sessions M.empty
- , users = users'
- , cache = emptyCache
- , plugins = plugins' }
-
updateAppState :: MonadIO m => (AppState -> AppState) -> m ()
updateAppState fn = liftIO $! atomicModifyIORef appstate $ \st -> (fn st, ())
View
13 gitit.hs
@@ -28,8 +28,6 @@ import System.FilePath ((</>))
import Control.Concurrent
import Network.Gitit.Config (getConfigFromOpts)
import Data.Maybe (isNothing)
-import qualified Data.Map as M
-import System.IO.UTF8 (readFile)
import Control.Monad.Reader
import System.Log.Logger (logM, Priority(..), setLevel, setHandlers,
getLogger, saveGlobalLogger)
@@ -50,12 +48,6 @@ main = do
when (isNothing mbFind) $ error $
"Required program '" ++ prog ++ "' not found in system path."
- -- read user file
- userFileExists <- doesFileExist $ userFile conf
- users' <- if userFileExists
- then liftM (M.fromList . read) $ readFile $ userFile conf
- else return M.empty
-
-- set up logging
let level = if debugMode conf then DEBUG else logLevel conf
logFileHandler <- fileHandler (logFile conf) level
@@ -74,11 +66,8 @@ main = do
let conf' = conf{jsMath = jsMathExists, logLevel = level}
- -- load plugins
- plugins' <- loadPlugins $ pluginModules conf'
-
-- initialize state
- initializeGititState users' plugins'
+ initializeGititState (userFile conf') (pluginModules conf')
-- setup the page repository, template, and static files, if they don't exist
createRepoIfMissing conf'

0 comments on commit ecd8882

Please sign in to comment.