mirror of
https://github.com/journeyman-cc/smeagol.git
synced 2026-04-12 18:05:06 +00:00
After being so pleased with myself last night, I find that commit was full
of sloppy bugs. Many of them fixed in this one.
This commit is contained in:
parent
80b1bc054e
commit
72ed9e5536
6 changed files with 72 additions and 72 deletions
|
|
@ -1,26 +1,26 @@
|
|||
{% extends "templates/base.html" %}
|
||||
{% block content %}
|
||||
<div id="content" class="auth">
|
||||
<form action="{{servlet-context}}/auth" method="POST">
|
||||
{% if user %}
|
||||
<p class="widget">
|
||||
<label for="submit">To finish editing</label>
|
||||
<input name="action" id="action" type="submit" class="action-dangerous" value="Logout!"/>
|
||||
</p>
|
||||
{% else %}
|
||||
<p class="widget">
|
||||
<label for="username">Your username</label>
|
||||
<input name="username" id="username" type="text"/>
|
||||
</p>
|
||||
<p class="widget">
|
||||
<label for="password">Your password</label>
|
||||
<input name="password" id="password" type="password"/>
|
||||
</p>
|
||||
<p class="widget">
|
||||
<label for="submit">To edit this wiki</label>
|
||||
<input name="action" id="action" type="submit" class="action" value="Login!"/>
|
||||
</p>
|
||||
{% endif %}
|
||||
</form>
|
||||
</div>
|
||||
<div id="content" class="auth">
|
||||
<form action="{{servlet-context}}/auth" method="POST">
|
||||
{% if user %}
|
||||
<p class="widget">
|
||||
<label for="submit">To finish editing</label>
|
||||
<input name="action" id="action" type="submit" class="action-dangerous" value="Logout!"/>
|
||||
</p>
|
||||
{% else %}
|
||||
<p class="widget">
|
||||
<label for="username">Your username</label>
|
||||
<input name="username" id="username" type="text"/>
|
||||
</p>
|
||||
<p class="widget">
|
||||
<label for="password">Your password</label>
|
||||
<input name="password" id="password" type="password"/>
|
||||
</p>
|
||||
<p class="widget">
|
||||
<label for="submit">To edit this wiki</label>
|
||||
<input name="action" id="action" type="submit" class="action" value="Login!"/>
|
||||
</p>
|
||||
{% endif %}
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
<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="{{edit-selected}}"><a href="{{servlet-context}}/edit?content={{title}}">Edit this page</a></li>
|
||||
<li class="{{edit-selected}}"><a href="{{servlet-context}}/edit?page={{title}}">Edit this page</a></li>
|
||||
<li class="{{auth-selected}}"><a href="{{servlet-context}}/auth">
|
||||
{% if user %}
|
||||
Log out
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
{% extends "templates/base.html" %}
|
||||
{% block content %}
|
||||
<div id="content" class="edit">
|
||||
<form action="{{servlet-context}}/edit" method="POST">
|
||||
<input type="hidden" name="content" value="{{title}}"/>
|
||||
<textarea name="src" id="src" rows="25" cols="80">{{content}}</textarea>
|
||||
<p class="widget">
|
||||
<label for="summary">What have you changed?</label>
|
||||
<input name="summary" id="summary" type="text"
|
||||
value="{%if exists%}{%else%}New file {{title}}{%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!"/>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
<div id="content" class="edit">
|
||||
<form action="{{servlet-context}}/edit" method="POST">
|
||||
<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>
|
||||
<input name="summary" id="summary" type="text"
|
||||
value="{%if exists%}{%else%}New file {{title}}{%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!"/>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -25,14 +25,14 @@
|
|||
[username password]
|
||||
(let [path (str (io/resource-path) "../passwd")
|
||||
users (read-string (slurp path))
|
||||
user (keyword username)]
|
||||
user ((keyword username) users)]
|
||||
(timbre/info (str "Authenticating " username " against " path))
|
||||
(.equals (:password (user users)) password)))
|
||||
(and user (.equals (:password user) password))))
|
||||
|
||||
(defn get-email
|
||||
"Return the email address associated with this `username`."
|
||||
[username]
|
||||
(let [path (str (io/resource-path) "passwd")
|
||||
(let [path (str (io/resource-path) "../passwd")
|
||||
users (read-string (slurp path))
|
||||
user (keyword username)]
|
||||
(:email (user users))))
|
||||
user ((keyword username) users)]
|
||||
(if user (:email user))))
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@
|
|||
:middleware (load-middleware)
|
||||
:ring-defaults (mk-defaults false)
|
||||
;; add access rules here
|
||||
:access-rules [{:redirect "auth"
|
||||
:access-rules [{:redirect "/auth"
|
||||
:rule user-access}]
|
||||
;; serialize/deserialize the following data formats
|
||||
;; available formats:
|
||||
|
|
|
|||
|
|
@ -36,26 +36,26 @@
|
|||
[html-src]
|
||||
(clojure.string/replace html-src #"\[\[[^\[\]]*\]\]"
|
||||
#(let [text (clojure.string/replace %1 #"[\[\]]" "")]
|
||||
(str "<a href='wiki?content=" text "'>" text "</a>"))))
|
||||
(str "<a href='wiki?page=" text "'>" text "</a>"))))
|
||||
|
||||
(defn process-source
|
||||
"Process `source-text` and save it to the specified `file-path`, committing it
|
||||
to Git and finally redirecting to wiki-page."
|
||||
[params]
|
||||
(let [source-text (:src params)
|
||||
content (:content params)
|
||||
file-name (str content ".md")
|
||||
page (:page params)
|
||||
file-name (str page ".md")
|
||||
file-path (str (io/resource-path) "/content/" file-name)
|
||||
exists? (.exists (clojure.java.io/as-file file-path))
|
||||
git-repo (git/load-repo (str (io/resource-path) "/content/.git"))
|
||||
user (session/get :user)
|
||||
email (auth/get-email user)
|
||||
summary (str user ": " (or (:summary params) "no summary"))]
|
||||
(timbre/info (str "Saving " user "'s changes (" summary ") to " file-name))
|
||||
(timbre/info (str "Saving " user "'s changes (" summary ") to " page))
|
||||
(spit file-path source-text)
|
||||
(if (not exists?) (git/git-add git-repo file-name))
|
||||
(git/git-commit git-repo summary {:name user :email email})
|
||||
(response/redirect (str "/wiki?" content))
|
||||
(response/redirect (str "/wiki?" page))
|
||||
))
|
||||
|
||||
(defn edit-page
|
||||
|
|
@ -64,17 +64,17 @@
|
|||
[request]
|
||||
(let [params (keywordize-keys (:params request))
|
||||
src-text (:src params)
|
||||
content (:content params)
|
||||
file-name (str "/content/" content ".md")
|
||||
file-path (str (io/resource-path) file-name)
|
||||
page (or (:page params) "Introduction")
|
||||
file-path (str (io/resource-path) "content/" page ".md")
|
||||
exists? (.exists (clojure.java.io/as-file file-path))]
|
||||
(cond src-text (process-source params)
|
||||
true
|
||||
(layout/render "edit.html"
|
||||
{:title (str "Edit " content)
|
||||
{:title (str "Edit " page)
|
||||
:page page
|
||||
:left-bar (local-links (util/md->html "/content/_edit-left-bar.md"))
|
||||
:header (local-links (util/md->html "/content/_header.md"))
|
||||
:content (if exists? (io/slurp-resource file-name) "")
|
||||
:content (if exists? (io/slurp-resource (str "/content/" page ".md")) "")
|
||||
:user (session/get :user)
|
||||
:exists exists?}))))
|
||||
|
||||
|
|
@ -82,19 +82,19 @@
|
|||
"Render the markdown page specified in this `request`, if any. If none found, redirect to edit-page"
|
||||
[request]
|
||||
(let [params (keywordize-keys (:params request))
|
||||
content (or (:content params) "Introduction")
|
||||
file-name (str "/content/" content ".md")
|
||||
page (or (:content params) (:page params) "Introduction")
|
||||
file-name (str "/content/" page ".md")
|
||||
file-path (str (io/resource-path) file-name)
|
||||
exists? (.exists (clojure.java.io/as-file file-path))]
|
||||
(cond exists?
|
||||
(layout/render "wiki.html"
|
||||
{:title content
|
||||
:page content
|
||||
{:title page
|
||||
:page page
|
||||
:left-bar (local-links (util/md->html "/content/_left-bar.md"))
|
||||
:header (local-links (util/md->html "/content/_header.md"))
|
||||
:content (local-links (util/md->html file-name))
|
||||
:user (session/get :user)})
|
||||
true (response/redirect (str "/edit?content=" content)))))
|
||||
true (response/redirect (str "/edit?page=" page)))))
|
||||
|
||||
(defn history-page
|
||||
"Render the history for the markdown page specified in this `request`,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue