Permalink
Browse files

Added data/default.conf, which defines default config file values.

The file is self-documented using comments.
Removed old data/SampleConfig.hs.
Modified README to reflect new configuration method.
  • Loading branch information...
jgm committed Apr 13, 2009
1 parent 4361c9c commit ce07825bb8ab13503c8b2ee1fe6a73e483979b5f
Showing with 133 additions and 137 deletions.
  1. +11 −6 Gitit/Config.hs
  2. +6 −108 README.markdown
  3. +0 −22 data/SampleConfig.hs
  4. +115 −0 data/default.conf
  5. +1 −1 gitit.cabal
View
@@ -32,6 +32,7 @@ import Control.Monad.Error
import System.Log.Logger ()
import Data.List (intercalate)
import Data.Char (toLower, toUpper, isDigit)
+import Paths_gitit (getDataFileName)
data Opt
= Help
@@ -85,6 +86,7 @@ compileInfo =
forceEither :: Show e => Either e a -> a
forceEither = either (\e -> error (show e)) id
+{-
setDefault :: MonadError CPError m => OptionSpec -> String -> ConfigParser -> m ConfigParser
setDefault opt val cp = set cp "DEFAULT" opt val
@@ -104,7 +106,7 @@ defaultConfigParser = forceEither $
setDefault "port" "5001" >>=
setDefault "debug-mode" "no" >>=
setDefault "front-page" "Front Page" >>=
- setDefault "no-edit" "Front Page" >>=
+ setDefault "no-edit" "Help" >>=
setDefault "no-delete" "Front Page, Help" >>=
setDefault "access-question" "" >>=
setDefault "access-question-answers" "" >>=
@@ -113,17 +115,20 @@ defaultConfigParser = forceEither $
setDefault "recaptcha-private-key" "" >>=
setDefault "max-cache-size" "2000000" >>=
setDefault "mime-types-file" "/etc/mime.types"
+-}
handleFlag :: Config -> Opt -> IO Config
handleFlag conf opt = do
progname <- getProgName
case opt of
Help -> hPutStrLn stderr (usageInfo (usageHeader progname) flags) >> exitWith ExitSuccess
Version -> hPutStrLn stderr (progname ++ " version " ++ _VERSION ++ compileInfo ++ copyrightMessage) >> exitWith ExitSuccess
- Debug -> return $ conf { debugMode = True }
- PrintDefaultConfig -> hPutStrLn stdout (to_string defaultConfigParser) >> exitWith ExitSuccess
- Port p -> return $ conf { portNumber = p }
- ConfigFile fname -> readfile defaultConfigParser fname >>= extractConfig . forceEither
+ PrintDefaultConfig -> getDataFileName "data/default.conf" >>= readFile >>= hPutStrLn stdout >> exitWith ExitSuccess
+ Debug -> return conf{ debugMode = True }
+ Port p -> return conf{ portNumber = p }
+ ConfigFile fname -> do
+ defaultCP <- getDataFileName "data/default.conf" >>= readfile emptyCP
+ readfile (forceEither defaultCP) fname >>= extractConfig . forceEither
extractConfig :: ConfigParser -> IO Config
extractConfig cp = do
@@ -209,6 +214,6 @@ lrStrip = reverse . dropWhile (== ' ') . reverse . dropWhile (== ' ')
getConfigFromOpts :: IO Config
getConfigFromOpts = do
- defaultConfig <- extractConfig defaultConfigParser
+ defaultConfig <- getDataFileName "data/default.conf" >>= readfile emptyCP >>= extractConfig . forceEither
getArgs >>= parseArgs >>= foldM handleFlag defaultConfig
View
@@ -114,114 +114,12 @@ Configuration options
---------------------
You can set some configuration options when starting gitit, using the
-option `-f [filename]`. A configuration file takes the following form:
-
- Config {
- repository = Git "wikidata",
- defaultPageType = Markdown,
- userFile = "gitit-users",
- templateFile = "template.html",
- logFile = "gitit.log",
- logLevel = WARNING,
- staticDir = "static",
- pluginModules = ["plugins/DotPlugin"],
- tableOfContents = False,
- maxUploadSize = 100000,
- portNumber = 5001,
- debugMode = True,
- frontPage = "Front Page",
- noEdit = ["Help", "Front Page"],
- noDelete = ["Help", "Front Page"],
- accessQuestion = Just ("Enter the access code (to request an access code, contact me@somewhere.org):", ["abcd"]),
- useRecaptcha = False,
- recaptchaPublicKey = "",
- recaptchaPrivateKey = "",
- maxCacheSize = 2000000,
- mimeTypesFile = "/etc/mime.types"
- }
-
-- `repository` specifies the type and (relative) path of the repository
- in which the wiki's pages will be stored. If it does not exist, gitit
- will create it on startup. Supported repository types are `Git` and
- `Darcs`.
-
-- `defaultPageType` is the type of markup used to interpret pages in
- the wiki. Two values are currently supported: `Markdown` and `RST`.
- If `Markdown` is selected, [pandoc]'s syntax extensions (for footnotes,
- delimited code blocks, etc.) will be enabled. Note that pandoc's
- reStructuredText parser is not complete, so some pages may
- not be rendered correctly if `RST` is selected.
-
-- `userFile` is a file containing user login information (with hashed
- passwords). If it does not exist, gitit will start with an empty list
- of users. Gitit will write a new `userFile` on shutdown.
-
-- `templateFile` is a file containing an HTML template for the wiki pages.
- If it does not exist, gitit will create a default template. (For most
- purposes, this can be used just as it is, but some users may wish to
- customize the look of their wiki.) `templateFile` is an
- `HStringTemplate` template.
-
-- `logFile` is the path of gitit's log file. The log file is in
- [Apache combined log format].
-
-- `logLevel` controls how much is logged. Possible values (from
- most to least verbose) are `DEBUG`, `INFO`, `NOTICE`, `WARNING`,
- `ERROR`, `CRITICAL`, `ALERT`, `EMERGENCY`.
-
-- `staticDir` is the (relative) path of a directory in which static content
- (javascript, CSS, images) is stored. If it does not exist, gitit will
- create it on startup.
-
-- `pluginModules` is a list (possibly empty) of plugin modules to load.
-
-- `tableOfContents` is either `False` or `True`. If it is `True`, a table
- of contents (derived from the page's headers) will appear on each page.
-
-- `maxUploadSize` (in bytes) sets a limit to the size of file uploads.
-
-- `portNumber` is the number of the port on which the wiki will be served.
-
-- `debugMode` is either `True` or `False`. If it is `True`, debug information
- will be printed to the console when gitit is running.
-
-- `frontPage` is the name of the page that is designated as the "front" or
- "entrance" page of the wiki. Any page may be designated.
-
-- `noEdit` is a list of pages that cannot be edited.
-
-- `noDelete` is a list of pages that cannot be deleted.
-
-- `accessQuestion` provides primitive access control. It is either `Nothing`,
- in which case anyone will be allowed to create an account and edit wiki pages,
- or `Just (question, [answer1, answer2, ...])`, where question is a prompt
- that will be displayed when a user tries to create an account, and
- `answer1, answer2, ...` are the valid responses. The user must provide a
- valid response in order to create an account.
-
-- `useRecaptcha` is either `True` or `False`. It specifies whether to
- use the [reCAPTCHA] service to provide captchas for user registration.
-
-- `recaptchaPublicKey` and `recaptchaPrivateKey` are
- [reCAPTCHA] keys, which can be obtained free of charge at
- <http://recaptcha.net/api/getkey>. The values of these fields are ignored
- if `useRecaptcha` is set to `False`.
-
-- `maxCacheSize` is the maximum size of the in-memory page cache (in bytes).
-
-- `mimeTypesFile` is the path of a file containing mime type associations.
- Each line of the file should contain a mime type, followed by some space,
- followed by a space-separated list of file extensions that map to that mime
- type. If the file is not found, some simple defaults will be used.
-
-[reCAPTCHA]: http://recaptcha.net
-[Apache combined log format]: http://httpd.apache.org/docs/2.2/logs.html#combined
-
-The easiest way to create a custom configuration file is to dump the default
-configuration and modify it:
-
- gitit --print-default-config > myconf.hs
- # edit myconf.hs
+option `-f [filename]`. To get a copy of the default configuration file,
+which you can customize, just type:
+
+ gitit --print-default-config > default.conf
+
+The default configuration file is documented with comments throughout.
Configuring gitit
=================
View
@@ -1,22 +0,0 @@
-Config {
- repository = Git "wikidata",
- defaultPageType = Markdown,
- userFile = "gitit-users",
- templateFile = "template.html",
- logFile = "gitit.log",
- logLevel = WARNING,
- staticDir = "static",
- pluginModules = ["data/DotPlugin"],
- tableOfContents = False,
- maxUploadSize = 100000,
- portNumber = 5001,
- debugMode = True,
- frontPage = "Front Page",
- noEdit = ["Help", "Front Page"],
- noDelete = ["Help", "Front Page"],
- accessQuestion = Just ("Enter the access code (to request an access code, contact me@somewhere.org):", ["abcd"]),
- useRecaptcha = False,
- recaptchaPublicKey = "",
- recaptchaPrivateKey = "",
- maxCacheSize = 2000000,
- mimeTypesFile = "/etc/mime.types" }
View
@@ -0,0 +1,115 @@
+# This is the default configuration file for gitit.
+# Lines beginning with # are comments.
+# Uncommented lines show the defaults.
+
+port: 5001
+# sets the port on which the web server will run.
+
+repository-type: Git
+# specifies the type of repository used for wiki content.
+# Options are Git and Darcs.
+
+repository-path: wikidata
+# specifies the path of the repository directory. If it does not
+# exist, gitit will create it on startup.
+
+user-file: gitit-users
+# specifies the path of the file containing user login information.
+# If it does not exist, gitit will create it (with an empty user list).
+
+static-dir: static
+# specifies the path of the static directory (containing javascript,
+# css, and images). If it does not exist, gitit will create it
+# and populate it with required scripts, stylesheets, and images.
+
+default-page-type: Markdown
+# specifies the type of markup used to interpret pages in
+# the wiki. Two values are currently supported: Markdown and RST.
+# If Markdown is selected, pandoc's syntax extensions (for footnotes,
+# delimited code blocks, etc.) will be enabled. Note that pandoc's
+# reStructuredText parser is not complete, so some pages may
+# not be rendered correctly if RST is selected.
+
+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.
+
+log-file: gitit.log
+# specifies the path of gitit's log file. If it does not exist,
+# gitit will create it. The log is in Apache combined log format.
+
+log-level: WARNING
+# determines how much information is logged.
+# Possible values (from most to least verbose) are DEBUG, INFO,
+# NOTICE, WARNING, ERROR, CRITICAL, ALERT, EMERGENCY.
+
+front-page: Front Page
+# specifies which wiki page is to be used as the wiki's front page.
+# Gitit creates a default front page on startup, if one does not exist
+# already.
+
+no-delete: Front Page, Help
+# specifies pages that cannot be deleted through the web interface.
+# (They can still be deleted directly using git or darcs.)
+# A comma-separated list of page names. Leave blank to allow
+# every page to be deleted.
+
+no-edit: Help
+# specifies pages that cannot be edited through the web interface.
+# Leave blank to allow every page to be edited.
+
+table-of-contents: yes
+# specifies whether to print a tables of contents (with links to
+# sections) on each wiki page.
+
+plugins:
+# specifies a list of plugins to load. Plugins may be specified
+# either by their path or by their module name. If the plugin name
+# starts with Gitit.Plugin., gitit will assume that the plugin is
+# an installed module and will not try to find a source file.
+# Examples:
+# plugins: plugins/DotPlugin.hs, CapitalizeEmphasisPlugin.hs
+# plugins: plugins/DotPlugin
+# plugins: Gitit.Plugin.InterwikiLinks
+
+max-cache-size: 2000000
+# specifies an upper limit on the size of the in-memory page cache,
+# in bytes.
+
+max-upload-size: 100000
+# specifies an upper limit on the size (in bytes) of files uploaded
+# through the wiki's web interface.
+
+debug-mode: no
+# if "yes", causes debug information to be logged while gitit is running.
+
+mime-types-file: /etc/mime.types
+# specifies the path of a file containing mime type mappings.
+# Each line of the file should contain two fields, separated by
+# whitespace. The first field is the mime type, the second is a
+# file extension. For example:
+# video/x-ms-wmx wmx
+# If the file is not found, some simple defaults will be used.
+
+use-recaptcha: no
+# if "yes", causes gitit to use the reCAPTCHA service
+# (http://recaptcha.net) to prevent bots from creating accounts.
+
+recaptcha-private-key:
+recaptcha-public-key:
+# specifies the public and private keys for the reCAPTCHA service.
+# To get these, you need to create an account at http://recaptcha.net.
+
+access-question:
+access-question-answers:
+# specifies a question that users must answer when they attempt to create
+# an account, along with a comma-separated list of acceptable answers.
+# This can be used to institute a rudimentary password for signing up as
+# a user on the wiki, or as an alternative to reCAPTCHA.
+# Example:
+# access-question: What is the code given to you by Ms. X?
+# access-question-answers: RED DOG, red dog
+
View
@@ -35,7 +35,7 @@ data-files: css/screen.css, css/print.css, css/ie.css, css/hk-pyg.css,
js/jquery-ui.packed.js,
js/preview.js, js/search.js,
data/post-update, data/FrontPage.page, data/Help.page,
- data/template.html, data/SampleConfig.hs,
+ data/template.html, data/default.conf,
plugins/CapitalizeEmphasisPlugin.hs,
plugins/DotPlugin.hs,
plugins/InterwikiPlugin.hs,

0 comments on commit ce07825

Please sign in to comment.