From baaa153bcca59c2f2d3264cc2b5664e6791d9871 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 20 Aug 2016 22:03:20 +0100 Subject: [PATCH] Upversioned to 0.5.1-SNAPSHOT; diff2html now works; many packages (but not timbre) updated; documentation improved. --- project.clj | 30 +++++----- resources/public/content/Introduction.md | 69 ++++------------------ resources/public/content/_edit-left-bar.md | 2 +- resources/public/content/_header.md | 2 +- resources/public/content/_left-bar.md | 19 +++++- resources/public/css/standard.css | 46 ++++++++++----- src/smeagol/authenticate.clj | 55 +++++++++-------- src/smeagol/diff2html.clj | 63 ++++++++++++++++++-- src/smeagol/handler.clj | 44 ++++++++------ src/smeagol/history.clj | 45 ++++++++------ src/smeagol/layout.clj | 45 ++++++++------ src/smeagol/middleware.clj | 48 +++++++++------ src/smeagol/repl.clj | 45 ++++++++------ src/smeagol/routes/wiki.clj | 60 ++++++++++++------- src/smeagol/session_manager.clj | 44 ++++++++------ src/smeagol/util.clj | 44 ++++++++------ 16 files changed, 400 insertions(+), 261 deletions(-) diff --git a/project.clj b/project.clj index 99a6f1f..79b1b8f 100644 --- a/project.clj +++ b/project.clj @@ -1,21 +1,21 @@ -(defproject smeagol "0.5.0-rc1" +(defproject smeagol "0.5.1-SNAPSHOT" :description "A simple Git-backed Wiki inspired by Gollum" :url "https://github.com/simon-brooke/smeagol" - :dependencies [[org.clojure/clojure "1.6.0"] - [org.clojure/core.memoize "0.5.6"] - [lib-noir "0.9.4" :exclusions [org.clojure/tools.reader]] + :dependencies [[org.clojure/clojure "1.7.0"] + [org.clojure/core.memoize "0.5.9"] + [lib-noir "0.9.9" :exclusions [org.clojure/tools.reader]] [com.cemerick/url "0.1.1"] - [ring-server "0.3.1"] - [selmer "0.7.2"] + [ring-server "0.4.0"] + [selmer "1.0.7"] [com.taoensso/timbre "3.3.1" :exclusions [org.clojure/tools.reader]] [com.taoensso/tower "3.0.2" :exclusions [com.taoensso/encore]] - [markdown-clj "0.9.55" :exclusions [com.keminglabs/cljx]] - [crypto-password "0.1.3"] - [clj-jgit "0.8.2"] - [environ "1.0.0"] - [im.chit/cronj "1.4.2"] - [noir-exception "0.2.2"] - [prone "0.6.0"]] + [markdown-clj "0.9.89" :exclusions [com.keminglabs/cljx]] + [crypto-password "0.2.0"] + [clj-jgit "0.8.9"] + [environ "1.1.0"] + [im.chit/cronj "1.4.4"] + [noir-exception "0.2.5"] + [prone "1.1.1"]] :repl-options {:init-ns smeagol.repl} :jvm-opts ["-server"] @@ -35,8 +35,8 @@ :stacktraces? false :auto-reload? false}} :dev {:dependencies [[ring-mock "0.1.5"] - [ring/ring-devel "1.3.1"] - [pjstadig/humane-test-output "0.6.0"]] + [ring/ring-devel "1.5.0"] + [pjstadig/humane-test-output "0.8.1"]] :injections [(require 'pjstadig.humane-test-output) (pjstadig.humane-test-output/activate!)] :env {:dev true}}} diff --git a/resources/public/content/Introduction.md b/resources/public/content/Introduction.md index 7a2ea63..be73b46 100644 --- a/resources/public/content/Introduction.md +++ b/resources/public/content/Introduction.md @@ -1,66 +1,21 @@ -# Welcome to Smeagol! +# Welcome to the Levellers Wiki -Smeagol is a simple Wiki engine inspired by [Gollum](https://github.com/gollum/gollum/wiki). Gollum is a Wiki engine written in Ruby, which uses a number of simple text formats including [Markdown](http://daringfireball.net/projects/markdown/), and which uses [Git](http://git-scm.com/) to provide versioning and backup. I needed a new Wiki for a project and thought Gollum would be ideal - but unfortunately it doesn't provide user authentication, which I needed, and it was simpler for me to reimplement the bits I did need in Clojure than to modify Gollum. +This is a sort of loose online thinktank for the radical left in rural Scotland. -So at this stage Smeagol is a Wiki engine written in Clojure which uses Markdown as its text format, which does have user authentication, and which uses Git as its versioning and backup system. +## Latest additions -## Status +* [[Birnam workshop]] +* [[Holding size]] +* [[Local Government: key policy issues]] -Smeagol is now a fully working small Wiki engine, and meets my own immediate needs. There are some obvious -things which could be improved - see **TODO** list below - but it works now and doesn't seem to have any major problems. +## Everything is new -## Markup syntax +And in fact there's not much here yet. The software is also new and may break; if it does, please contact [[Simon]]. -Smeagol uses the Markdown format as provided by [markdown-clj](https://github.com/yogthos/markdown-clj), with the addition that anything enclosed in double square brackets, \[\[like this\]\], will be treated as a link into the wiki itself. +## Come and join in -## Security and authentication +This isn't an 'anybody can edit it' wiki; it's a bunch of people all of whom more or less know each other, trying to get a consistent policy platform together. But we aren't seeking to be exclusive. If you'd like to join the editing group, please contact [[Simon]]. -Security is now greatly improved. There is a file called *passwd* in the *resources* directory, which contains a clojure map which maps usernames to maps with plain-text passwords and emails thus: +## Please feel free to use our ideas - {:admin {:password "admin" :email "admin@localhost"} - :adam {:password "secret" :email "adam@localhost"}} - -that is to say, the username is a keyword and the corresponding password is a string. However, since version 0.5.0, users can now change their own passwords, and when the user changes their password their new password is encrypted using the [scrypt](http://www.tarsnap.com/scrypt.html) one-way encryption scheme. The password file is now no longer either in the *resources/public* directory so cannot be downloaded through the browser, nor in the git archive to which the Wiki content is stored, so that even if that git archive is remotely clonable an attacker cannot get the password file that way. - -There's still no mechanism to add a new user to the system through the user interface; you do sill have to do that by editing the password file in an editor. - -## Todo - -* Image (and other media) upload; -* Improved editor. The editor is at present very primitive - right back from the beginnings of the Web. It would be nice to have a rich embedded editor like [Hallo](https://github.com/bergie/hallo) or [Aloha](http://aloha-editor.org/Content.Node/index.html) but I haven't (yet) had time to integrate them! -* Transform diff output to HTML to show changes in a more user friendly format; -* Mechanism to add users through the user interface; - -## License - -Copyright © 2014-2015 Simon Brooke. Licensed under the GNU General Public License, -version 2.0 or (at your option) any later version. If you wish to incorporate -parts of Smeagol into another open source project which uses a less restrictive -license, please contact me; I'm open to dual licensing it. - -## Prerequisites - -You will need [Leiningen][1] 2.0 or above installed. - -[1]: https://github.com/technomancy/leiningen - -## Running - -To start a web server for the application, run: - - lein ring server - -or more probably - - nohup lein ring server > smeagol.log & - -Alternatively, if you want to deploy to a servlet container (which I would strongly recommend), the simplest thing is to run: - - lein ring uberwar - -(a command which I'm sure Smeagol would entirely appreciate) and deploy the resulting war file. - - -## Editing the framing content - -You can edit the [[\_left-bar]], the [[\_edit-left-bar]], and the [[\_header]]. +This is not a party political wiki, although some of us may be members of the Greens, the SNP, or other parties. We'd be very pleased if any party adopted policy we develop. \ No newline at end of file diff --git a/resources/public/content/_edit-left-bar.md b/resources/public/content/_edit-left-bar.md index 7e15569..bbd61ca 100644 --- a/resources/public/content/_edit-left-bar.md +++ b/resources/public/content/_edit-left-bar.md @@ -10,4 +10,4 @@ + \*\***bold**\*\* + \__italic_\_ -More documentation [here](http://daringfireball.net/projects/markdown/syntax) +More documentation [here](http://daringfireball.net/projects/markdown/syntax) \ No newline at end of file diff --git a/resources/public/content/_header.md b/resources/public/content/_header.md index d50260c..3bfc0ac 100644 --- a/resources/public/content/_header.md +++ b/resources/public/content/_header.md @@ -1 +1 @@ -This is the header. There isn't yet much in it. You could [edit](edit?page=_header) it to provide internal navigation or branding. +**Levellers** | A wiki for collaboratively developing left-wing policy for rural Scotland. \ No newline at end of file diff --git a/resources/public/content/_left-bar.md b/resources/public/content/_left-bar.md index 4eb8b93..776fca4 100644 --- a/resources/public/content/_left-bar.md +++ b/resources/public/content/_left-bar.md @@ -1 +1,18 @@ -This is the left bar. There's nothing in it yet. You could [edit](edit?page=_left-bar) it to provide internal navigation or branding. +## Topic areas + +* [[Agriculture]] +* [[Broadband]] +* [[Employment and Industry]] +* [[Energy and Fuel]] +* [[Housing]] +* [[Land Ownership]] +* [[Land Reform]] +* [[Land Taxation]] +* [[Local Government]] +* [[Transport]] + +## About + +* [[Authors]] +* [[Editing Guidelines]] + diff --git a/resources/public/css/standard.css b/resources/public/css/standard.css index 7e8052a..17fdd3e 100644 --- a/resources/public/css/standard.css +++ b/resources/public/css/standard.css @@ -57,6 +57,7 @@ body { #nav-menu { margin: 0; + padding: 0; } #nav ul li { @@ -165,17 +166,21 @@ li.nav-item a:active { background: gray; color: white; } (document.documentElement.clientHeight-this.offsetHeight))); } -.error { - background-color: red; - color: white; + +.change { + background-color: rgb( 223, 223, 223); + border: thin solid silver; } -.widget { - background-color: silver; - border: thin solid white; - margin-top: 0; - margin-bottom: 0; + +.error { width: 100%; + background-color: red; + color: white; +} + +.message { + border: thin solid red; } .minor-controls { @@ -186,27 +191,36 @@ li.nav-item a:active { background: gray; color: white; } background:rgba(40,40,40,0.8); font-size: 66%; } + .minor-controls a { float: right; color: white; } -.message { - border: thin solid red; +.warn { + color: maroon; +} + +.widget { + background-color: silver; + border: thin solid white; + margin-top: 0; + margin-bottom: 0; + width: 100%; } .wiki { margin: 0; } -div.error { - width: 100%; -} - form { border: thin solid silver; } +del { + color: red; +} + div.content, form, p, pre, h1, h2, h3, h4, h5 { padding: 0.25em 5%; } @@ -233,6 +247,10 @@ input.required:after { color: red; } +ins { + color: green; +} + label { width: 20%; min-width: 20em; diff --git a/src/smeagol/authenticate.clj b/src/smeagol/authenticate.clj index 74cffa2..6decdbf 100644 --- a/src/smeagol/authenticate.clj +++ b/src/smeagol/authenticate.clj @@ -1,31 +1,37 @@ -(ns smeagol.authenticate +(ns ^{:doc "Authentication functions." + :author "Simon Brooke"} + smeagol.authenticate (:use clojure.walk) (:require [taoensso.timbre :as timbre] [noir.io :as io] [crypto.password.scrypt :as password])) -;; Smeagol: a very simple Wiki engine -;; Copyright (C) 2014 Simon Brooke - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the GNU General Public License -;; as published by the Free Software Foundation; either version 2 -;; of the License, or (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program; if not, write to the Free Software -;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; -;; All functions which relate to the passwd file are in this namespace, in order -;; that it can reasonably simply swapped out for a more secure replacement. -;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; +;;;; Smeagol: a very simple Wiki engine. +;;;; +;;;; This program is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU General Public License +;;;; as published by the Free Software Foundation; either version 2 +;;;; of the License, or (at your option) any later version. +;;;; +;;;; This program is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program; if not, write to the Free Software +;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +;;;; USA. +;;;; +;;;; Copyright (C) 2014 Simon Brooke +;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; +;;;; All functions which relate to the passwd file are in this namespace, in order +;;;; that it can reasonably simply swapped out for a more secure replacement. +;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defn authenticate @@ -48,6 +54,9 @@ user ((keyword username) users)] (if user (:email user)))) +;;; TODO: worth locking the passwd file to prevent corruption if two simultaneous threads +;;; try to write it. See http://stackoverflow.com/questions/6404717/idiomatic-file-locking-in-clojure + (defn change-pass "Change the password for the user with this `username` and `oldpass` to this `newpass`. Return `true` if password was successfully changed. Subsequent to user change, their diff --git a/src/smeagol/diff2html.clj b/src/smeagol/diff2html.clj index f84d38e..0369d24 100644 --- a/src/smeagol/diff2html.clj +++ b/src/smeagol/diff2html.clj @@ -1,8 +1,63 @@ -(ns smeagol.diff2html) +(ns ^{:doc "Format a diff as HTML." + :author "Simon Brooke"} + smeagol.diff2html + (:require [clojure.string :refer [join split split-lines]])) -(defn diff2html +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; +;;;; Smeagol: a very simple Wiki engine. +;;;; +;;;; This program is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU General Public License +;;;; as published by the Free Software Foundation; either version 2 +;;;; of the License, or (at your option) any later version. +;;;; +;;;; This program is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program; if not, write to the Free Software +;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +;;;; USA. +;;;; +;;;; Copyright (C) 2014 Simon Brooke +;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + +(defn starts-with? + "True if `s` starts with this `prefix`" + [^String s ^String prefix] + (.startsWith s prefix)) + + +(defn mung-line + "Convert a single line from diff to HTML" + [^String line] + (cond + (starts-with? line "+") (str "

" (subs line 1) "

") + (starts-with? line "-") (str "

" (subs line 1) "

") + (starts-with? line "@@") "
" + (starts-with? line "\\") (str "

" (subs line 1) "

") + :true (str "

" line "

"))) + + +(defn diff2html "Convert this string, assumed to be in diff format, to HTML." [^String diff-text] ;; TODO doesn't work yet - (str "
" diff-text "
")) - \ No newline at end of file + (apply str + (flatten + (list "
" + (join "\n" + (remove nil? + (map mung-line + ;; The first five lines are boilerplate, and + ;; uninteresting for now + (drop 5 + (split-lines diff-text))))) + "
")))) + + diff --git a/src/smeagol/handler.clj b/src/smeagol/handler.clj index f72f6eb..d76f85d 100644 --- a/src/smeagol/handler.clj +++ b/src/smeagol/handler.clj @@ -1,21 +1,6 @@ -;; Smeagol: a very simple Wiki engine -;; Copyright (C) 2014 Simon Brooke - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the GNU General Public License -;; as published by the Free Software Foundation; either version 2 -;; of the License, or (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program; if not, write to the Free Software -;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -(ns smeagol.handler +(ns ^{:doc "Set up, configure, and clean up after the wiki server." + :author "Simon Brooke"} + smeagol.handler (:require [compojure.core :refer [defroutes]] [smeagol.routes.wiki :refer [wiki-routes]] [smeagol.middleware :refer [load-middleware]] @@ -32,6 +17,29 @@ [environ.core :refer [env]] [cronj.core :as cronj])) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; +;;;; Smeagol: a very simple Wiki engine. +;;;; +;;;; This program is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU General Public License +;;;; as published by the Free Software Foundation; either version 2 +;;;; of the License, or (at your option) any later version. +;;;; +;;;; This program is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program; if not, write to the Free Software +;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +;;;; USA. +;;;; +;;;; Copyright (C) 2014 Simon Brooke +;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (defn user-access [request] (session/get :user)) diff --git a/src/smeagol/history.clj b/src/smeagol/history.clj index d9aaf24..134701d 100644 --- a/src/smeagol/history.clj +++ b/src/smeagol/history.clj @@ -1,4 +1,6 @@ -(ns smeagol.history +(ns ^{:doc "Explore the history of a page." + :author "Simon Brooke"} + smeagol.history (:require [taoensso.timbre :as timbre] [clj-jgit.porcelain :as git] [clj-jgit.internal :as i] @@ -10,22 +12,28 @@ [org.eclipse.jgit.treewalk.filter PathFilter] [org.eclipse.jgit.diff DiffEntry DiffFormatter])) -;; Smeagol: a very simple Wiki engine -;; Copyright (C) 2014 Simon Brooke - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the GNU General Public License -;; as published by the Free Software Foundation; either version 2 -;; of the License, or (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program; if not, write to the Free Software -;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; +;;;; Smeagol: a very simple Wiki engine. +;;;; +;;;; This program is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU General Public License +;;;; as published by the Free Software Foundation; either version 2 +;;;; of the License, or (at your option) any later version. +;;;; +;;;; This program is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program; if not, write to the Free Software +;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +;;;; USA. +;;;; +;;;; Copyright (C) 2014 Simon Brooke +;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defn entry-contains "If this `log-entry` contains a reference to this `file-path`, return the entry; @@ -40,6 +48,7 @@ (:changed_files log-entry)))) log-entry)) + (defn find-history [^String git-directory-path ^String file-path] "Return the log entries in the repository at this `git-directory-path` which refer to changes to the file at this `file-path`." @@ -67,6 +76,7 @@ (.dispose walk))) result)) + (defn diff "Find the diff in the file at `file-path` within the repository at `git-directory-path` between versions `older` and `newer` or between the specified @@ -96,6 +106,7 @@ out))) (.toString out)))) + (defn fetch-version "Return (as a String) the text of this `version` of the file at this `file-path` in the git directory at this `git-directory-path`. diff --git a/src/smeagol/layout.clj b/src/smeagol/layout.clj index 908a475..668ee34 100644 --- a/src/smeagol/layout.clj +++ b/src/smeagol/layout.clj @@ -1,29 +1,39 @@ -;; Smeagol: a very simple Wiki engine -;; Copyright (C) 2014 Simon Brooke -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the GNU General Public License -;; as published by the Free Software Foundation; either version 2 -;; of the License, or (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program; if not, write to the Free Software -;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -(ns smeagol.layout +(ns ^{:doc "Render a page as HTML." + :author "Simon Brooke"} + smeagol.layout (:require [selmer.parser :as parser] [clojure.string :as s] [ring.util.response :refer [content-type response]] [compojure.response :refer [Renderable]] [environ.core :refer [env]])) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; +;;;; Smeagol: a very simple Wiki engine. +;;;; +;;;; This program is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU General Public License +;;;; as published by the Free Software Foundation; either version 2 +;;;; of the License, or (at your option) any later version. +;;;; +;;;; This program is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program; if not, write to the Free Software +;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +;;;; USA. +;;;; +;;;; Copyright (C) 2014 Simon Brooke +;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (def template-path "templates/") + (deftype RenderableTemplate [template params] Renderable (render [this request] @@ -42,6 +52,7 @@ response) "text/html; charset=utf-8"))) + (defn render [template & [params]] (RenderableTemplate. template params)) diff --git a/src/smeagol/middleware.clj b/src/smeagol/middleware.clj index 590d5ff..f285d79 100644 --- a/src/smeagol/middleware.clj +++ b/src/smeagol/middleware.clj @@ -1,21 +1,6 @@ -;; Smeagol: a very simple Wiki engine -;; Copyright (C) 2014 Simon Brooke - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the GNU General Public License -;; as published by the Free Software Foundation; either version 2 -;; of the License, or (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program; if not, write to the Free Software -;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -(ns smeagol.middleware +(ns ^{:doc "In truth, boilerplate provided by LuminusWeb." + :author "Simon Brooke"} + smeagol.middleware (:require [taoensso.timbre :as timbre] [selmer.parser :as parser] [environ.core :refer [env]] @@ -23,18 +8,45 @@ [prone.middleware :refer [wrap-exceptions]] [noir-exception.core :refer [wrap-internal-error]])) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; +;;;; Smeagol: a very simple Wiki engine. +;;;; +;;;; This program is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU General Public License +;;;; as published by the Free Software Foundation; either version 2 +;;;; of the License, or (at your option) any later version. +;;;; +;;;; This program is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program; if not, write to the Free Software +;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +;;;; USA. +;;;; +;;;; Copyright (C) 2014 Simon Brooke +;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + (defn log-request [handler] (fn [req] (timbre/debug req) (handler req))) + (def development-middleware [wrap-error-page wrap-exceptions]) + (def production-middleware [#(wrap-internal-error % :log (fn [e] (timbre/error e)))]) + (defn load-middleware [] (concat (when (env :dev) development-middleware) production-middleware)) diff --git a/src/smeagol/repl.clj b/src/smeagol/repl.clj index a61e76e..58b3efb 100644 --- a/src/smeagol/repl.clj +++ b/src/smeagol/repl.clj @@ -1,25 +1,34 @@ -;; Smeagol: a very simple Wiki engine -;; Copyright (C) 2014 Simon Brooke - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the GNU General Public License -;; as published by the Free Software Foundation; either version 2 -;; of the License, or (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program; if not, write to the Free Software -;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -(ns smeagol.repl +(ns ^{:doc "Functions to allow the wiki to be started and stopped from the REPL." + :author "Simon Brooke"} + smeagol.repl (:use smeagol.handler ring.server.standalone [ring.middleware file-info file])) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; +;;;; Smeagol: a very simple Wiki engine. +;;;; +;;;; This program is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU General Public License +;;;; as published by the Free Software Foundation; either version 2 +;;;; of the License, or (at your option) any later version. +;;;; +;;;; This program is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program; if not, write to the Free Software +;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +;;;; USA. +;;;; +;;;; Copyright (C) 2014 Simon Brooke +;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + (defonce server (atom nil)) (defn get-handler [] diff --git a/src/smeagol/routes/wiki.clj b/src/smeagol/routes/wiki.clj index 820c1d9..3671561 100644 --- a/src/smeagol/routes/wiki.clj +++ b/src/smeagol/routes/wiki.clj @@ -1,23 +1,8 @@ -;; Smeagol: a very simple Wiki engine -;; Copyright (C) 2014 Simon Brooke - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the GNU General Public License -;; as published by the Free Software Foundation; either version 2 -;; of the License, or (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program; if not, write to the Free Software -;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -(ns smeagol.routes.wiki - (:use clojure.walk) - (:require [compojure.core :refer :all] +(ns ^{:doc "Render all the main pages of a very simple Wiki engine." + :author "Simon Brooke"} + smeagol.routes.wiki + (:require [clojure.walk :refer :all] + [compojure.core :refer :all] [clj-jgit.porcelain :as git] [cemerick.url :refer (url url-encode url-decode)] [markdown.core :as md] @@ -33,15 +18,39 @@ [smeagol.util :as util] [smeagol.history :as hist])) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; +;;;; Smeagol: a very simple Wiki engine. +;;;; +;;;; This program is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU General Public License +;;;; as published by the Free Software Foundation; either version 2 +;;;; of the License, or (at your option) any later version. +;;;; +;;;; This program is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program; if not, write to the Free Software +;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +;;;; USA. +;;;; +;;;; Copyright (C) 2014 Simon Brooke +;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (defn local-links "Rewrite text in `html-src` surrounded by double square brackets as a local link into this wiki." - [html-src] + [^String html-src] (clojure.string/replace html-src #"\[\[[^\[\]]*\]\]" #(let [text (clojure.string/replace %1 #"[\[\]]" "") encoded (url-encode text)] (timbre/debug (format "URL encode: '%s' -> '%s'" text encoded)) (format "%s" encoded text)))) + (defn get-git-repo "Get the git repository for my content, creating it if necessary" [] @@ -50,6 +59,7 @@ (if (.exists repo) (git/load-repo repo) (git/git-init path)))) + (defn process-source "Process `source-text` and save it to the specified `file-path`, committing it to Git and finally redirecting to wiki-page." @@ -70,6 +80,7 @@ (response/redirect (str "/wiki?page=" (url-encode page))) )) + (defn edit-page "Render a page in a text-area for editing. This could have been done in the same function as wiki-page, and that would have been neat, but I couldn't see how to establish security if that were done." @@ -91,6 +102,7 @@ :user (session/get :user) :exists exists?})))) + (defn wiki-page "Render the markdown page specified in this `request`, if any. If none found, redirect to edit-page" [request] @@ -110,6 +122,7 @@ :version (System/getProperty "smeagol.version")}) true (response/redirect (str "/edit?page=" page))))) + (defn history-page "Render the history for the markdown page specified in this `request`, if any. If none, error?" @@ -125,6 +138,7 @@ :header (local-links (util/md->html "/content/_header.md")) :history (hist/find-history repo-path file-name)}))) + (defn version-page "Render a specific historical version of a page" [request] @@ -146,6 +160,7 @@ repo-path file-name version))) :user (session/get :user)}))) + (defn diff-page "Render a diff between two versions of a page" [request] @@ -164,6 +179,7 @@ :content (d2h/diff2html (hist/diff repo-path file-name version)) :user (session/get :user)}))) + (defn auth-page "Render the auth page" [request] @@ -191,6 +207,7 @@ :header (local-links (util/md->html "/content/_header.md")) :user user})))) + (defn passwd-page "Render a page to change the user password" [request] @@ -213,6 +230,7 @@ :header (local-links (util/md->html "/content/_header.md")) :message message}))) + (defroutes wiki-routes (GET "/wiki" request (wiki-page request)) (GET "/" request (wiki-page request)) diff --git a/src/smeagol/session_manager.clj b/src/smeagol/session_manager.clj index fc31064..75f85d1 100644 --- a/src/smeagol/session_manager.clj +++ b/src/smeagol/session_manager.clj @@ -1,24 +1,32 @@ -;; Smeagol: a very simple Wiki engine -;; Copyright (C) 2014 Simon Brooke - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the GNU General Public License -;; as published by the Free Software Foundation; either version 2 -;; of the License, or (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program; if not, write to the Free Software -;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -(ns smeagol.session-manager +(ns ^{:doc "In truth, boilerplate provided by LuminusWeb." + :author "Simon Brooke"} + smeagol.session-manager (:require [noir.session :refer [clear-expired-sessions]] [cronj.core :refer [cronj]])) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; +;;;; Smeagol: a very simple Wiki engine. +;;;; +;;;; This program is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU General Public License +;;;; as published by the Free Software Foundation; either version 2 +;;;; of the License, or (at your option) any later version. +;;;; +;;;; This program is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program; if not, write to the Free Software +;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +;;;; USA. +;;;; +;;;; Copyright (C) 2014 Simon Brooke +;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (def cleanup-job (cronj :entries diff --git a/src/smeagol/util.clj b/src/smeagol/util.clj index dc1c324..791b77b 100644 --- a/src/smeagol/util.clj +++ b/src/smeagol/util.clj @@ -1,24 +1,32 @@ -;; Smeagol: a very simple Wiki engine -;; Copyright (C) 2014 Simon Brooke - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the GNU General Public License -;; as published by the Free Software Foundation; either version 2 -;; of the License, or (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program; if not, write to the Free Software -;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -(ns smeagol.util +(ns ^{:doc "Miscellaneous utility functions supporting Smeagol." + :author "Simon Brooke"} + smeagol.util (:require [noir.io :as io] [markdown.core :as md])) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; +;;;; Smeagol: a very simple Wiki engine. +;;;; +;;;; This program is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU General Public License +;;;; as published by the Free Software Foundation; either version 2 +;;;; of the License, or (at your option) any later version. +;;;; +;;;; This program is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program; if not, write to the Free Software +;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +;;;; USA. +;;;; +;;;; Copyright (C) 2014 Simon Brooke +;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (defn md->html "reads a markdown file from public/md and returns an HTML string" [filename]