1 module Rakka.Environment
10 import Control.Arrow.ArrowIO
13 import qualified Data.Map as M
15 import qualified Network.HTTP.Lucu.Config as LC
17 import Rakka.SystemConfig
18 import Rakka.Wiki.Interpreter
19 import Rakka.Wiki.Interpreter.Base
22 data Environment = Environment {
23 envLocalStateDir :: !FilePath
24 , envLucuConf :: !LC.Config
25 , envStorage :: !Storage
26 , envSysConf :: !SystemConfig
27 , envInterpTable :: !(IORef InterpTable)
31 type InterpTable = Map String Interpreter
34 setupEnv :: FilePath -> PortNumber -> IO Environment
35 setupEnv lsdir portNum
36 = do let lucuConf = LC.defaultConfig {
37 LC.cnfServerPort = PortNumber portNum
40 sysConf = mkSystemConfig lucuConf
41 interpTable <- mkInterpTable
42 return $ Environment {
43 envLocalStateDir = lsdir
44 , envLucuConf = lucuConf
45 , envStorage = storage
46 , envSysConf = sysConf
47 , envInterpTable = interpTable
51 mkInterpTable :: IO (IORef InterpTable)
52 mkInterpTable = newIORef (listToTable baseInterpreters)
54 listToTable :: [Interpreter] -> InterpTable
56 = M.fromList [ (commandName x, x) | x <- xs ]
59 getInterpTable :: Environment -> IO InterpTable
60 getInterpTable = readIORef . envInterpTable
63 getInterpTableA :: ArrowIO a => Environment -> a b InterpTable
64 getInterpTableA = arrIO0 . getInterpTable