Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 117 lines (106 sloc) 5.528 kb
daaafff @alsonkemp Initial commit
authored
1 module Turbinado.View (
2 evalView,
3 defaultContentType,
4 -- limited export from Turbinado.View.Monad
5 View, ViewT, ViewT',
6 runView, runViewT,
7 -- * Functions
1e33cd0 @alsonkemp Switching to HasEnvironment class; adding 'Components'; improving the…
authored
8 liftIO, catch,
6ac94d0 @alsonkemp Never ending cleanup not ending...
authored
9 insertView,
10 insertDefaultView,
1e33cd0 @alsonkemp Switching to HasEnvironment class; adding 'Components'; improving the…
authored
11 insertComponent,
daaafff @alsonkemp Initial commit
authored
12
13 -- Module Exports
da95eda @alsonkemp Updating to match turbinado-website
authored
14 module Turbinado.View.Helpers,
daaafff @alsonkemp Initial commit
authored
15 module Turbinado.View.HTML,
16 module Turbinado.View.XML,
17 module Turbinado.View.XML.PCDATA,
18 module Turbinado.View.XMLGenerator,
19 module Turbinado.Environment.CodeStore,
a1aa2cd @alsonkemp Updating the ORM; Adding a mini-CMS; Adding a little HAML translator
authored
20 module Turbinado.Environment.Params,
daaafff @alsonkemp Initial commit
authored
21 module Turbinado.Environment.Request,
22 module Turbinado.Environment.Response,
a8f9a12 @alsonkemp still learning git... updates...
authored
23 module Turbinado.Environment.Settings,
a1aa2cd @alsonkemp Updating the ORM; Adding a mini-CMS; Adding a little HAML translator
authored
24 module Turbinado.Environment.Types,
25 module Turbinado.Environment.ViewData
daaafff @alsonkemp Initial commit
authored
26 ) where
27
4c5c1b2 syncing with website code
alsonk authored
28 import Control.OldException (catchDyn)
daaafff @alsonkemp Initial commit
authored
29 import Control.Monad
30 import Control.Monad.State
31 import Control.Monad.Trans (MonadIO(..))
1e33cd0 @alsonkemp Switching to HasEnvironment class; adding 'Components'; improving the…
authored
32 import Data.Char
a8f9a12 @alsonkemp still learning git... updates...
authored
33 import Data.List
daaafff @alsonkemp Initial commit
authored
34 import Data.Maybe
35 import qualified Network.HTTP as HTTP
a8f9a12 @alsonkemp still learning git... updates...
authored
36 import qualified Network.URI as URI
daaafff @alsonkemp Initial commit
authored
37 import Prelude hiding (catch)
a8f9a12 @alsonkemp still learning git... updates...
authored
38 import System.FilePath
daaafff @alsonkemp Initial commit
authored
39
c59c8d3 Checking in all of the Environment + Website changes
alson authored
40 import Turbinado.Controller.Monad hiding (catch)
41 import Turbinado.Environment.CodeStore
1e33cd0 @alsonkemp Switching to HasEnvironment class; adding 'Components'; improving the…
authored
42 import Turbinado.Environment.Logger
a1aa2cd @alsonkemp Updating the ORM; Adding a mini-CMS; Adding a little HAML translator
authored
43 import Turbinado.Environment.Params
daaafff @alsonkemp Initial commit
authored
44 import Turbinado.Environment.Request
45 import Turbinado.Environment.Response
a8f9a12 @alsonkemp still learning git... updates...
authored
46 import Turbinado.Environment.Settings
c59c8d3 Checking in all of the Environment + Website changes
alson authored
47 import Turbinado.Environment.Types
a1aa2cd @alsonkemp Updating the ORM; Adding a mini-CMS; Adding a little HAML translator
authored
48 import Turbinado.Environment.ViewData
c59c8d3 Checking in all of the Environment + Website changes
alson authored
49 import Turbinado.Server.StandardResponse
daaafff @alsonkemp Initial commit
authored
50 import Turbinado.View.Exception
da95eda @alsonkemp Updating to match turbinado-website
authored
51 import Turbinado.View.Helpers
daaafff @alsonkemp Initial commit
authored
52 import Turbinado.View.HTML
1e33cd0 @alsonkemp Switching to HasEnvironment class; adding 'Components'; improving the…
authored
53 import Turbinado.View.Monad hiding (liftIO)
daaafff @alsonkemp Initial commit
authored
54 import Turbinado.View.XML hiding (Name)
55 import Turbinado.View.XML.PCDATA
56 import Turbinado.View.XMLGenerator
57 import Turbinado.Utility.General
58
1e33cd0 @alsonkemp Switching to HasEnvironment class; adding 'Components'; improving the…
authored
59 evalView :: (HasEnvironment m) => View XML -> m ()
60 evalView p = do e <- getEnvironment
61 (x, e') <- liftIO $ runView p e
c59c8d3 Checking in all of the Environment + Website changes
alson authored
62 pageResponse [] $ renderAsHTML x
daaafff @alsonkemp Initial commit
authored
63
64 defaultContentType :: String
65 defaultContentType = "text/html; charset=ISO-8859-1"
66
1a1e99e @alsonkemp More cleanup...
authored
67 insertDefaultView :: View XML
68 insertDefaultView =
69 do cl <- getView
70 debugM $ " Layout: insertDefaultView : loading " ++ (fst cl) ++ " - " ++ (snd cl)
71 c <- retrieveCode CTView cl
72 case c of
4c5c1b2 syncing with website code
alsonk authored
73 CodeLoadView v _ -> v
74 CodeLoadController _ _ -> error "retrieveAndRunLayout called, but returned CodeLoadController"
1a1e99e @alsonkemp More cleanup...
authored
75 CodeLoadFailure e -> return $ cdata e
76
77 insertView :: String -> String -> View XML
78 insertView c a =
79 do debugM $ " Layout: insertView : loading " ++ c ++ " - " ++ a
80 c <- retrieveCode CTView (c, (toLower (head a)):(tail a))
81 case c of
4c5c1b2 syncing with website code
alsonk authored
82 CodeLoadView v _ -> v
83 CodeLoadController _ _ -> error "retrieveAndRunLayout called, but returned CodeLoadController"
1a1e99e @alsonkemp More cleanup...
authored
84 CodeLoadFailure e -> return $ cdata e
85
1e33cd0 @alsonkemp Switching to HasEnvironment class; adding 'Components'; improving the…
authored
86 insertComponent :: String -> String -> [(String, String)] -> View XML
87 insertComponent controller action opts =
88 do debugM $ " insertComponent: Starting"
db57095 @alsonkemp syncing with website
authored
89 p <- retrieveCode CTComponentController (joinPath [controller,"Controller"], (toLower $ head action) : (tail action))
1e33cd0 @alsonkemp Switching to HasEnvironment class; adding 'Components'; improving the…
authored
90 case p of
91 CodeLoadMissing -> return $ cdata $ "insertComponent error: code missing : " ++ controller ++ " - " ++ action
92 CodeLoadFailure e -> return $ cdata $ "insertComponent error: " ++ e
4c5c1b2 syncing with website code
alsonk authored
93 CodeLoadComponentController p' _ -> do oldE <- getEnvironment
1e33cd0 @alsonkemp Switching to HasEnvironment class; adding 'Components'; improving the…
authored
94 mapM_ (\(k, v) -> setSetting k v) opts
95 lift $ p'
96 -- allow for overloading of the Component Controller and View
97 c <- getSetting "component-controller"
98 a <- getSetting "component-view"
99 insertComponentView oldE (fromMaybe controller c) (fromMaybe action a)
100 _ -> return $ cdata $ "insertComponent error: received incorrect CodeStatus"
101
102 insertComponentView :: Environment -> String -> String -> View XML
103 insertComponentView oldE controller action =
104 do debugM $ " insertComponentView: Starting"
db57095 @alsonkemp syncing with website
authored
105 v <- retrieveCode CTComponentView (joinPath [controller, "Views", action], "markup")
1e33cd0 @alsonkemp Switching to HasEnvironment class; adding 'Components'; improving the…
authored
106 case v of
107 CodeLoadMissing -> do setEnvironment oldE
108 return $ cdata $ "insertComponentView error: code missing : " ++ (joinPath [controller, action]) ++ " - markup"
109 CodeLoadFailure e -> do setEnvironment oldE
110 return $ cdata $ "insertComponentView error: " ++ e
4c5c1b2 syncing with website code
alsonk authored
111 CodeLoadComponentView v' _ -> do res <- v'
1e33cd0 @alsonkemp Switching to HasEnvironment class; adding 'Components'; improving the…
authored
112 setEnvironment oldE
113 return res
114 _ -> do setEnvironment oldE
115 return $ cdata $ "insertComponentView error"
a8f9a12 @alsonkemp still learning git... updates...
authored
116
Something went wrong with that request. Please try again.