From bc0dd7508125272926fc227fef0e0e0dfe77f1de Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Sun, 11 Jan 2015 15:02:08 +0000 Subject: [PATCH] Apart from writing a diff2html transform and maybe adding a user-admin page, I'd say this is feature complete. Good enough for me, anyway! --- resources/templates/history.html | 4 ++-- src/smeagol/history.clj | 3 ++- src/smeagol/routes/wiki.clj | 22 ++++++++++++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/resources/templates/history.html b/resources/templates/history.html index c73f5b8..1b520e3 100644 --- a/resources/templates/history.html +++ b/resources/templates/history.html @@ -12,7 +12,7 @@ {% for entry in history %} - + S {{entry.time}} @@ -22,7 +22,7 @@ Show version - What's changed? + What's changed? {% endfor %} diff --git a/src/smeagol/history.clj b/src/smeagol/history.clj index cf52fc7..e9250f6 100644 --- a/src/smeagol/history.clj +++ b/src/smeagol/history.clj @@ -72,7 +72,8 @@ Based on JGit Cookbook ShowFileDiff." ([^String git-directory-path ^String file-path ^String version] - "TODO: Doesn't work yet") + (diff git-directory-path file-path version + (:id (first (find-history git-directory-path file-path))))) ([^String git-directory-path ^String file-path ^String older ^String newer] (let [git-r (git/load-repo git-directory-path) old-parse (prepare-tree-parser git-r older) diff --git a/src/smeagol/routes/wiki.clj b/src/smeagol/routes/wiki.clj index 4ba4ae8..d286d45 100644 --- a/src/smeagol/routes/wiki.clj +++ b/src/smeagol/routes/wiki.clj @@ -26,11 +26,11 @@ [noir.session :as session] [taoensso.timbre :as timbre] [smeagol.authenticate :as auth] + [smeagol.diff2html :as d2h] [smeagol.layout :as layout] [smeagol.util :as util] [smeagol.history :as hist])) - (defn local-links "Rewrite text in `html-src` surrounded by double square brackets as a local link into this wiki." [html-src] @@ -131,7 +131,24 @@ (hist/fetch-version repo-path file-name version))) :user (session/get :user)}))) - + +(defn diff-page + "Render a diff between two versions of a page" + [request] + (let [params (keywordize-keys (:params request)) + page (or (:page params) "Introduction") + version (:version params) + file-name (str page ".md") + repo-path (str (io/resource-path) "/content/")] + (layout/render "wiki.html" + {:title (str "Changes since version " version " of " page) + :page page + :left-bar (local-links + (util/md->html "/content/_left-bar.md")) + :header (local-links + (util/md->html "/content/_header.md")) + :content (d2h/diff2html (hist/diff repo-path file-name version)) + :user (session/get :user)}))) (defn auth-page "Render the auth page" @@ -168,6 +185,7 @@ (POST "/edit" request (route/restricted (edit-page request))) (GET "/history" request (history-page request)) (GET "/version" request (version-page request)) + (GET "/changes" request (diff-page request)) (GET "/auth" request (auth-page request)) (POST "/auth" request (auth-page request)) (GET "/about" [] (about-page)))