Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More Environment stuff

  • Loading branch information...
commit 8ae8a2063cd388652868435110488bb7ccb94b2e 1 parent a9327b2
alsonk authored
49 Turbinado/Environment.hs
View
@@ -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
2  Turbinado/Environment/CodeStore.hs
View
@@ -29,7 +29,7 @@ import Config.Master
import qualified Turbinado.Server.Exception as Ex
import Turbinado.Environment.Logger
-import Turbinado.Environment
+import {-# SOURCE #-} Turbinado.Environment
import Turbinado.Environment.Request
import Turbinado.Environment.Response
import Turbinado.View.Monad
2  Turbinado/Environment/Logger.hs
View
@@ -3,7 +3,7 @@ module Turbinado.Environment.Logger where
import qualified System.Log.Logger as L
import qualified System.Log.Handler.Simple as S
import Control.Concurrent.MVar
-import Turbinado.Environment
+import {-# SOURCE #-} Turbinado.Environment
import Config.Master
import Data.Dynamic
2  Turbinado/Environment/MimeTypes.hs
View
@@ -45,7 +45,7 @@ import Data.Typeable
import qualified Data.Map as Map hiding (Map)
import Text.ParserCombinators.Parsec
-import Turbinado.Environment
+import {-# SOURCE #-} Turbinado.Environment
data MimeTypes = MimeTypes (Map String MimeType)
deriving (Typeable)
8 Turbinado/Environment/Request.hs
View
@@ -12,7 +12,7 @@ import Turbinado.Utility.General
import qualified Data.Map as M
import Control.Monad
import Data.Maybe
-import Turbinado.Environment
+import {-# SOURCE #-} Turbinado.Environment
requestKey = "request"
@@ -20,13 +20,11 @@ addRequestToEnvironment :: HTTP.Request -> EnvironmentFilter
addRequestToEnvironment = setRequest
getRequest :: Environment -> HTTP.Request
-getRequest = getKey requestKey
+getRequest = fromJust $ request
setRequest :: HTTP.Request -> EnvironmentFilter
-setRequest req = setKey requestKey req
+setRequest req e = return $ e { request = Just req}
-modifyRequest :: (HTTP.Request -> HTTP.Request) -> EnvironmentFilter
-modifyRequest f = getRequest >>= (setRequest . f)
{-
lookupHeader :: (Monad m) => m (Maybe String)
2  Turbinado/Environment/Response.hs
View
@@ -12,7 +12,7 @@ import Turbinado.Utility.General
import qualified Data.Map as M
import Control.Monad
import Data.Maybe
-import Turbinado.Environment
+import {-# SOURCE #-} Turbinado.Environment
import System.Time
import System.Locale
2  Turbinado/Environment/Routes.hs
View
@@ -12,7 +12,7 @@ import Control.Monad
import qualified Network.HTTP as HTTP
import qualified Network.URI as URI
import Turbinado.Controller.Exception
-import Turbinado.Environment
+import {-# SOURCE #-} Turbinado.Environment
import Turbinado.Environment.Logger
import Turbinado.Environment.Request
import Turbinado.Environment.Settings
2  Turbinado/Environment/Settings.hs
View
@@ -17,7 +17,7 @@ import Control.Monad.State
import Data.Maybe
import Data.Char
import System.FilePath
-import Turbinado.Environment
+import {-# SOURCE #-} Turbinado.Environment
type Settings = M.Map String Dynamic
2  Turbinado/Environment/ViewData.hs
View
@@ -7,7 +7,7 @@ module Turbinado.Environment.ViewData (
import qualified Data.Map as M
import Control.Monad
import Data.Maybe
-import Turbinado.Environment
+import {-# SOURCE #-} Turbinado.Environment
type ViewData = Map String Dynamic
2  turbinado.cabal
View
@@ -12,7 +12,7 @@ Executable server
Main-is: Turbinado/Server.hs
Build-Depends: base, bytestring, containers, directory, filepath, harp, hslogger, hsx, HTTP, mtl, network, old-locale, old-time, parsec, plugins, pretty, regex-compat, time
Hs-Source-Dirs: . , config
- ghc-options: -F -pgmFtrhsx -O
+ ghc-options: -O
Extensions: MultiParamTypeClasses,
FunctionalDependencies,
TypeFamilies,
Please sign in to comment.
Something went wrong with that request. Please try again.