mirror of
https://github.com/journeyman-cc/smeagol.git
synced 2026-04-12 18:05:06 +00:00
Upversioned to 0.5.1-SNAPSHOT; diff2html now works; many packages
(but not timbre) updated; documentation improved.
This commit is contained in:
parent
b31b50b976
commit
baaa153bcc
16 changed files with 400 additions and 261 deletions
30
project.clj
30
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}}}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -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.
|
||||
|
|
@ -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]]
|
||||
|
||||
|
|
|
|||
|
|
@ -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)));
|
||||
}
|
||||
|
||||
|
||||
.change {
|
||||
background-color: rgb( 223, 223, 223);
|
||||
border: thin solid silver;
|
||||
}
|
||||
|
||||
|
||||
.error {
|
||||
width: 100%;
|
||||
background-color: red;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.widget {
|
||||
background-color: silver;
|
||||
border: thin solid white;
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
width: 100%;
|
||||
.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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;
|
||||
;;;; 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 "<p><ins>" (subs line 1) "</ins></p>")
|
||||
(starts-with? line "-") (str "<p><del>" (subs line 1) "</del></p>")
|
||||
(starts-with? line "@@") "</div><div class='change'>"
|
||||
(starts-with? line "\\") (str "<p class='warn'>" (subs line 1) "</p>")
|
||||
:true (str "<p>" line "</p>")))
|
||||
|
||||
|
||||
(defn diff2html
|
||||
"Convert this string, assumed to be in diff format, to HTML."
|
||||
[^String diff-text]
|
||||
;; TODO doesn't work yet
|
||||
(str "<pre>" diff-text "</pre>"))
|
||||
(apply str
|
||||
(flatten
|
||||
(list "<div class='change'>"
|
||||
(join "\n"
|
||||
(remove nil?
|
||||
(map mung-line
|
||||
;; The first five lines are boilerplate, and
|
||||
;; uninteresting for now
|
||||
(drop 5
|
||||
(split-lines diff-text)))))
|
||||
"</div>"))))
|
||||
|
||||
|
||||
|
|
@ -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))
|
||||
|
||||
|
|
|
|||
|
|
@ -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`.
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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 []
|
||||
|
|
|
|||
|
|
@ -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 "<a href='wiki?page=%s'>%s</a>" 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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue