Permalink
Browse files

Changed Environment type

  • Loading branch information...
1 parent a8f9a12 commit a9327b29b564ac7ab125522f7f73691b14b60cd4 alson committed Nov 24, 2008
View
@@ -0,0 +1,16 @@
+index :: Controller ()
+index = do pages <- quickQuery' "select * from page" []
+ return ()
+
+show :: Controller ()
+show = do e <- getEnvironment
+ let id' = getSetting "id" e :: Maybe String
+ doIO $ debugM e $ "XXXXXXXX id' = " ++ (Prelude.show id')
+ case id' of
+ Nothing -> redirectTo "/Home"
+ Just i -> do q <- quickQuery' "select title, content from page where id = ?" [toSql i]
+ e' <- doIO $ setViewDataValue "page-title" (Prelude.show $ (head q) !! 0) e
+ e''<- doIO $ setViewDataValue "page-content" (Prelude.show $ (head q) !! 1) e
+ put e''
+
+
View
@@ -0,0 +1,4 @@
+page :: View XML
+page = <div>
+ <% getViewDataValue "page-content" %>
+ </div>
@@ -0,0 +1,27 @@
+module Turbinado.Environment.Database (
+ addDatabaseToEnvironment,
+ Connection
+ ) where
+
+import Data.Typeable
+import Data.Dynamic
+import qualified Data.Map as M
+import Control.Monad
+import Control.Monad.State
+import Control.Monad.Trans
+import Data.Maybe
+import qualified Database.HDBC as HDBC
+import Database.HDBC (IConnection)
+
+import Config.Master
+import Turbinado.Controller.Monad
+import Turbinado.Environment.Types
+
+
+addDatabaseToEnvironment :: Controller ()
+addDatabaseToEnvironment = do e <- get
+ case databaseConnection of
+ Nothing -> return ()
+ Just conn -> do c <- doIO $ conn
+ put $ e {getDatabase = Just c}
+
@@ -0,0 +1,118 @@
+module Turbinado.Environment.Types where
+
+import Data.Dynamic
+import qualified Data.Map as M
+import Data.Maybe
+import System.IO
+import System.IO.Unsafe
+import System.Log.Logger
+import Text.Regex
+import Control.Concurrent.MVar
+import Control.Monad.State
+import qualified Network.HTTP as HTTP
+import HSX.XMLGenerator (XMLGenT(..), unXMLGenT)
+import Turbinado.View.XML
+import Config.Master
+import System.Time
+import System.Plugins
+
+-- Stuffing all Environment "types" into this file to avoid
+-- recursive imports...
+
+data Environment = Environment { getCodeStore :: Maybe CodeStore
+ , getDatabase :: Maybe Database
+ , getLoggerLock :: Maybe LoggerLock
+ , getMimeTypes :: Maybe MimeTypes
+ , getRequest :: Maybe HTTP.Request
+ , getResponse :: Maybe HTTP.Response
+ , getRoutes :: Maybe Routes
+ , getSettings :: Maybe Settings
+ , getViewData :: Maybe ViewData
+ , getAppEnvironment :: Maybe AppEnvironment
+ }
+
+-- type EnvironmentFilter = Environment -> IO Environment
+
+newEnvironment :: Environment
+newEnvironment = Environment { getCodeStore = Nothing
+ , getDatabase = Nothing
+ , getLoggerLock = Nothing
+ , getMimeTypes = Nothing
+ , getRequest = Nothing
+ , getResponse = Nothing
+ , getRoutes = Nothing
+ , getSettings = Nothing
+ , getViewData = Nothing
+ , getAppEnvironment = Nothing
+ }
+
+--
+-- * Types for CodeStore
+--
+
+data CodeType = CTView | CTController | CTLayout
+type CodeDate = ClockTime
+type Function = String
+type CodeLocation = (FilePath, Function)
+
+data CodeStore = CodeStore (MVar CodeMap)
+type CodeMap = M.Map CodeLocation CodeStatus
+data CodeStatus = CodeLoadFailure |
+ CodeLoadController (StateT Environment IO ()) Module CodeDate |
+ CodeLoadView (XMLGenT (StateT Environment IO) XML ) Module CodeDate
+
+--
+-- * Types for Database
+--
+
+type Database = Connection
+
+
+--
+-- * Types for Logger
+--
+
+type LoggerLock = MVar ()
+
+
+--
+-- * Types for MimeTypes
+--
+
+data MimeTypes = MimeTypes (M.Map String MimeType)
+data MimeType = MimeType String String
+
+instance Show MimeType where
+ showsPrec _ (MimeType part1 part2) = showString (part1 ++ '/':part2)
+
+--
+-- * Types for Request
+--
+
+-- Just a basic Request from Network.HTTP
+
+--
+-- * Types for Response
+--
+
+-- Just a basic Response from Network.HTTP
+
+--
+-- * Types for Routes
+--
+
+type Keys = [String]
+data Routes = Routes [(Regex, Keys)]
+
+--
+-- * Types for Settings
+--
+
+type Settings = M.Map String Dynamic
+
+--
+-- * Types for ViewData
+--
+
+type ViewData = M.Map String Dynamic
+
Oops, something went wrong.

0 comments on commit a9327b2

Please sign in to comment.