Skip to content

HTTPS clone URL

Subversion checkout URL

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