#30: Progress; not yet satisfied.

This commit is contained in:
simon 2017-09-09 23:19:45 +01:00
parent 85097f942a
commit 88d26e6d45
3 changed files with 70 additions and 42 deletions

View file

@ -10,7 +10,15 @@ Smeagol cannot access either its configuration or its content from the jar file,
1. `SMEAGOL_CONFIG` should be the full or relative pathname of a Smeagol [[Configuration]] file;
2. `SMEAGOL_CONTENT_DIR` should be the full or relative pathname of the directory from which Smeagol should serve content (which may initially be empty, but must be writable by the process which runs Smeagol)'
3. `SMEAGOL_PASSWD` should be the full or relative pathname of a Smeagol Passwd file - see [[Security and authentication]]. This file must contain an entry for at least your initial user, and, if you want to administer users through the user interface, must be writable by the process which runs Smeagol;
3. `SMEAGOL_PASSWD` should be the full or relative pathname of a Smeagol Passwd file - see [[Security and authentication]]. This file must contain an entry for at least your initial user, and, if you want to administer users through the user interface, must be writable by the process which runs Smeagol.
**NOTE** that `SMEAGOL_CONTENT_DIR` must contain at least the following files:
1. `_edit-side-bar.md` - the side-bar that should be displayed when editing pages;
2. `_header.md` - the header to be displayed on all pages;
3. `_side-bar.md` - the side-bar that should be displayed when not editing pages.
Standard versions of these files can be found in the [source repository](https://github.com/journeyman-cc/smeagol/tree/master/resources/public/content). All these files should be in markdown format - see [[Extensible Markup]].
You can run the jar file with:

View file

@ -84,6 +84,7 @@
([request]
(edit-page request (util/get-message :default-page-title request) ".md" "edit.html" "_edit-side-bar.md"))
([request default suffix template side-bar]
(or
(show-sanity-check-error)
(let [params (keywordize-keys (:params request))
src-text (:src params)
@ -92,7 +93,11 @@
file-path (cjio/file util/content-dir file-name)
exists? (.exists (cjio/as-file file-path))
user (session/get :user)]
(if-not exists? (timbre/info (format "File '%s' not found; creating a new file" file-path)) (timbre/info (format "Opening '%s' for editing" file-path)))
(if-not
exists?
(timbre/info
(format "File '%s' not found; creating a new file" file-path))
(timbre/info (format "Opening '%s' for editing" file-path)))
(cond src-text (process-source params suffix request)
true
(layout/render template
@ -101,7 +106,7 @@
:page page
:side-bar (md->html (slurp (cjio/file util/content-dir side-bar)))
:content (if exists? (slurp file-path) "")
:exists exists?}))))))
:exists exists?})))))))
(defn edit-css-page
@ -181,7 +186,7 @@
(timbre/info (format "Showing version '%s' of page '%s'" version page))
(layout/render "wiki.html"
(merge (util/standard-params request)
{:title (str (util/get-message :vers-col-hdr request) " " version " of " page)
{:title (str (util/get-message :vers-col-hdr request) " " version " " (util/get-message :of request) " " page)
:page page
:content (md->html content)}))))
@ -196,9 +201,18 @@
(timbre/info (format "Showing diff between version '%s' of page '%s' and current" version page))
(layout/render "wiki.html"
(merge (util/standard-params request)
{:title (str (util/get-message :diff-title-prefix request)" " version " of " page)
{:title
(str
(util/get-message :diff-title-prefix request)
" "
version
" "
(util/get-message :of request)
" "
page)
:page page
:content (d2h/diff2html (hist/diff util/content-dir file-name version))}))))
:content (d2h/diff2html
(hist/diff util/content-dir file-name version))}))))
(defn auth-page
@ -225,7 +239,9 @@
true
(layout/render "auth.html"
(merge (util/standard-params request)
{:title (if user (str (util/get-message :logout-link request) " " user) (util/get-message :login-link request))
{:title (if user
(str (util/get-message :logout-link request) " " user)
(util/get-message :login-link request))
:redirect-to ((:headers request) "referer")}))))))

View file

@ -2,13 +2,7 @@
:author "Simon Brooke"}
smeagol.sanity
(:require [clojure.java.io :as cjio]
[clojure.string :as s]
[compojure.response :refer [Renderable]]
[environ.core :refer [env]]
[hiccup.core :refer [html]]
[ring.util.anti-forgery :refer [anti-forgery-field]]
[ring.util.response :refer [content-type response]]
[selmer.parser :as parser]
[smeagol.configuration :refer [config]]
[smeagol.util :as util]
[taoensso.timbre :as timbre]))
@ -36,9 +30,12 @@
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn check-content-dir []
(defn check-content-dir
"Check that the content directory exists and is populated. Throw exception
if not."
[]
(try
(let [directory (cjio/as-file (cjio/resource util/content-dir))]
(let [directory (cjio/as-file util/content-dir)]
(if
(.isDirectory directory)
true
@ -50,31 +47,38 @@
(catch Exception any
(throw (Exception. (str "Content directory '" util/content-dir "' does not exist") any))))
(try
(slurp (cjio/resource (str util/content-dir java.io.File/separator "_side-bar.md")))
(doall
(map
#(let
[path (cjio/file util/content-dir %)]
(timbre/info "Checking the existence of " path)
(slurp path))
["_side-bar.md" "_edit-side-bar.md" "_header.md"]))
(timbre/info "Content directory '" util/content-dir "' check completed.")
(catch Exception any
(throw (Exception. (str "Content directory '" util/content-dir "' is not initialised") any)))))
(defn- raw-sanity-check-installation []
(check-content-dir)
(config :test))
(defn sanity-check-installation []
(defn- raw-sanity-check-installation
"Actually do the sanity check."
[]
(timbre/info "Running sanity check")
(check-content-dir)
(config :test)
(timbre/info "Sanity check completed"))
;;(def sanity-check-installation (memoize raw-sanity-check-installation))
;;; We memoise the sanity check so that although it is called for every wiki
;;; page, it is only actually evaluated once.
(def sanity-check-installation (memoize raw-sanity-check-installation))
(defn- get-causes [any]
(defn- get-causes
"Get the causes of this `error`, if it is an Exception."
[error]
(if
(instance? Exception any)
(cons any (get-causes (.getCause any)))
(instance? Exception error)
(cons error (get-causes (.getCause error)))
'()))