Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 128 lines (99 sloc) 3.809 kB
a9327b2 Changed Environment type
alson authored
1 module Turbinado.Environment.Types where
2
3 import Data.Dynamic
4 import qualified Data.Map as M
5 import Data.Maybe
6 import System.IO
7 import System.IO.Unsafe
8 import System.Log.Logger
9 import Text.Regex
10 import Control.Concurrent.MVar
11 import Control.Monad.State
12 import qualified Network.HTTP as HTTP
13 import HSX.XMLGenerator (XMLGenT(..), unXMLGenT)
14 import Turbinado.View.XML
15 import Config.Master
16 import System.Time
17 import System.Plugins
18
194a9f8 @alsonkemp Syncing with turbinado-website
authored
19
20 -- | The class of types which hold an 'Environment'.
21 -- 'View' and 'Controller' are both instances of this class.
1e33cd0 @alsonkemp Switching to HasEnvironment class; adding 'Components'; improving the…
authored
22 class (MonadIO m) => HasEnvironment m where
23 getEnvironment :: m Environment
24 setEnvironment :: Environment -> m ()
25
194a9f8 @alsonkemp Syncing with turbinado-website
authored
26 -- | The Environment in which each request is handled.
27 -- All components are held within 'Maybe's so that the
28 -- Environment can be partially constructed.
a9327b2 Changed Environment type
alson authored
29 data Environment = Environment { getCodeStore :: Maybe CodeStore
30 , getDatabase :: Maybe Database
31 , getLoggerLock :: Maybe LoggerLock
32 , getMimeTypes :: Maybe MimeTypes
33 , getRequest :: Maybe HTTP.Request
34 , getResponse :: Maybe HTTP.Response
35 , getRoutes :: Maybe Routes
36 , getSettings :: Maybe Settings
37 , getViewData :: Maybe ViewData
38 , getAppEnvironment :: Maybe AppEnvironment
39 }
40
194a9f8 @alsonkemp Syncing with turbinado-website
authored
41 -- | Construct a new empty 'Environment'.
a9327b2 Changed Environment type
alson authored
42 newEnvironment :: Environment
43 newEnvironment = Environment { getCodeStore = Nothing
44 , getDatabase = Nothing
45 , getLoggerLock = Nothing
46 , getMimeTypes = Nothing
47 , getRequest = Nothing
48 , getResponse = Nothing
49 , getRoutes = Nothing
50 , getSettings = Nothing
51 , getViewData = Nothing
52 , getAppEnvironment = Nothing
53 }
54
55 --
56 -- * Types for CodeStore
57 --
58
1e33cd0 @alsonkemp Switching to HasEnvironment class; adding 'Components'; improving the…
authored
59 data CodeType = CTView | CTController | CTComponentView | CTComponentController | CTLayout deriving (Show)
a9327b2 Changed Environment type
alson authored
60 type CodeDate = ClockTime
61 type Function = String
62 type CodeLocation = (FilePath, Function)
63
64 data CodeStore = CodeStore (MVar CodeMap)
65 type CodeMap = M.Map CodeLocation CodeStatus
1e33cd0 @alsonkemp Switching to HasEnvironment class; adding 'Components'; improving the…
authored
66 data CodeStatus = CodeLoadMissing |
67 CodeLoadFailure String |
1a1e99e @alsonkemp More cleanup...
authored
68 CodeLoadController (StateT Environment IO ()) Module CodeDate |
1e33cd0 @alsonkemp Switching to HasEnvironment class; adding 'Components'; improving the…
authored
69 CodeLoadView (XMLGenT (StateT Environment IO) XML ) Module CodeDate |
70 CodeLoadComponentController (StateT Environment IO ()) Module CodeDate |
71 CodeLoadComponentView (XMLGenT (StateT Environment IO) XML ) Module CodeDate
a9327b2 Changed Environment type
alson authored
72
73 --
74 -- * Types for Database
75 --
76
77 type Database = Connection
78
79
80 --
81 -- * Types for Logger
82 --
83
84 type LoggerLock = MVar ()
85
86
87 --
88 -- * Types for MimeTypes
89 --
90
91 data MimeTypes = MimeTypes (M.Map String MimeType)
92 data MimeType = MimeType String String
93
94 instance Show MimeType where
95 showsPrec _ (MimeType part1 part2) = showString (part1 ++ '/':part2)
96
97 --
98 -- * Types for Request
99 --
100
101 -- Just a basic Request from Network.HTTP
102
103 --
104 -- * Types for Response
105 --
106
107 -- Just a basic Response from Network.HTTP
108
109 --
110 -- * Types for Routes
111 --
112
113 type Keys = [String]
114 data Routes = Routes [(Regex, Keys)]
115
116 --
117 -- * Types for Settings
118 --
119
120 type Settings = M.Map String Dynamic
121
122 --
123 -- * Types for ViewData
124 --
125
126 type ViewData = M.Map String Dynamic
127
Something went wrong with that request. Please try again.