Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New createTemplateIfMissing function in Initialize.

Library exports functions to create template, static, repo.
  • Loading branch information...
commit 2e7f4e91311483e3c1698dc0ea6d2ed202c80e5d 1 parent d7d984f
@jgm authored
Showing with 24 additions and 18 deletions.
  1. +4 −0 Network/Gitit.hs
  2. +17 −7 Network/Gitit/Initialize.hs
  3. +3 −11 gitit.hs
View
4 Network/Gitit.hs
@@ -28,6 +28,9 @@ module Network.Gitit ( initializeGititState
, loadPlugin
, wikiHandler
, readMimeTypesFile
+ , createRepoIfMissing
+ , createTemplateIfMissing
+ , createStaticIfMissing
)
where
import Network.Gitit.Types
@@ -36,6 +39,7 @@ import Network.Gitit.State
import Network.Gitit.Server
import Network.Gitit.Plugins (loadPlugin)
import Network.Gitit.Handlers
+import Network.Gitit.Initialize
import Network.Gitit.Config (readMimeTypesFile, getDefaultConfig)
import Control.Monad.Reader
import System.Directory
View
24 Network/Gitit/Initialize.hs
@@ -16,7 +16,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
{- Functions for initializing a Gitit wiki.
-}
-module Network.Gitit.Initialize ( createStaticIfMissing, createRepoIfMissing )
+module Network.Gitit.Initialize ( createStaticIfMissing, createRepoIfMissing, createTemplateIfMissing )
where
import System.FilePath ((</>), (<.>), takeExtension)
import Data.FileStore
@@ -24,13 +24,22 @@ import Network.Gitit.Types
import Network.Gitit.Framework
import Paths_gitit (getDataFileName)
import Control.Exception (throwIO, try)
-import System.Directory (copyFile, createDirectoryIfMissing, doesDirectoryExist, getDirectoryContents)
+import System.Directory (copyFile, createDirectoryIfMissing, doesDirectoryExist, getDirectoryContents, doesFileExist)
import Control.Monad (unless, forM_, liftM)
import Prelude hiding (readFile)
import System.IO.UTF8
-import System.IO (stderr)
import Text.Pandoc
import Text.Pandoc.Shared (HTMLMathMethod(..))
+import System.Log.Logger (logM, Priority(..))
+
+-- | Create template file if it doesn't exist.
+createTemplateIfMissing :: Config -> IO ()
+createTemplateIfMissing conf' = do
+ templateExists <- doesFileExist (templateFile conf')
+ unless templateExists $ do
+ templatePath <- getDataFileName $ "data" </> "template.html"
+ copyFile templatePath (templateFile conf')
+ logM "gitit" WARNING $ "Created default " ++ templateFile conf'
-- | Create page repository unless it exists.
createRepoIfMissing :: Config -> IO ()
@@ -68,11 +77,12 @@ createRepoIfMissing conf = do
-- add front page and help page
create fs (frontPage conf <.> "page") (Author "Gitit" "") "Default front page" welcomecontents
create fs "Help.page" (Author "Gitit" "") "Default help page" helpcontents
- hPutStrLn stderr "Created repository"
+ logM "gitit" WARNING $ "Created repository"
-- | Create static directory unless it exists.
-createStaticIfMissing :: FilePath -> IO ()
-createStaticIfMissing staticdir = do
+createStaticIfMissing :: Config -> IO ()
+createStaticIfMissing conf = do
+ let staticdir = staticDir conf
staticExists <- doesDirectoryExist staticdir
unless staticExists $ do
@@ -98,5 +108,5 @@ createStaticIfMissing staticdir = do
jsDataDir <- getDataFileName "js"
forM_ javascripts $ \f -> copyFile (jsDataDir </> f) (jsdir </> f)
- hPutStrLn stderr $ "Created " ++ staticdir ++ " directory"
+ logM "gitit" WARNING $ "Created " ++ staticdir ++ " directory"
View
14 gitit.hs
@@ -35,7 +35,6 @@ import System.Log.Logger (logM, Priority(..), setLevel, setHandlers,
getLogger, saveGlobalLogger)
import System.Log.Handler.Simple (fileHandler)
import Data.Char (toLower)
-import Paths_gitit
main :: IO ()
main = do
@@ -83,17 +82,10 @@ main = do
-- initialize state
initializeGititState users' plugins'
- -- setup the page repository and static files, if they don't exist
+ -- setup the page repository, template, and static files, if they don't exist
createRepoIfMissing conf'
- let staticdir = staticDir conf'
- createStaticIfMissing staticdir
-
- -- create template file if it doesn't exist
- templateExists <- doesFileExist (templateFile conf')
- unless templateExists $ do
- templatePath <- getDataFileName $ "data" </> "template.html"
- copyFile templatePath (templateFile conf')
- logM "gitit" WARNING $ "Created default " ++ templateFile conf'
+ createStaticIfMissing conf'
+ createTemplateIfMissing conf'
let serverConf = Conf { validator = Nothing, port = portNumber conf' }
-- start the server
Please sign in to comment.
Something went wrong with that request. Please try again.