Added the raw basis for history browsing - doesn't work yet, but

doesn't affect the user interface either.
This commit is contained in:
simon 2015-01-09 17:41:12 +00:00
parent c749012459
commit 4444664bdf
3 changed files with 74 additions and 1 deletions

View file

@ -0,0 +1,32 @@
{% extends "templates/base.html" %}
{% block content %}
<div id="header" class="wiki">
<h1>{{title}}</h1>
{{header|safe}}
</div>
<div id="left-bar" class="wiki">
{{left-bar|safe}}
</div>
<div id="content" class="wiki">
<table>
<tr>
<th>Who</th><th>When</th><th>What</th><th>Which</th>
</tr>
{% for entry in history %}
<tr>
<td>
<a href="mailto:{{entry.email}}">{{entry.author}}</a>
</td>
<td>
{{entry.time}}
</td>
<td>
{{entry.message}}
</td>
<td>
{{entry.id}}
</td>
</tr>
</table>
</div>
{% endblock %}

24
src/smeagol/history.clj Normal file
View file

@ -0,0 +1,24 @@
(ns smeagol.history
(:require [clj-jgit.porcelain :as git]
[clj-jgit.querying :as q]))
(defn entry-contains
"If this `log-entry` contains a reference to this `file-path`, return the entry;
else nil."
[^String log-entry ^String file-path]
(cond
(not
(empty?
(filter
#(= (first %) file-path)
(: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`."
(let [repository (git/load-repo git-directory-path)]
(filter
#(entry-contains % file-path)
(map #(q/commit-info repository %)
(git/git-log repository)))))

View file

@ -25,7 +25,8 @@
[noir.session :as session]
[smeagol.authenticate :as auth]
[smeagol.layout :as layout]
[smeagol.util :as util]))
[smeagol.util :as util]
[smeagol.history :as hist]))
(defn local-links
@ -91,6 +92,22 @@
:user (session/get :user)})
true (response/redirect (str "/edit?content=" content)))))
(defn history-page
"Render the history for the markdown page specified in this `request`, if any. If none, error?"
[request]
(let [params (keywordize-keys (:params request))
content (or (:content params) "Introduction")
file-name (str "/content/" content ".md")
file-path (str (io/resource-path) file-name)
exists? (.exists (clojure.java.io/as-file file-path))]
(layout/render "history.html"
{:title content
:left-bar (local-links (util/md->html "/content/_left-bar.md"))
:header (local-links (util/md->html "/content/_header.md"))
:history (hist/find-history (io/resource-path) file-name)})))
(defn auth-page
"Render the auth page"
[request]