Skip to content
This repository
Browse code

Use nested templates in templates/ directory rather than template.html.

  • Loading branch information...
commit f1f023a5de0aa81133257b965ed90e9bfb80c50d 1 parent aa82ce3
John MacFarlane authored
12 Network/Gitit.hs
@@ -103,8 +103,8 @@ import Control.Monad.Reader
103 103 import System.Directory
104 104 import System.FilePath
105 105 import Prelude hiding (readFile)
106   -import System.IO.UTF8
107 106 import Paths_gitit
  107 +import Data.Maybe (fromJust)
108 108 import qualified Text.StringTemplate as T
109 109 import Codec.Binary.UTF8.String (decodeString)
110 110
@@ -122,12 +122,12 @@ wikiHandler conf = do
122 122 FormAuth -> authHandler : wikiHandlers
123 123 _ -> wikiHandlers
124 124 let fs = filestoreFromConfig conf
125   - templateText <- liftIO $ do
126   - templateExists <- doesFileExist $ templateFile conf
  125 + templs <- liftIO $ do
  126 + templateExists <- doesDirectoryExist $ templatesDir conf
127 127 if templateExists
128   - then readFile $ templateFile conf
129   - else getDataFileName ("data" </> "template.html") >>= readFile
130   - let templ = T.newSTMP templateText
  128 + then T.directoryGroup $ templatesDir conf
  129 + else getDataFileName ("data" </> "templates") >>= T.directoryGroup
  130 + let templ = fromJust $ T.getStringTemplate "page" templs
131 131 let ws = WikiState { wikiConfig = conf, wikiFileStore = fs, wikiTemplate = templ }
132 132 if compressResponses conf
133 133 then compressedResponseFilter
4 Network/Gitit/Config.hs
@@ -131,7 +131,7 @@ extractConfig cp = do
131 131 cfShowLHSBirdTracks <- get cp "DEFAULT" "show-lhs-bird-tracks"
132 132 cfAuthenticationMethod <- get cp "DEFAULT" "authentication-method"
133 133 cfUserFile <- get cp "DEFAULT" "user-file"
134   - cfTemplateFile <- get cp "DEFAULT" "template-file"
  134 + cfTemplatesDir <- get cp "DEFAULT" "templates-dir"
135 135 cfLogFile <- get cp "DEFAULT" "log-file"
136 136 cfLogLevel <- get cp "DEFAULT" "log-level"
137 137 cfStaticDir <- get cp "DEFAULT" "static-dir"
@@ -179,7 +179,7 @@ extractConfig cp = do
179 179 _ -> error
180 180 "Invalid authentication-method.\nLegal values are: form, http"
181 181 , userFile = cfUserFile
182   - , templateFile = cfTemplateFile
  182 + , templatesDir = cfTemplatesDir
