Rather nice and satisfactory. Slightly conflates the issue of configuration and internationalisation at present, but I think internationalisation is a target to hit as a separate job.
This commit is contained in:
simon 2017-03-12 17:14:43 +00:00
parent 5d9462b7c3
commit 2f897089fe
17 changed files with 295 additions and 186 deletions

3
.gitignore vendored
View file

@ -13,4 +13,5 @@ pom.xml.asc
.lein-plugins/
.lein-failures
.lein-env
.nrepl-port
smeagol.log*

104
resources/config.edn Normal file
View file

@ -0,0 +1,104 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
;;;; 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) 2017 Simon Brooke
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; config.edn: a simple configuration map for Smeagol; inspired by Cryogen.
;;; This is essentially all the text in the chrome - that which isn't editable
;;; through the wiki itself
;; ; ; ; ; ; ; ; ; ;
{:add-user-label "Add new user" ;; label for the add user link on edit users page
:change-pass-label "Change password!"
;; text of the change password widget itself on the
;; change password page
:change-pass-link "Change password"
;; text of the change password link on the menu
:change-pass-prompt "To change your password"
;; text of the change password widget prompt on the
;; change password page
:change-col-hdr "Changes" ;; header for the changes column in history
:chpass-bad-match "Your proposed passwords don't match"
;; error text if proposed passwords don't match
:chpass-fail "Your password was not changed"
;; error text on fail other htan too short or bad match
:chpass-success "Your password was changed"
;; confirmation text on password change
:chpass-too-short "You proposed password wasn't long enough: eight characters required"
;; error text if proposed password is too short
:chpass-title-prefix "Change password for"
;; prefix for title of change password page
:cookies-about "About cookies" ;; about cookies text
:cookies-more "This website stores session information as a 'cookie' on your browser. This helps us show you the content you want to see. This cookie does not identify you, and cannot be read by other websites. It is deleted by your browser as soon as you leave this site. This website does not use any third party cookies, so your visit here cannot be tracked by other websites."
;; more about cookies text
:default-page-title "Introduction" ;; title of the default page in this wiki
:del-col-hdr "Delete" ;; header for delete column on edit users page
:del-user-fail "Could not delete user"
;; error message on failure to delete user
:del-user-success "Successfully deleted user"
;; confirmation message on deletion of user
:diff-title-prefix "Changes since version"
;; prefix for the header of the changes page
:edit-col-hdr "Edit" ;; header for edit column on edit users page
:edit-page-link "Edit this page"
;; text of the edit page link on the content frame
:edit-title-prefix "Edit" ;; prefix for title of edit content page
:edit-users-link "Edit users" ;; text of the edit users link on the menu
:edit-users-title "Select user to edit"
;; title of edit users page
:email-prompt "Email address" ;; text of the email widget prompt on edit user page
:is-admin-prompt "Is administrator?"
:home-link "Home" ;; text of the home link on the menu
:login-label "Log in!" ;; text of the login widget on the login page
:login-link "Log in" ;; text of the login link on the menu
:login-prompt "To edit this wiki"
;; text of the action widget prompt on the login page
:logout-label "Log out!" ;; text of the logout widget on the logout page
:logout-link "Log out" ;; text of the logout link on the menu
:logged-in-as "You are logged in as"
;; text of the 'logged in as' label on the menu
:history-link "History" ;; text of the history link on the content frame
:history-title-prefix "History of" ;; prefix of the title on the history page
:new-pass-prompt "New password" ;; text of the new password widget prompt on the change
;; password and edit user pages
:old-pass-prompt "Your password"
;; text of the old password widget prompt on the change
;; password page, and password widget on login page
:rpt-pass-prompt "And again" ;; text of the new password widget prompt on the change
;; password and edit user pages
:save-prompt "When you have finished editing"
;; text of the save widget label on edit content
;; and edit user page
:save-label "Save!" ;; text of the save widget itself
:save-user-fail "Failed to store user"
:save-user-success "Successfully stored user"
:site-title "Smeagol" ;; overall title of the site, used in page headings
:username-prompt "Username" ;; text of the username widget prompt on edit user page
;; text of the is admin widget prompt on edit user page
:user-title-prefix "Edit user" ;; prefix for title of edit user page
:vers-col-hdr "Version" ;; header for the version column in history
:what-col-hdr "What" ;; header for the what column in history
:what-changed-prompt "What have you changed?"
;; text of the summary widget prompt on edit
;; content page
:when-col-hdr "When" ;; header for the when column in history
:your-uname-prompt "Your username" ;; text of the username widget prompt on the login page
}

