Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alsonk
committed
Nov 25, 2008
1 parent
a9327b2
commit 8ae8a20
Showing
10 changed files
with
44 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,47 @@ | ||
module Turbinado.Environment ( | ||
Environment, | ||
EnvironmentFilter, | ||
newEnvironment, | ||
getKey, | ||
setKey | ||
EnvironmentFilter | ||
) where | ||
|
||
import Data.Dynamic | ||
import Data.Map | ||
import Data.Maybe | ||
import System.IO | ||
import System.IO.Unsafe | ||
import System.Log.Logger | ||
import Config.Master | ||
|
||
-- Using Dynamic for two reasons: | ||
-- 1) Break module cycles (Environment doesn't import the various Request, Response, etc bits | ||
-- 2) Extensibility - easy for plugins to add data to the Environment | ||
type Environment = Map String Dynamic | ||
import Turbinado.Environment.CodeStore | ||
import Turbinado.Environment.Logger | ||
import Turbinado.Environment.MimeTypes | ||
import Turbinado.Environment.Request | ||
import Turbinado.Environment.Response | ||
import Turbinado.Environment.Routes | ||
import Turbinado.Environment.Settings | ||
import Turbinado.Environment.ViewData | ||
|
||
data Environment = Environment { getCodeStore :: Maybe CodeStore | ||
, getLogger :: Maybe Logger | ||
, getMimeTypes :: Maybe MimeTypes | ||
, request :: Maybe Request | ||
, getResponse :: Maybe Response | ||
, getRoutes :: Maybe Routes | ||
, getSettings :: Maybe Settings | ||
, getViewData :: Maybe ViewData | ||
, getAppEnvironment :: Maybe AppEnvironment | ||
} | ||
|
||
type EnvironmentFilter = Environment -> IO Environment | ||
|
||
newEnvironment :: IO Environment | ||
newEnvironment = return (empty :: Environment) | ||
newEnvironment = return $ Environment { | ||
getCodeStore = Nothing | ||
, getLogger = Nothing | ||
, getMimeTypes = Nothing | ||
, getRequest = Nothing | ||
, getResponse = Nothing | ||
, getRoutes = Nothing | ||
, getSettings = Nothing | ||
, getViewData = Nothing | ||
, getAppEnvironment = Nothing | ||
} | ||
|
||
|
||
getKey :: (Typeable a) => String -> Environment -> a | ||
getKey k e = fromJust $ fromDynamic $ e ! k | ||
|
||
setKey :: (Typeable a) => String -> a -> EnvironmentFilter | ||
setKey k v = \e -> return $ insert k (toDyn v) e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters