darcsden-1.1: src/DarcsDen/Pages/Base.hs
{-# LANGUAGE PatternGuards, CPP #-}
{-# OPTIONS_GHC -F -pgmF trhsx #-}
module DarcsDen.Pages.Base where
import Data.Char (toLower)
import Data.List (sortBy)
import Data.Maybe (fromMaybe)
import Data.Ord (comparing)
import HSP
import DarcsDen.Pages.HSPage ( HSPage )
import DarcsDen.State.Session
import DarcsDen.Settings
import DarcsDen.State.User
base :: String -> Bool -> HSP XML -> HSP XML -> HSP XML -> HSPage
base title indexable crumb pagenav content sess =
<html>
<head>
<title><% title %><% if not (null title) then " :: " else "" %><% hostname %></title>
<% if indexable then <% "" %> else <% <meta name="robots" content="noindex" /> %> %>
<link rel="shortcut icon" href=(baseUrl ++ "public/images/favicon.ico") />
<link rel="stylesheet" href=(baseUrl ++ "public/bootstrap/css/bootstrap.min.css") type="text/css" />
-- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-- <link rel="stylesheet" href=(baseUrl ++ "public/bootstrap/css/bootstrap-responsive.css") type="text/css" />
<link rel="stylesheet" href=(baseUrl ++ "public/css/main.css") type="text/css" />
#ifdef HIGHLIGHTER
<link rel="stylesheet" href=(baseUrl ++ "public/css/highlight.css") />
#endif
<link rel="stylesheet" href=(baseUrl ++ "public/codemirror-3.14/lib/codemirror.css") />
<link rel="stylesheet" href=(baseUrl ++ "public/codemirror-3.14/theme/elegant.css") />
<script src=(baseUrl ++ "public/js/jquery-1.8.1.min.js") type="text/javascript"></script>
<script src=(baseUrl ++ "public/bootstrap/js/bootstrap.min.js") type="text/javascript"></script>
<script src=(baseUrl ++ "public/js/relatize.js") type="text/javascript"></script>
<script src=(baseUrl ++ "public/js/main.js") type="text/javascript"></script>
<script src=(baseUrl ++ "public/codemirror-3.14/lib/codemirror-compressed.js") type="text/javascript"></script>
</head>
<body>
<div class="container-fluid">
<div class="row-fluid header">
<div class="offset1 span11">
<% sitenav (sUser sess) %>
<h1 class="head">
<% siteLink %>
<span class="crumb">
<% cdata " :: " %>
<% crumb %>
</span>
</h1>
</div>
</div>
<div class="row-fluid middle">
<div class="offset1 span9 content">
<% map notification (sNotifications sess) %>
<% content %>
</div>
<div class="span2 navbar pagenav">
<% pagenav %>
</div>
</div>
<div class="row-fluid footer">
<div class="span12">
<% siteFooter %>
</div>
</div>
</div>
</body>
</html>
where
sitenav (Just u) =
<ul class="navbar sitenav links">
<li class="home"><a class="small button" href=(baseUrl ++ u)>my repos</a></li>
<li class="settings"><a class="small button" href=(baseUrl ++ "settings")>settings</a></li>
<li class="logout"><a class="small button" href=(baseUrl ++ "logout")>log out</a></li>
</ul>
sitenav Nothing =
<ul class="navbar sitenav links">
<% if multiuser
then <% <li class="register"><a class="small button" href=(baseUrl ++ "register")>register</a></li> %>
else <% "" %>
%>
<li class="login"><a class="small button" href=(baseUrl ++ "login")>log in</a></li>
</ul>
notification :: Notification -> HSP XML
notification (Success msg) = <div class="notification success"><% msg %></div>
notification (Message msg) = <div class="notification message"><% msg %></div>
notification (Warning msg) = <div class="notification warning"><% msg %></div>
frontpage :: [User] -> HSPage
frontpage us = base
""
True
<span>home</span>
<div></div>
<div class="row-fluid frontpage">
<div class="span3">
<h2>users</h2>
<ul class="user-repos"><% map userlink us' %></ul>
<h2>repos</h2>
<ul class="user-repos">
<li class="username"><a href=(baseUrl ++ "explore")>All repos</a></li>
</ul>
</div>
<div class="span9 markdown">
<% frontPageContent %>
</div>
</div>
where
us' :: [User]
us' = sortBy (comparing (map toLower . uName)) us
userlink :: User -> HSP XML
userlink User{uName=u} = <li class="username"><a href=(u)><% u %></a></li>
field :: HSP XML -> String -> String -> HSP XML
field f l n =
<div class="field">
<% f %>
<label><% l %></label> -- TODO: for=
<%
if n /= ""
then <span class="note"><% n %></span>
else <br />
%>
</div>
input :: String -> String -> HSP XML
input n v = <input type="text" name=n id=n value=v size="40" maxlength="1000" />
inputWith :: String -> String -> [(String,String)] -> HSP XML
inputWith n v attrs = <input type="text" name=n id=n value=v (map (\(a,b) -> a := b) attrs) />
textarea :: Int -> String -> String -> HSP XML
textarea r n v = <textarea rows=r name=n id=n><% v %></textarea>
input' :: [(String, String)] -> String -> HSP XML
input' is n = input n (fromMaybe "" (lookup n is))
inputWith' :: [(String, String)] -> String -> [(String,String)] -> HSP XML
inputWith' is n attrs = inputWith n (fromMaybe "" (lookup n is)) attrs
checkbox' :: [(String, String)] -> String -> HSP XML
checkbox' is n
| n `elem` (map fst is) =
<div class="inline-wrapper"><% box `set` ("checked" := "checked") %></div>
| otherwise = <div class="inline-wrapper"><% box %></div>
where box = <input type="checkbox" name=n />
checkbox :: Bool -> [(String, String)] -> String -> HSP XML
checkbox False = checkbox'
checkbox True = \is n -> checkbox' ((n, "1"):is) n
password' :: [(String, String)] -> String -> HSP XML
password' is n = <input type="password" name=n id=n value=(fromMaybe "" (lookup n is)) />
passwordWith' :: [(String, String)] -> String -> [(String, String)] -> HSP XML
passwordWith' is n attrs = <input type="password" name=n id=n value=(fromMaybe "" (lookup n is)) (map (\(a,b) -> a := b) attrs) />
textarea' :: [(String, String)] -> Int -> String -> HSP XML
textarea' is r n = textarea r n (fromMaybe "" (lookup n is))
submit :: String -> HSP XML
submit l =
<div class="buttons">
<input type="submit" value=l />
<br />
</div>
paginate :: String -> Int -> Int -> HSP XML
paginate _ _ 1 = <div class="dd-pagination"></div>
paginate url page totalpages =
<div class="dd-pagination">
<ul>
<% if page /= 1 then <% prev %> else <% spacer %> %>
<li>page <% show page %> of <% show totalpages %></li>
<% if page /= totalpages then <% next %> else <% spacer %> %>
</ul>
</div>
where
prev = <li class="prev"><a class="small button" href=(url ++ "/page/" ++ show (page - 1))><% "<-" %> prev</a></li>
next = <li class="next"><a class="small button" href=(url ++ "/page/" ++ show (page + 1))>next <% "->" %></a></li>
spacer = <li class="prevnextspacer"></li>