-
Notifications
You must be signed in to change notification settings - Fork 5
/
Layouts.hs
118 lines (105 loc) · 4.35 KB
/
Layouts.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
{-# LANGUAGE CPP #-}
#if PRODUCTION
{-# LANGUAGE Safe #-}
#endif
{-# LANGUAGE OverloadedStrings #-}
module Layouts where
import LIO
import Gitstar.Policy
import Data.Maybe
import Data.Monoid
import Control.Monad
import Hails.HttpServer
import Hails.Web.Controller hiding (body)
import Hails.Web.Responses
import Prelude hiding (head, id, div, span)
import Text.Blaze.Html5 hiding (map)
import Text.Blaze.Html5.Attributes hiding (title, span, content)
import qualified Text.Blaze.Html.Renderer.Utf8 as R (renderHtml)
import Utils
renderHtml :: Html -> Controller Response
renderHtml htmlBody = do
muName <- getHailsUser
muser <- liftLIO $ maybe (return Nothing) mkUser muName
return $ okHtml $ R.renderHtml $ application muser htmlBody
where mkUser uName = Just `liftM` getOrCreateUser uName
stylesheet :: String -> Html
stylesheet uri = link ! rel "stylesheet" ! type_ "text/css" ! href (toValue uri)
homeHtml :: Html -> Controller Response
homeHtml htmlBody = return $ okHtml $ R.renderHtml $ homeLayout htmlBody
homeLayout :: Html -> Html
homeLayout content = docTypeHtml $ do
head $ do
title $ "GitStar - For hackers and other heretics"
stylesheet "/static/css/bootstrap.css"
stylesheet "/static/css/gh-buttons.css"
stylesheet "/static/css/home.css"
body $ do
div ! class_ "row" $
div ! id "flash-messages" ! class_ "span4 offset4" $ ""
div ! class_ "container" $ content
script ! src "/static/js/jquery.js" $ ""
script ! src "/static/js/jquery.cookie.js" $ ""
script ! src "/static/js/bootstrap.min.js" $ ""
script ! src "/static/js/bootstrap-typeahead.js" $ ""
script ! src "/static/js/application.js" $ ""
script ! src "/static/js/flash.js" $ ""
application :: Maybe User -> Html -> Html
application muser content = docTypeHtml $ do
head $ do
title $ "GitStar - For hackers and other heretics"
stylesheet "/static/css/bootstrap.css"
stylesheet "/static/css/gh-buttons.css"
stylesheet "/static/css/application.css"
body $ do
div ! class_ "navbar navbar-fixed-top" $ do
div ! class_ "navbar-inner" $ do
div ! class_ "container" $ do
a ! href "/" ! class_ "brand" $ "Gitstar"
ul ! class_ "nav" $ do
li $ a ! href "/users" $ "List Users"
li $ a ! href "/projects" $ "List Projects"
ul ! class_ "nav pull-right" $ do
maybe publicMenu userMenu muser
div ! class_ "row" $
div ! id "flash-messages" ! class_ "span4 offset4" $ ""
div ! class_ "container" $ content
script ! src "/static/js/jquery.js" $ ""
script ! src "/static/js/jquery.cookie.js" $ ""
script ! src "/static/js/bootstrap.min.js" $ ""
script ! src "/static/js/bootstrap-typeahead.js" $ ""
script ! src "/static/js/application.js" $ ""
script ! src "/static/js/flash.js" $ ""
where publicMenu = do
li $ a ! href "/login" $ do
span ! class_ "icon-road" $ ""
" Login"
userMenu user = do
let gravatar = md5 . fromMaybe "" $ userGravatar user
li $ a ! href (toValue $ "/" `mappend` userName user) $
img ! src (toValue $ "https://secure.gravatar.com/avatar/"
`mappend` gravatar `mappend` "?s=25")
li ! class_ "dropdown" $ do
a ! href "#" ! class_ "dropdown-toggle"
! dataAttribute "toggle" "dropdown" $ do
toHtml $ userName user
b ! class_ "caret" $ ""
ul ! class_ "dropdown-menu" $ do
li $ a ! href (toValue $ "/" `mappend` userName user) $ do
span ! class_ "icon-user" $ ""
" View Profile"
li $ a ! href "/user/edit" $ do
span ! class_ "icon-edit" $ ""
" Edit Profile"
li $ a ! href "/projects/new" $ do
span ! class_ "icon-folder-open" $ ""
" New project"
li $ a ! href "/apps/" $ do
span ! class_ "icon-pencil" $ ""
" Manage Apps"
li $ a ! href "/keys/" $ do
span ! class_ "icon-lock" $ ""
" Manage keys"
li $ a ! href "/logout" $ do
span ! class_ "icon-road" $ ""
" Logout"