Permalink
Browse files

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

  • Loading branch information...
1 parent aa82ce3 commit f1f023a5de0aa81133257b965ed90e9bfb80c50d @jgm committed Jul 9, 2009
View
12 Network/Gitit.hs
@@ -103,8 +103,8 @@ import Control.Monad.Reader
import System.Directory
import System.FilePath
import Prelude hiding (readFile)
-import System.IO.UTF8
import Paths_gitit
+import Data.Maybe (fromJust)
import qualified Text.StringTemplate as T
import Codec.Binary.UTF8.String (decodeString)
@@ -122,12 +122,12 @@ wikiHandler conf = do
FormAuth -> authHandler : wikiHandlers
_ -> wikiHandlers
let fs = filestoreFromConfig conf
- templateText <- liftIO $ do
- templateExists <- doesFileExist $ templateFile conf
+ templs <- liftIO $ do
+ templateExists <- doesDirectoryExist $ templatesDir conf
if templateExists
- then readFile $ templateFile conf
- else getDataFileName ("data" </> "template.html") >>= readFile
- let templ = T.newSTMP templateText
+ then T.directoryGroup $ templatesDir conf
+ else getDataFileName ("data" </> "templates") >>= T.directoryGroup
+ let templ = fromJust $ T.getStringTemplate "page" templs
let ws = WikiState { wikiConfig = conf, wikiFileStore = fs, wikiTemplate = templ }
if compressResponses conf
then compressedResponseFilter
View
4 Network/Gitit/Config.hs
@@ -131,7 +131,7 @@ extractConfig cp = do
cfShowLHSBirdTracks <- get cp "DEFAULT" "show-lhs-bird-tracks"
cfAuthenticationMethod <- get cp "DEFAULT" "authentication-method"
cfUserFile <- get cp "DEFAULT" "user-file"
- cfTemplateFile <- get cp "DEFAULT" "template-file"
+ cfTemplatesDir <- get cp "DEFAULT" "templates-dir"
cfLogFile <- get cp "DEFAULT" "log-file"
cfLogLevel <- get cp "DEFAULT" "log-level"
cfStaticDir <- get cp "DEFAULT" "static-dir"
@@ -179,7 +179,7 @@ extractConfig cp = do
_ -> error
"Invalid authentication-method.\nLegal values are: form, http"
, userFile = cfUserFile
- , templateFile = cfTemplateFile
+ , templatesDir = cfTemplatesDir
, logFile = cfLogFile
, logLevel = let levelString = map toUpper cfLogLevel
levels = ["DEBUG", "INFO", "NOTICE", "WARNING", "ERROR",
View
14 Network/Gitit/Initialize.hs
@@ -54,14 +54,18 @@ initializeGititState conf = do
, cache = emptyCache
, plugins = plugins' }
--- | Create template file if it doesn't exist.
+-- | Create templates dir if it doesn't exist.
createTemplateIfMissing :: Config -> IO ()
createTemplateIfMissing conf' = do
- templateExists <- doesFileExist (templateFile conf')
+ templateExists <- doesDirectoryExist (templatesDir conf')
unless templateExists $ do
- templatePath <- getDataFileName $ "data" </> "template.html"
- copyFile templatePath (templateFile conf')
- logM "gitit" WARNING $ "Created default " ++ templateFile conf'
+ createDirectoryIfMissing True (templatesDir conf')
+ templatePath <- getDataFileName $ "data" </> "templates"
+ templs <- liftM (filter (`notElem` [".",".."])) $
+ getDirectoryContents templatePath
+ forM_ templs $ \t -> do
+ copyFile (templatePath </> t) (templatesDir conf' </> t)
+ logM "gitit" WARNING $ "Created default " ++ (templatesDir conf' </> t)
-- | Create page repository unless it exists.
createRepoIfMissing :: Config -> IO ()
View
2 Network/Gitit/Types.hs
@@ -59,7 +59,7 @@ data Config = Config {
showLHSBirdTracks :: Bool, -- show Haskell code with bird tracks
authenticationMethod :: AuthenticationMethod, -- use forms or HTTP digest?
userFile :: FilePath, -- path of users database
- templateFile :: FilePath, -- page template
+ templatesDir :: FilePath, -- directory containing page templates
logFile :: FilePath, -- path of server log file
logLevel :: Priority, -- severity filter for log messages
-- (DEBUG, INFO, NOTICE, WARNING, ERROR,
View
21 README.markdown
@@ -106,9 +106,9 @@ supports this. So you should make sure that you are using a UTF-8 locale
when running gitit. (To check this, type `locale`.)
Switch to the directory where you want to run gitit. This should be a
-directory where you have write access, since two directories, `static`
-and `wikidata`, and two files, `gitit-users` and `template.html`, will
-be created here. To start gitit, just type:
+directory where you have write access, since three directories, `static`,
+`templates`, and `wikidata`, and two files, `gitit-users` and `gitit.log`,
+will be created here. To start gitit, just type:
gitit
@@ -117,7 +117,7 @@ If all goes well, gitit will do the following:
1. Create a git repository, `wikidata`, and add a default front page.
2. Create a `static` directory containing the scripts, images,
and stylesheets used by gitit.
- 3. Create a `template.html` file containing an HStringTemplate template
+ 3. Create a `templates` directory containing HStringTemplate templates
for wiki pages.
4. Start a web server on port 5001.
@@ -231,9 +231,9 @@ Changing the theme
------------------
To change the look of the wiki, you can modify `screen.css` in
-`static/css`. But a better approach is to add a line to `template.html`
-that imports your own custom stylesheet. This line should go
-after the line that links to `/css/screen.css`:
+`static/css`. But a better approach is to add a line to
+`templates/page.st` that imports your own custom stylesheet. This line
+should go after the line that links to `/css/screen.css`:
<link href="/css/my-screen.css" rel="stylesheet" media="screen, projection" type="text/css" />
@@ -247,9 +247,10 @@ To change the look of printed pages, modify `print.css`.
The logo picture can be changed by copying a new PNG file to
`static/img/logo.png`.
-For more radical changes, you can modify `template.html`.
-Note that interpolated variables are surrounded by `$`s, so literal
-`$` must be backslash-escaped.
+For more radical changes, you can modify any of the templates in
+`templates`. The `page.st` template is the master template; it includes
+the others. Interpolated variables are surrounded by `$`s, so
+`literal $` must be backslash-escaped.
Adding support for math
-----------------------
View
13 data/default.conf
@@ -45,12 +45,13 @@ show-lhs-bird-tracks: no
# specifies whether to show Haskell code blocks in "bird style",
# with "> " at the beginning of each line.
-template-file: template.html
-# specifies the path of the page template file. If it does not exist,
-# gitit will create a default template. Users may wish to edit this
-# file to customize the appearance of their wiki. The template file
-# is an HStringTemplate template. Variables to be interpolated appear
-# between $'s. Literal $'s must be backslash-escaped.
+templates-dir: templates
+# specifies the path of the directory containing page templates.
+# If it does not exist, gitit will create it with default templates.
+# Users may wish to edit the templates to customize the appearance of
+# their wiki. The template files are HStringTemplate templates.
+# Variables to be interpolated appear between $'s. Literal $'s must be
+# backslash-escaped.
log-file: gitit.log
# specifies the path of gitit's log file. If it does not exist,
View
88 data/template.html
@@ -1,88 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <title>Wiki - $pagetitle$</title>
- $if(printable)$
- <link href="$base$/_static/css/print.css" rel="stylesheet" media="all" type= "text/css" />
- $else$
- <link href="$base$/_static/css/reset-fonts-grids.css" rel="stylesheet" media="screen, projection" type="text/css" />
- <link href="$base$/_static/css/base-min.css" rel="stylesheet" media="screen, projection" type="text/css" />
- <link href="$base$/_static/css/hk-pyg.css" rel="stylesheet" media="screen, projection" type="text/css" />
- <link href="$base$/_static/css/screen.css" rel="stylesheet" media="screen, projection" type="text/css" />
- <link href="$base$/_static/css/print.css" rel="stylesheet" media="print" type= "text/css" />
- $endif$
- <!--[if IE]><link href="$base$/_static/css/ie.css" rel="stylesheet" media="screen, projection" type="text/css" /><![endif]-->
- </head>
- <body>
- <div id="doc3" class="yui-t1">
- <div id="yui-main">
- <div id="maincol" class="yui-b">
- <div id="userbox">
- $if(showLogin)$
- $if(user)$
- <a href="$base$/_logout">Logout $user$</a>
- $else$
- <a href="$base$/_login">Login</a> &bull; <a href="/_register">Get an account</a>
- $endif$
- $else$
- <span class="login">Logged in as $user$</span>
- $endif$
- </div>
- $tabs$
- <div id="content">
- $if(nothead)$
- <h2 class="revision">Revision $revision$</h2>
- $endif$
- <h1 class="pageTitle"><a href="$base$/$pagename$">$pagetitle$</a></h1>
- $messages$
- $content$
- </div>
- <div id="footer">powered by <a href="http://github.com/jgm/gitit/tree/master/">gitit</a></div>
- </div>
- </div>
- <div id="sidebar" class="yui-b first">
- <div id="logo">
- <a href="$base$/" title="Go to top page"><img src="$base$/_static/img/logo.png" /></a>
- </div>
- $if(sitenav)$
- <div class="sitenav">
- <fieldset>
- <legend>Site</legend>
- <ul>
- <li><a href="$base$/">Front page</a></li>
- <li><a href="$base$/_index">All pages</a></li>
- <li><a href="$base$/_categories">Categories</a></li>
- <li><a href="$base$/_random">Random page</a></li>
- <li><a href="$base$/_activity">Recent activity</a></li>
- <li><a href="$base$/_upload">Upload a file</a></li>
- <li><a href="$base$/Help">Help</a></li>
- </ul>
- $searchbox$
- </fieldset>
- </div>
- $endif$
- $if(pagetools)$
- <div class="pageTools">
- <fieldset>
- <legend>This page</legend>
- <ul>
- <li><a href="$base$/$pagename$?revision=$revision$&amp;showraw">Raw page source</a></li>
- <li><a href="$base$/$pagename$?revision=$revision$&amp;printable">Printable version</a></li>
- <li><a href="$base$/$pagename$?delete">Delete this page</a></li>
- </ul>
- $exportbox$
- </fieldset>
- </div>
- $endif$
- $if(markuphelp)$
- <div class="markupHelp">
- $markuphelp$
- </div>
- $endif$
- </div>
- </div>
- $javascripts$
- </body>
-</html>
View
8 data/templates/content.st
@@ -0,0 +1,8 @@
+<div id="content">
+ $if(nothead)$
+ <h2 class="revision">Revision $revision$</h2>
+ $endif$
+ <h1 class="pageTitle"><a href="$base$/$pagename$">$pagetitle$</a></h1>
+ $messages$
+ $content$
+</div>
View
1 data/templates/footer.st
@@ -0,0 +1 @@
+<div id="footer">powered by <a href="http://github.com/jgm/gitit/tree/master/">gitit</a></div>
View
3 data/templates/logo.st
@@ -0,0 +1,3 @@
+<div id="logo">
+ <a href="$base$/" title="Go to top page"><img src="$base$/_static/img/logo.png" /></a>
+</div>
View
3 data/templates/markuphelp.st
@@ -0,0 +1,3 @@
+<div class="markupHelp">
+ $markuphelp$
+</div>
View
43 data/templates/page.st
@@ -0,0 +1,43 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <title>Wiki - $pagetitle$</title>
+ $if(printable)$
+ <link href="$base$/_static/css/print.css" rel="stylesheet" media="all" type= "text/css" />
+ $else$
+ <link href="$base$/_static/css/reset-fonts-grids.css" rel="stylesheet" media="screen, projection" type="text/css" />
+ <link href="$base$/_static/css/base-min.css" rel="stylesheet" media="screen, projection" type="text/css" />
+ <link href="$base$/_static/css/hk-pyg.css" rel="stylesheet" media="screen, projection" type="text/css" />
+ <link href="$base$/_static/css/screen.css" rel="stylesheet" media="screen, projection" type="text/css" />
+ <link href="$base$/_static/css/print.css" rel="stylesheet" media="print" type= "text/css" />
+ $endif$
+ <!--[if IE]><link href="$base$/_static/css/ie.css" rel="stylesheet" media="screen, projection" type="text/css" /><![endif]-->
+ </head>
+ <body>
+ <div id="doc3" class="yui-t1">
+ <div id="yui-main">
+ <div id="maincol" class="yui-b">
+ $userbox()$
+ $tabs$
+ $content()$
+ $footer()$
+ </div>
+ </div>
+ <div id="sidebar" class="yui-b first">
+ $logo()$
+ $if(sitenav)$
+ $sitenav()$
+ $endif$
+ $if(pagetools)$
+ $pagetools()$
+ $endif$
+ $if(markuphelp)$
+ $markuphelp()$
+ $endif$
+ </div>
+ </div>
+ $javascripts$
+ </body>
+</html>
View
11 data/templates/pagetools.st
@@ -0,0 +1,11 @@
+<div class="pageTools">
+ <fieldset>
+ <legend>This page</legend>
+ <ul>
+ <li><a href="$base$/$pagename$?revision=$revision$&amp;showraw">Raw page source</a></li>
+ <li><a href="$base$/$pagename$?revision=$revision$&amp;printable">Printable version</a></li>
+ <li><a href="$base$/$pagename$?delete">Delete this page</a></li>
+ </ul>
+ $exportbox$
+ </fieldset>
+</div>
View
15 data/templates/sitenav.st
@@ -0,0 +1,15 @@
+<div class="sitenav">
+ <fieldset>
+ <legend>Site</legend>
+ <ul>
+ <li><a href="$base$/">Front page</a></li>
+ <li><a href="$base$/_index">All pages</a></li>
+ <li><a href="$base$/_categories">Categories</a></li>
+ <li><a href="$base$/_random">Random page</a></li>
+ <li><a href="$base$/_activity">Recent activity</a></li>
+ <li><a href="$base$/_upload">Upload a file</a></li>
+ <li><a href="$base$/Help">Help</a></li>
+ </ul>
+ $searchbox$
+ </fieldset>
+</div>
View
11 data/templates/userbox.st
@@ -0,0 +1,11 @@
+<div id="userbox">
+ $if(showLogin)$
+ $if(user)$
+ <a href="$base$/_logout">Logout $user$</a>
+ $else$
+ <a href="$base$/_login">Login</a> &bull; <a href="/_register">Get an account</a>
+ $endif$
+ $else$
+ <span class="login">Logged in as $user$</span>
+ $endif$
+</div>
View
6 gitit.cabal
@@ -37,7 +37,11 @@ data-files: css/screen.css, css/print.css, css/ie.css, css/hk-pyg.css,
data/post-update, data/FrontPage.page, data/Help.page,
data/markup.Markdown, data/markup.RST,
data/markup.HTML, data/markup.LaTeX,
- data/template.html, data/default.conf,
+ data/default.conf,
+ data/templates/page.st, data/templates/content.st,
+ data/templates/userbox.st, data/templates/footer.st,
+ data/templates/logo.st, data/templates/markuphelp.st,
+ data/templates/pagetools.st, data/templates/sitenav.st,
data/markupHelp/Markdown, data/markupHelp/Markdown+LHS,
data/markupHelp/RST, data/markupHelp/RST+LHS,
data/markupHelp/LaTeX, data/markupHelp/LaTeX+LHS,

0 comments on commit f1f023a

Please sign in to comment.