183 183 , logFile = cfLogFile
184 184 , logLevel = let levelString = map toUpper cfLogLevel
185 185 levels = ["DEBUG", "INFO", "NOTICE", "WARNING", "ERROR",
14 Network/Gitit/Initialize.hs
@@ -54,14 +54,18 @@ initializeGititState conf = do
54 54 , cache = emptyCache
55 55 , plugins = plugins' }
56 56
57   --- | Create template file if it doesn't exist.
  57 +-- | Create templates dir if it doesn't exist.
58 58 createTemplateIfMissing :: Config -> IO ()
59 59 createTemplateIfMissing conf' = do
60   - templateExists <- doesFileExist (templateFile conf')
  60 + templateExists <- doesDirectoryExist (templatesDir conf')
61 61 unless templateExists $ do
62   - templatePath <- getDataFileName $ "data" </> "template.html"
63   - copyFile templatePath (templateFile conf')
64   - logM "gitit" WARNING $ "Created default " ++ templateFile conf'
  62 + createDirectoryIfMissing True (templatesDir conf')
  63 + templatePath <- getDataFileName $ "data" </> "templates"
  64 + templs <- liftM (filter (`notElem` [".",".."])) $
  65 + getDirectoryContents templatePath
  66 + forM_ templs $ \t -> do
  67 + copyFile (templatePath </> t) (templatesDir conf' </> t)
  68 + logM "gitit" WARNING $ "Created default " ++ (templatesDir conf' </> t)
65 69
66 70 -- | Create page repository unless it exists.
67 71 createRepoIfMissing :: Config -> IO ()
2  Network/Gitit/Types.hs
@@ -59,7 +59,7 @@ data Config = Config {
59 59 showLHSBirdTracks :: Bool, -- show Haskell code with bird tracks
60 60 authenticationMethod :: AuthenticationMethod, -- use forms or HTTP digest?
61 61 userFile :: FilePath, -- path of users database
62   - templateFile :: FilePath, -- page template
  62 + templatesDir :: FilePath, -- directory containing page templates
63 63 logFile :: FilePath, -- path of server log file
64 64 logLevel :: Priority, -- severity filter for log messages
65 65 -- (DEBUG, INFO, NOTICE, WARNING, ERROR,
21 README.markdown
Source Rendered
@@ -106,9 +106,9 @@ supports this. So you should make sure that you are using a UTF-8 locale
106 106 when running gitit. (To check this, type `locale`.)
107 107
108 108 Switch to the directory where you want to run gitit. This should be a
109   -directory where you have write access, since two directories, `static`
110   -and `wikidata`, and two files, `gitit-users` and `template.html`, will
111   -be created here. To start gitit, just type:
  109 +directory where you have write access, since three directories, `static`,
  110 +`templates`, and `wikidata`, and two files, `gitit-users` and `gitit.log`,
  111 +will be created here. To start gitit, just type:
112 112
113 113 gitit
114 114
@@ -117,7 +117,7 @@ If all goes well, gitit will do the following:
117 117 1. Create a git repository, `wikidata`, and add a default front page.
118 118 2. Create a `static` directory containing the scripts, images,
119 119 and stylesheets used by gitit.
120   - 3. Create a `template.html` file containing an HStringTemplate template
  120 + 3. Create a `templates` directory containing HStringTemplate templates
121 121 for wiki pages.
122 122 4. Start a web server on port 5001.
123 123
@@ -231,9 +231,9 @@ Changing the theme
231 231 ------------------
232 232
233 233 To change the look of the wiki, you can modify `screen.css` in
234   -`static/css`. But a better approach is to add a line to `template.html`
235   -that imports your own custom stylesheet. This line should go
236   -after the line that links to `/css/screen.css`:
  234 +`static/css`. But a better approach is to add a line to
  235 +`templates/page.st` that imports your own custom stylesheet. This line
  236 +should go after the line that links to `/css/screen.css`:
237 237
238 238 <link href="/css/my-screen.css" rel="stylesheet" media="screen, projection" type="text/css" />
239 239
@@ -247,9 +247,10 @@ To change the look of printed pages, modify `print.css`.
247 247 The logo picture can be changed by copying a new PNG file to
248 248 `static/img/logo.png`.
249 249
250   -For more radical changes, you can modify `template.html`.
251   -Note that interpolated variables are surrounded by `$`s, so literal
252   -`$` must be backslash-escaped.
  250 +For more radical changes, you can modify any of the templates in
  251 +`templates`. The `page.st` template is the master template; it includes
  252 +the others. Interpolated variables are surrounded by `$`s, so
  253 +`literal $` must be backslash-escaped.
253 254
254 255 Adding support for math
255 256 -----------------------
13 data/default.conf
@@ -45,12 +45,13 @@ show-lhs-bird-tracks: no
45 45 # specifies whether to show Haskell code blocks in "bird style",
46 46 # with "> " at the beginning of each line.
47 47
48   -template-file: template.html
49   -# specifies the path of the page template file. If it does not exist,
50   -# gitit will create a default template. Users may wish to edit this
51   -# file to customize the appearance of their wiki. The template file
52   -# is an HStringTemplate template. Variables to be interpolated appear
53   -# between $'s. Literal $'s must be backslash-escaped.
  48 +templates-dir: templates
  49 +# specifies the path of the directory containing page templates.
  50 +# If it does not exist, gitit will create it with default templates.
  51 +# Users may wish to edit the templates to customize the appearance of
  52 +# their wiki. The template files are HStringTemplate templates.
  53 +# Variables to be interpolated appear between $'s. Literal $'s must be
  54 +# backslash-escaped.
54 55
55 56 log-file: gitit.log
56 57 # specifies the path of gitit's log file. If it does not exist,
88 data/template.html
... ... @@ -1,88 +0,0 @@
1   -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2   - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3   -<html xmlns="http://www.w3.org/1999/xhtml">
4   - <head>
5   - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6   - <title>Wiki - $pagetitle$</title>
7   - $if(printable)$
8   - <link href="$base$/_static/css/print.css" rel="stylesheet" media="all" type= "text/css" />
9   - $else$
10   - <link href="$base$/_static/css/reset-fonts-grids.css" rel="stylesheet" media="screen, projection" type="text/css" />
11   - <link href="$base$/_static/css/base-min.css" rel="stylesheet" media="screen, projection" type="text/css" />
12   - <link href="$base$/_static/css/hk-pyg.css" rel="stylesheet" media="screen, projection" type="text/css" />
13   - <link href="$base$/_static/css/screen.css" rel="stylesheet" media="screen, projection" type="text/css" />
14   - <link href="$base$/_static/css/print.css" rel="stylesheet" media="print" type= "text/css" />
15   - $endif$
16   - <!--[if IE]><link href="$base$/_static/css/ie.css" rel="stylesheet" media="screen, projection" type="text/css" /><![endif]-->
17   - </head>
18   - <body>
19   - <div id="doc3" class="yui-t1">
20   - <div id="yui-main">
21   - <div id="maincol" class="yui-b">
22   - <div id="userbox">
23   - $if(showLogin)$
24   - $if(user)$
25   - <a href="$base$/_logout">Logout $user$</a>
26   - $else$
27   - <a href="$base$/_login">Login</a> &bull; <a href="/_register">Get an account</a>
28   - $endif$
29   - $else$
30   - <span class="login">Logged in as $user$</span>
31   - $endif$
32   - </div>
33   - $tabs$
34   - <div id="content">
35   - $if(nothead)$
36   - <h2 class="revision">Revision $revision$</h2>
37   - $endif$
38   - <h1 class="pageTitle"><a href="$base$/$pagename$">$pagetitle$</a></h1>
39   - $messages$
40   - $content$
41   - </div>
42   - <div id="footer">powered by <a href="http://github.com/jgm/gitit/tree/master/">gitit</a></div>
43   - </div>
44   - </div>
45   - <div id="sidebar" class="yui-b first">
46   - <div id="logo">
47   - <a href="$base$/" title="Go to top page"><img src="$base$/_static/img/logo.png" /></a>
48   - </div>
49   - $if(sitenav)$
50   - <div class="sitenav">
51   - <fieldset>
52   - <legend>Site</legend>
53   - <ul>
54   - <li><a href="$base$/">Front page</a></li>
55   - <li><a href="$base$/_index">All pages</a></li>
56   - <li><a href="$base$/_categories">Categories</a></li>
57   - <li><a href="$base$/_random">Random page</a></li>
58   - <li><a href="$base$/_activity">Recent activity</a></li>
59   - <li><a href="$base$/_upload">Upload a file</a></li>
60   - <li><a href="$base$/Help">Help</a></li>
61   - </ul>
62   - $searchbox$
63   - </fieldset>
64   - </div>
65   - $endif$
66   - $if(pagetools)$
67   - <div class="pageTools">
68   - <fieldset>
69   - <legend>This page</legend>
70   - <ul>
71   - <li><a href="$base$/$pagename$?revision=$revision$&amp;showraw">Raw page source</a></li>
72   - <li><a href="$base$/$pagename$?revision=$revision$&amp;printable">Printable version</a></li>
73   - <li><a href="$base$/$pagename$?delete">Delete this page</a></li>
74   - </ul>
75   - $exportbox$
76   - </fieldset>
77   - </div>
78   - $endif$
79   - $if(markuphelp)$
80   - <div class="markupHelp">
81   - $markuphelp$
82   - </div>
83   - $endif$
84   - </div>
85   - </div>
86   - $javascripts$
87   - </body>
88   -</html>
8 data/templates/content.st
... ... @@ -0,0 +1,8 @@
  1 +<div id="content">
  2 + $if(nothead)$
  3 + <h2 class="revision">Revision $revision$</h2>
  4 + $endif$
  5 + <h1 class="pageTitle"><a href="$base$/$pagename$">$pagetitle$</a></h1>
  6 + $messages$
  7 + $content$
  8 +</div>
1  data/templates/footer.st
... ... @@ -0,0 +1 @@
3  data/templates/logo.st
... ... @@ -0,0 +1,3 @@
  1 +<div id="logo">
  2 + <a href="$base$/" title="Go to top page"><img src="$base$/_static/img/logo.png" /></a>
  3 +</div>
3  data/templates/markuphelp.st
... ... @@ -0,0 +1,3 @@
  1 +<div class="markupHelp">
  2 + $markuphelp$
  3 +</div>
43 data/templates/page.st
... ... @@ -0,0 +1,43 @@
  1 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3 +<html xmlns="http://www.w3.org/1999/xhtml">
  4 + <head>
  5 + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  6 + <title>Wiki - $pagetitle$</title>
  7 + $if(printable)$
  8 + <link href="$base$/_static/css/print.css" rel="stylesheet" media="all" type= "text/css" />
  9 + $else$
  10 + <link href="$base$/_static/css/reset-fonts-grids.css" rel="stylesheet" media="screen, projection" type="text/css" />
  11 + <link href="$base$/_static/css/base-min.css" rel="stylesheet" media="screen, projection" type="text/css" />
  12 + <link href="$base$/_static/css/hk-pyg.css" rel="stylesheet" media="screen, projection" type="text/css" />
  13 + <link href="$base$/_static/css/screen.css" rel="stylesheet" media="screen, projection" type="text/css" />
  14 + <link href="$base$/_static/css/print.css" rel="stylesheet" media="print" type= "text/css" />
  15 + $endif$
  16 + <!--[if IE]><link href="$base$/_static/css/ie.css" rel="stylesheet" media="screen, projection" type="text/css" /><![endif]-->
  17 + </head>
  18 + <body>
  19 + <div id="doc3" class="yui-t1">
  20 + <div id="yui-main">
  21 + <div id="maincol" class="yui-b">
  22 + $userbox()$
  23 + $tabs$
  24 + $content()$
  25 + $footer()$
  26 + </div>
  27 + </div>
  28 + <div id="sidebar" class="yui-b first">
  29 + $logo()$
  30 + $if(sitenav)$
  31 + $sitenav()$
  32 + $endif$
  33 + $if(pagetools)$
  34 + $pagetools()$
  35 + $endif$
  36 + $if(markuphelp)$
  37 + $markuphelp()$
  38 + $endif$
  39 + </div>
  40 + </div>
  41 + $javascripts$
  42 + </body>
  43 +</html>
11 data/templates/pagetools.st
... ... @@ -0,0 +1,11 @@
  1 +<div class="pageTools">
  2 + <fieldset>
  3 + <legend>This page</legend>
  4 + <ul>
  5 + <li><a href="$base$/$pagename$?revision=$revision$&amp;showraw">Raw page source</a></li>
  6 + <li><a href="$base$/$pagename$?revision=$revision$&amp;printable">Printable version</a></li>
  7 + <li><a href="$base$/$pagename$?delete">Delete this page</a></li>
  8 + </ul>
  9 + $exportbox$
  10 + </fieldset>
  11 +</div>
15 data/templates/sitenav.st
... ... @@ -0,0 +1,15 @@
  1 +<div class="sitenav">
  2 + <fieldset>
  3 + <legend>Site</legend>
  4 + <ul>
  5 + <li><a href="$base$/">Front page</a></li>
  6 + <li><a href="$base$/_index">All pages</a></li>
  7 + <li><a href="$base$/_categories">Categories</a></li>
  8 + <li><a href="$base$/_random">Random page</a></li>
  9 + <li><a href="$base$/_activity">Recent activity</a></li>
  10 + <li><a href="$base$/_upload">Upload a file</a></li>
  11 + <li><a href="$base$/Help">Help</a></li>
  12 + </ul>
  13 + $searchbox$
  14 + </fieldset>
  15 +</div>
11 data/templates/userbox.st
... ... @@ -0,0 +1,11 @@
  1 +<div id="userbox">
  2 + $if(showLogin)$
  3 + $if(user)$
  4 + <a href="$base$/_logout">Logout $user$</a>
  5 + $else$
  6 + <a href="$base$/_login">Login</a> &bull; <a href="/_register">Get an account</a>
  7 + $endif$
  8 + $else$
  9 + <span class="login">Logged in as $user$</span>
  10 + $endif$
  11 +</div>
6 gitit.cabal
@@ -37,7 +37,11 @@ data-files: css/screen.css, css/print.css, css/ie.css, css/hk-pyg.css,
37 37 data/post-update, data/FrontPage.page, data/Help.page,
38 38 data/markup.Markdown, data/markup.RST,
39 39 data/markup.HTML, data/markup.LaTeX,
40   - data/template.html, data/default.conf,
  40 + data/default.conf,
  41 + data/templates/page.st, data/templates/content.st,
  42 + data/templates/userbox.st, data/templates/footer.st,
  43 + data/templates/logo.st, data/templates/markuphelp.st,
  44 + data/templates/pagetools.st, data/templates/sitenav.st,
41 45 data/markupHelp/Markdown, data/markupHelp/Markdown+LHS,
42 46 data/markupHelp/RST, data/markupHelp/RST+LHS,
43 47 data/markupHelp/LaTeX, data/markupHelp/LaTeX+LHS,

0 comments on commit f1f023a

Please sign in to comment.
Something went wrong with that request. Please try again.