View file

@ -1 +1 @@
{:admin {:admin true, :email "info@weft.scot", :password "admin"}}
{:admin {:admin true, :email "info@weft.scot", :password "$s0$f0801$27PoPWXDignJVpW1YZ9XTQ==$7cBOqLnlfohYYVY+Xiwr0CNyXDaw5TasRdG3D2v7G90="}, :fred {:email "fred@flintstone.bc", :admin false, :password "$s0$f0801$DOSa7z2466L994V9VIsoCA==$5/GueN3WsR+r+fiSdmiJqZnbzdIwUx0BXR3yd9OK8Wc="}}

View file

@ -1,91 +1,88 @@
![One wiki to rule them all](https://www.weft.scot/images/smeagol.png)
# Welcome to Smeagol!
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.
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.
## Status
Smeagol is now a fully working small Wiki engine, and meets my own immediate needs.
## Markup syntax
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.
## Security and authentication
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:
{:admin {:password "admin" :email "admin@localhost" :admin true}
: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.
## Images
Smeagol does not currently have any mechanism to upload images. You can, however, link to images already available on the web, like this:
![Smeagol](http://vignette3.wikia.nocookie.net/lotr/images/e/e1/Gollum_Render.png/revision/latest?cb=20141218075509)
## Todo
* Mechanism to add users through the user interface;
## Advertisement
If you like what you see here, I am available for work on open source Clojure projects. Contact me via [WEFT](http://www.weft.scot/).
### Phoning home
Smeagol currently requests the WEFT logo in the page footer from my home site. This is mainly so I can get a feel for how many people are using the product. If you object to this, edit the file
resources/templates/base.html
and replace the line
<img height="16" width="16" alt="The Web Engineering Factory &amp; Toolworks" src="http://www.weft.scot/images/weft.logo.64.png"> Developed by <a href="http://www.weft.scot/">WEFT</a>
with the line
<img height="16" width="16" alt="The Web Engineering Factory &amp; Toolworks" src="img/weft.logo.64.png"> Developed by <a href="http://www.weft.scot/">WEFT</a>
## 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](https://github.com/technomancy/leiningen) 2.0 or above installed.
You will need [node](https://nodejs.org/en/) and [bower](https://bower.io/) installed.
## Running
To start a web server for the application, run:
lein bower install
lein ring server
Alternatively, if you want to deploy to a servlet container (which I would strongly recommend), the simplest thing is to run:
lein bower install
lein ring uberwar
(a command which I'm sure Smeagol would entirely appreciate) and deploy the resulting war file.
## Experimental Docker image
You can now run Smeagol as a [Docker](http://www.docker.com) image. To run my Docker image, use
docker run simonbrooke/smeagol
Smeagol will run, obviously, on the IP address of your Docker image, on port 8080. To find the IP address, start the image using the command above and then use
docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -q)
Suppose this prints '10.10.10.10', then the URL to browse to will be http://10.10.10.10:8080/smeagol/
This image is _experimental_, but it does seem to work fairly well. What it does **not** yet do, however, is push the git repository to a remote location, so when you tear the Docker image down your edits will be lost. My next objective for this image is for it to have a cammand line parameter being the git address of a repository from which it can initialise the Wiki content, and to which it will periodically push local changes to the Wiki content.
To build your own Docker image, run:
lein clean
lein bower install
lein ring uberwar
lein docker build
This will build a new Docker image locally; you can, obviously, push it to your own Docker repository if you wish.
![One wiki to rule them all](https://www.weft.scot/images/smeagol.png)
# Welcome to Smeagol!
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.
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.
## Status
Smeagol is now a fully working small Wiki engine, and meets my own immediate needs.
## Markup syntax
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.
## Security and authentication
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:
{:admin {:password "admin" :email "admin@localhost" :admin true}
: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.
## Images
Smeagol does not currently have any mechanism to upload images. You can, however, link to images already available on the web, like this:
![Smeagol](http://vignette3.wikia.nocookie.net/lotr/images/e/e1/Gollum_Render.png/revision/latest?cb=20141218075509)
## Advertisement
If you like what you see here, I am available for work on open source Clojure projects. Contact me via [WEFT](http://www.weft.scot/).
### Phoning home
Smeagol currently requests the WEFT logo in the page footer from my home site. This is mainly so I can get a feel for how many people are using the product. If you object to this, edit the file
resources/templates/base.html
and replace the line
<img height="16" width="16" alt="The Web Engineering Factory &amp; Toolworks" src="http://www.weft.scot/images/weft.logo.64.png"> Developed by <a href="http://www.weft.scot/">WEFT</a>
with the line
<img height="16" width="16" alt="The Web Engineering Factory &amp; Toolworks" src="img/weft.logo.64.png"> Developed by <a href="http://www.weft.scot/">WEFT</a>
## 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](https://github.com/technomancy/leiningen) 2.0 or above installed.
You will need [node](https://nodejs.org/en/) and [bower](https://bower.io/) installed.
## Running
To start a web server for the application, run:
lein bower install
lein ring server
Alternatively, if you want to deploy to a servlet container (which I would strongly recommend), the simplest thing is to run:
lein bower install
lein ring uberwar
(a command which I'm sure Smeagol would entirely appreciate) and deploy the resulting war file.
## Experimental Docker image
You can now run Smeagol as a [Docker](http://www.docker.com) image. To run my Docker image, use
docker run simonbrooke/smeagol
Smeagol will run, obviously, on the IP address of your Docker image, on port 8080. To find the IP address, start the image using the command above and then use
docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -q)
Suppose this prints '10.10.10.10', then the URL to browse to will be http://10.10.10.10:8080/smeagol/
This image is _experimental_, but it does seem to work fairly well. What it does **not** yet do, however, is push the git repository to a remote location, so when you tear the Docker image down your edits will be lost. My next objective for this image is for it to have a cammand line parameter being the git address of a repository from which it can initialise the Wiki content, and to which it will periodically push local changes to the Wiki content.
To build your own Docker image, run:
lein clean
lein bower install
lein ring uberwar
lein docker build
This will build a new Docker image locally; you can, obviously, push it to your own Docker repository if you wish.

View file

@ -224,20 +224,20 @@ li.nav-item a:active { background: gray; color: white; }
width: 30%;
float: right;
position: fixed;
bottom: 1.5em;
bottom: 3.5em;
right: 0;
z-index: 150;
z-index: 175;
background: transparent;
}
/* about-cookies box: permanently visible part of cookies information box */
#about-cookies {
clear: right;
width: 10em;
font-size: 66%;
float: right;
text-align: right;
padding: 0.25em 2em;
border-radius: 0.25em;
color: white;
background:rgba(40,40,40,0.8);
}
@ -245,7 +245,8 @@ li.nav-item a:active { background: gray; color: white; }
/* more-about-cookies box, normally hidden */
#more-about-cookies {
display: none;
padding: 0.25em 2em;
padding: 0.5em 2em;
border-radius: 0.5em;
color: white;
background:rgba(40,40,40,0.8);
border-bottom: thin solid white;
@ -277,7 +278,9 @@ li.nav-item a:active { background: gray; color: white; }
.minor-controls {
list-style: none;
float: right;
right: 0;
padding: 0.25em 2em;
border-radius: 0.25em;
color: white;
background:rgba(40,40,40,0.8);
font-size: 66%;

View file

@ -5,21 +5,21 @@
<input type="hidden" name="redirect-to" value="{{redirect-to}}"/>
{% if user %}
<p class="widget">
<label for="submit">To finish editing</label>
<input name="action" id="action" type="submit" class="action-dangerous" value="Logout!"/>
<label for="submit">{{config.save-prompt}}</label>
<input name="action" id="action" type="submit" class="action-dangerous" value="{{config.logout-label}}"/>
</p>
{% else %}
<p class="widget">
<label for="username">Your username</label>
<label for="username">{{config.your-uname-prompt}}</label>
<input name="username" id="username" type="text" required/>
</p>
<p class="widget">
<label for="password">Your password</label>
<label for="password">{{config.old-pass-prompt}}</label>
<input name="password" id="password" type="password" required/>
</p>
<p class="widget">
<label for="submit">To edit this wiki</label>
<input name="action" id="action" type="submit" class="action" value="Login!"/>
<label for="submit">{{config.login-prompt}}</label>
<input name="action" id="action" type="submit" class="action" value="{{config.login-label}}"/>
</p>
{% endif %}
</form>

View file

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>{{title}}</title>
<title>{{config.site-title}}: {{title}}</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="{{servlet-context}}/content/stylesheet.css" media="screen and (min-device-width: 1025px)" rel="stylesheet" type="text/css" />
<link href="{{servlet-context}}/css/print.css" media="print" rel="stylesheet" type="text/css" />
@ -13,23 +13,23 @@
<!-- navbar -->
<div id="nav">
{% if user %}
<p class="user" id="user">You are logged in as {{user}} | <a href="passwd">change password</a></p>
<p class="user" id="user">{{config.logged-in-as}} {{user}} | <a href="passwd">{{config.change-pass-link}}</a></p>
{% endif %}
<img id="nav-icon" src="{{servlet-context}}/img/threelines.png" alt="Menu"/>
<ul id="nav-menu" class="nav">
<li class="{{wiki-selected}}"><a href="{{servlet-context}}/">Home</a></li>
<li class="{{wiki-selected}}"><a href="{{servlet-context}}/">{{config.home-link}}</a></li>
{% if admin %}
<li class="{{admin-selected}}"><a href="{{servlet-context}}/edit-users">Edit users</a></li>
<li class="{{admin-selected}}"><a href="{{servlet-context}}/edit-users">{{config.edit-users-link}}</a></li>
{% endif %}
<li class="{{auth-selected}}"><a href="{{servlet-context}}/auth">
{% if user %}
Log out
{{config.logout-link}}
{% else %}
Log in
{{config.login-link}}
{% endif %}</a></li>
</ul>
</div>
<h1>{{title}}</h1>
<h1>{{config.site-title}}: {{title}}</h1>
{{header|safe}}
{% if message %}
<div id="message">
@ -52,13 +52,10 @@
</div>
<div id="cookies">
<div id="more-about-cookies">
This website stores session information as a 'cookie' on your browser. This helps us show you the content
you want to see. This cookie does not identify you, and cannot be read by other websites. It is deleted by
your browser as soon as you leave this site. This website does not use any third party cookies, so your
visit here cannot be tracked by other websites.
{{config.cookies-more}}
</div>
<div id="about-cookies">
About cookies
{{config.cookies-about}}
</div>
</div>
<footer>

View file

@ -6,17 +6,14 @@
<input type="hidden" name="page" value="{{page}}"/>
<textarea name="src" id="src" rows="25" cols="80">{{content}}</textarea>
<p class="widget">
<label for="summary">What have you changed?</label>
<label for="summary">{{config.what-changed-prompt}}</label>
<input name="summary" id="summary" type="text"
value="{%if exists%}{%else%}New file {{title}}{%endif%}" required/>
</p>
<p class="widget">
<label for="submit">When you have finished editing</label>
<input name="submit" id="submit" type="submit" class="action" value="Save!"/>
<label for="submit">{{config.save-prompt}}</label>
<input name="submit" id="submit" type="submit" class="action" value="{{config.save-label}}"/>
</p>
</form>
</div>
<script>
var simplemde = new SimpleMDE();
</script>
{% endblock %}

View file

@ -4,28 +4,28 @@
<div id="content" class="edit">
<form action="{{servlet-context}}/edit-user" method="POST">
<p class="widget">
<label for="target">Username</label>
<label for="target">{{config.username-prompt}}</label>
<input type="text" name="target" id="target" value="{{target}}" required/>
</p>
<p class="widget">
<label for="pass1">New password</label>
<label for="pass1">{{config.new-pass-prompt}}</label>
<input name="pass1" id="pass1" type="password"/>
</p>
<p class="widget">
<label for="pass2">And again</label>
<label for="pass2">{{config.rpt-pass-prompt}}</label>
<input name="pass2" id="pass2" type="password"/>
</p>
<p class="widget">
<label for="email">Email address</label>
<label for="email">{{config.email-prompt}}</label>
<input name="email" id="email" type="text" value="{{details.email}}" required/>
</p>
<p class="widget">
<label for="admin">Is administrator?</label>
<label for="admin">{{config.is-admin-prompt}}</label>
<input name="admin" id="admin" type="checkbox" {% if details.admin %}checked{% endif %}/>
</p>
<p class="widget">
<label for="submit">When you have finished editing</label>
<input name="submit" id="submit" type="submit" class="action" value="Save!"/>
<label for="submit">{{config.save-prompt}}</label>
<input name="submit" id="submit" type="submit" class="action" value="{{config.save-label}}"/>
</p>
</form>
</div>

View file

@ -4,16 +4,16 @@
<div id="content">
<table>
<tr>
<th>Edit</th><th>Delete</th>
<th>{{config.edit-col-hdr}}</th><th>{{config.del-col-hdr}}</th>
</tr>
{% for user in users %}
<tr>
<td><a href="edit-user?target={{user}}">Edit {{user}}</a></td>
<td><a href="delete-user?target={{user}}">Delete {{user}}</a></td>
<td><a href="edit-user?target={{user}}">{{config.edit-col-hdr}} {{user}}</a></td>
<td><a href="delete-user?target={{user}}">{{config.del-col-hdr}} {{user}}</a></td>
</tr>
{% endfor %}
<tr>
<td><a href="edit-user">Add new user</a></td>
<td><a href="edit-user">{{config.add-user-label}}</a></td>
<td></td>
</tr>
</table>

View file

@ -10,13 +10,13 @@
<input type="hidden" name="page" value="{{page}}"/>
<textarea name="src" id="src" rows="25" cols="80">{{content}}</textarea>
<p class="widget">
<label for="summary">What have you changed?</label>
<label for="summary">{{config.what-changed-prompt}}</label>
<input name="summary" id="summary" type="text"
value="{%if exists%}{%else%}New file {{title}}{%endif%}" required/>
</p>
<p class="widget">
<label for="submit">When you have finished editing</label>
<input name="submit" id="submit" type="submit" class="action" value="Save!"/>
<label for="submit">{{config.save-prompt}}</label>
<input name="submit" id="submit" type="submit" class="action" value="{{config.save-label}}"/>
</p>
</form>
</div>

View file

@ -1,26 +1,29 @@
{% extends "templates/base.html" %}
{% block content %}
<div id="content" class="history">
<table>
<tr>
<th>When</th><th>What</th><th>Version</th><th>Changes</th>
</tr>
{% for entry in history %}
<tr>
<td>S
{{entry.time}}
</td>
<td>
{{entry.message}}
</td>
<td>
<a href="version?page={{page}}&amp;version={{entry.id}}">Show version</a>
</td>
<td>
<a href="changes?page={{page}}&amp;version={{entry.id}}">What's changed since?</a>
</td>
</tr>
{% endfor %}
</table>
<table>
<tr>
<th>{{config.when-col-hdr}}</th>
<th>{{config.what-col-hdr}}</th>
<th>{{config.vers-col-hdr}}</th>
<th>{{config.change-col-hdr}}</th>
</tr>
{% for entry in history %}
<tr>
<td>S
{{entry.time}}
</td>
<td>
{{entry.message}}
</td>
<td>
<a href="version?page={{page}}&amp;version={{entry.id}}">Show version</a>
</td>
<td>
<a href="changes?page={{page}}&amp;version={{entry.id}}">What's changed since?</a>
</td>
</tr>
{% endfor %}
</table>
</div>
{% endblock %}

View file

@ -4,8 +4,8 @@
<div id="content" class="wiki">
{% if editable %}
<ul class="minor-controls">
<li><a href="{{servlet-context}}/edit?page={{title}}">Edit this page</a></li>
<li><a href="history?page={{page}}">History</a></li>
<li><a href="{{servlet-context}}/edit?page={{title}}">{{config.edit-page-link}}</a></li>
<li><a href="history?page={{page}}">{{config.history-link}}</a></li>
</ul>
{% endif %}
{{content|safe}}

View file

@ -4,6 +4,7 @@
smeagol.layout
(:require [selmer.parser :as parser]
[clojure.string :as s]
[noir.io :as io]
[ring.util.response :refer [content-type response]]
[compojure.response :refer [Renderable]]
[environ.core :refer [env]]))
@ -33,6 +34,10 @@
(def template-path "templates/")
;; the relative path to the config file.
(def config-file-path (str (io/resource-path) "../config.edn"))
(def config (read-string (slurp config-file-path)))
(deftype RenderableTemplate [template params]
Renderable
@ -40,6 +45,7 @@
(content-type
(->> (assoc params
(keyword (s/replace template #".html" "-selected")) "active"
:config config
:dev (env :dev)
:servlet-context
(if-let [context (:servlet-context request)]

View file

@ -39,7 +39,7 @@
user (session/get :user)]
(layout/render "edit-users.html"
(merge (util/standard-params request)
{:title "Select user to edit"
{:title (:edit-users-title layout/config)
:users (auth/list-users)}))))
(defn delete-user
@ -48,11 +48,11 @@
(let [params (keywordize-keys (:params request))
target (:target params)
deleted (auth/delete-user target)
message (if deleted (str "Successfully deleted user " target))
error (if (not deleted) (str "Could not delete user " target))]
message (if deleted (str (:del-user-success layout/config) " " target "."))
error (if (not deleted) (str (:del-user-fail layout/config) " " target "."))]
(layout/render "edit-users.html"
(merge (util/standard-params request)
{:title "Select user to edit"
{:title (:edit-users-title layout/config)
:message message
:error error
:users (auth/list-users)}))))
@ -67,9 +67,9 @@
password (if (and pass1 (auth/evaluate-password pass1 (:pass2 params))) pass1)
stored (if (:email params)
(auth/add-user target password (:email params) (:admin params)))
message (if stored (str "User " target " was stored successfully."))
message (if stored (str (:save-user-success layout/config) " " target "."))
error (if (and (:email params) (not stored))
(str "User " target " was not stored."))
(str (:save-user-fail layout/config) " " target "."))
details (auth/fetch-user-details target)]
(if message
(timbre/info message))
@ -77,7 +77,7 @@
(timbre/warn error))
(layout/render "edit-user.html"
(merge (util/standard-params request)
{:title (str "Edit user " target)
{:title (str (:edit-title-prefix layout/config) " " target)
:message message
:error error
:target target

View file

@ -74,14 +74,14 @@
(if
(= suffix ".md")
(url-encode page)
"Introduction")))))
(:default-page-title layout/config))))))
(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."
([request]
(edit-page request "Introduction" ".md" "edit.html" "/content/_edit-side-bar.md"))
(edit-page request (:default-page-title layout/config) ".md" "edit.html" "/content/_edit-side-bar.md"))
([request default suffix template side-bar]
(let [params (keywordize-keys (:params request))
src-text (:src params)
@ -96,7 +96,7 @@
true
(layout/render template
(merge (util/standard-params request)
{:title (str "Edit " page)
{:title (str (:edit-title-prefix layout/config) " " page)
:page page
:side-bar (util/local-links (util/md->html side-bar))
:content (if exists? (io/slurp-resource (str "/content/" page suffix)) "")
@ -106,14 +106,14 @@
(defn edit-css-page
"Render a stylesheet in a text-area for editing.."
[request]
(edit-page request "stylesheet" ".css" "edit-css.html" "/content/_edit-side-bar.md"))
(edit-page request "stylesheet" ".css" "edit-css.html" "/content/_edit-side-bar.md"))
(defn wiki-page
"Render the markdown page specified in this `request`, if any. If none found, redirect to edit-page"
[request]
(let [params (keywordize-keys (:params request))
page (or (:page params) "Introduction")
page (or (:page params) (:default-page-title layout/config))
file-name (str "/content/" page ".md")
file-path (str (io/resource-path) file-name)
exists? (.exists (clojure.java.io/as-file file-path))]
@ -135,7 +135,7 @@
if any. If none, error?"
[request]
(let [params (keywordize-keys (:params request))
page (url-decode (or (:page params) "Introduction"))
page (url-decode (or (:page params) (:default-page-title layout/config)))
file-name (str page ".md")
repo-path (str (io/resource-path) "/content/")]
(layout/render "history.html"
@ -149,13 +149,13 @@
"Render a specific historical version of a page"
[request]
(let [params (keywordize-keys (:params request))
page (url-decode (or (:page params) "Introduction"))
page (url-decode (or (:page params) (:default-page-title layout/config)))
version (:version params)
file-name (str page ".md")
repo-path (str (io/resource-path) "/content/")]
(layout/render "wiki.html"
(merge (util/standard-params request)
{:title (str "Version " version " of " page)
{:title (str (:vers-col-hdr layout/config) " " version " of " page)
:page page
:content (util/local-links
(md/md-to-html-string
@ -167,13 +167,13 @@
"Render a diff between two versions of a page"
[request]
(let [params (keywordize-keys (:params request))
page (url-decode (or (:page params) "Introduction"))
page (url-decode (or (:page params) (:default-page-title layout/config)))
version (:version params)
file-name (str page ".md")
repo-path (str (io/resource-path) "/content/")]
(layout/render "wiki.html"
(merge (util/standard-params request)
{:title (str "Changes since version " version " of " page)
{:title (str (:diff-title-prefix layout/config)" " version " of " page)
:page page
:content (d2h/diff2html (hist/diff repo-path file-name version))}))))
@ -188,7 +188,7 @@
user (session/get :user)
redirect-to (or (:redirect-to params) "/wiki")]
(cond
(= action "Logout!")
(= action (:logout-label layout/config))
(do
(timbre/info (str "User " user " logging out"))
(session/remove! :user)
@ -200,7 +200,7 @@
true
(layout/render "auth.html"
(merge (util/standard-params request)
{:title (if user (str "Logout " user) "Log in")
{:title (if user (str (:logout-link layout/config) " " user) (:login-link layout/config))
:redirect-to ((:headers request) "referer")
:side-bar (util/local-links (util/md->html "/content/_side-bar.md"))
:header (util/local-links (util/md->html "/content/_header.md"))
@ -215,19 +215,20 @@
pass1 (:pass1 params)
pass2 (:pass2 params)
user (session/get :user)
message (cond
(nil? oldpass) nil
(and (auth/evaluate-password pass1 pass2) (auth/change-pass user oldpass pass2))
"Your password was changed"
(< (count pass1) 8) "You proposed password wasn't long enough: 8 characters required"
(not (= pass1 pass2)) "Your proposed passwords don't match"
true "Your password was not changed")] ;; but I don't know why...
changed? (and
(auth/evaluate-password pass1 pass2)
(auth/change-pass user oldpass pass2))]
(layout/render "passwd.html"
(merge (util/standard-params request)
{:title (str "Change passord for " user)
{:title (str (:chpass-title-prefix layout/config) " " user)
:side-bar (util/local-links (util/md->html "/content/_side-bar.md"))
:header (util/local-links (util/md->html "/content/_header.md"))
:message message}))))
:message (if changed? (:chpass-success layout/config))
:error (cond
changed? nil
(< (count pass1) 8) (:chpass-too-short layout/config)
(not (= pass1 pass2)) (:chpass-bad-match layout/config)
true (:chpass-fail layout/config))}))))
(defroutes wiki-routes