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:
simon 2015-01-12 21:57:21 +00:00
parent 80b1bc054e
commit 72ed9e5536
6 changed files with 72 additions and 72 deletions

View file

@ -19,7 +19,7 @@
<img id="nav-icon" src="{{servlet-context}}/img/threelines.png" alt="Menu"/> <img id="nav-icon" src="{{servlet-context}}/img/threelines.png" alt="Menu"/>
<ul id="nav-menu" class="nav"> <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}}/">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"> <li class="{{auth-selected}}"><a href="{{servlet-context}}/auth">
{% if user %} {% if user %}
Log out Log out

View file

@ -2,7 +2,7 @@
{% block content %} {% block content %}
<div id="content" class="edit"> <div id="content" class="edit">
<form action="{{servlet-context}}/edit" method="POST"> <form action="{{servlet-context}}/edit" method="POST">
<input type="hidden" name="content" value="{{title}}"/> <input type="hidden" name="page" value="{{page}}"/>
<textarea name="src" id="src" rows="25" cols="80">{{content}}</textarea> <textarea name="src" id="src" rows="25" cols="80">{{content}}</textarea>
<p class="widget"> <p class="widget">
<label for="summary">What have you changed?</label> <label for="summary">What have you changed?</label>

View file

@ -25,14 +25,14 @@
[username password] [username password]
(let [path (str (io/resource-path) "../passwd") (let [path (str (io/resource-path) "../passwd")
users (read-string (slurp path)) users (read-string (slurp path))
user (keyword username)] user ((keyword username) users)]
(timbre/info (str "Authenticating " username " against " path)) (timbre/info (str "Authenticating " username " against " path))
(.equals (:password (user users)) password))) (and user (.equals (:password user) password))))
(defn get-email (defn get-email
"Return the email address associated with this `username`." "Return the email address associated with this `username`."
[username] [username]
(let [path (str (io/resource-path) "passwd") (let [path (str (io/resource-path) "../passwd")
users (read-string (slurp path)) users (read-string (slurp path))
user (keyword username)] user ((keyword username) users)]
(:email (user users)))) (if user (:email user))))

View file

@ -90,7 +90,7 @@
:middleware (load-middleware) :middleware (load-middleware)
:ring-defaults (mk-defaults false) :ring-defaults (mk-defaults false)
;; add access rules here ;; add access rules here
:access-rules [{:redirect "auth" :access-rules [{:redirect "/auth"
:rule user-access}] :rule user-access}]
;; serialize/deserialize the following data formats ;; serialize/deserialize the following data formats
;; available formats: ;; available formats:

View file

@ -36,26 +36,26 @@
[html-src] [html-src]
(clojure.string/replace html-src #"\[\[[^\[\]]*\]\]" (clojure.string/replace html-src #"\[\[[^\[\]]*\]\]"
#(let [text (clojure.string/replace %1 #"[\[\]]" "")] #(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 (defn process-source
"Process `source-text` and save it to the specified `file-path`, committing it "Process `source-text` and save it to the specified `file-path`, committing it
to Git and finally redirecting to wiki-page." to Git and finally redirecting to wiki-page."
[params] [params]
(let [source-text (:src params) (let [source-text (:src params)
content (:content params) page (:page params)
file-name (str content ".md") file-name (str page ".md")
file-path (str (io/resource-path) "/content/" file-name) file-path (str (io/resource-path) "/content/" file-name)
exists? (.exists (clojure.java.io/as-file file-path)) exists? (.exists (clojure.java.io/as-file file-path))
git-repo (git/load-repo (str (io/resource-path) "/content/.git")) git-repo (git/load-repo (str (io/resource-path) "/content/.git"))
user (session/get :user) user (session/get :user)
email (auth/get-email user) email (auth/get-email user)
summary (str user ": " (or (:summary params) "no summary"))] 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) (spit file-path source-text)
(if (not exists?) (git/git-add git-repo file-name)) (if (not exists?) (git/git-add git-repo file-name))
(git/git-commit git-repo summary {:name user :email email}) (git/git-commit git-repo summary {:name user :email email})
(response/redirect (str "/wiki?" content)) (response/redirect (str "/wiki?" page))
)) ))
(defn edit-page (defn edit-page
@ -64,17 +64,17 @@
[request] [request]
(let [params (keywordize-keys (:params request)) (let [params (keywordize-keys (:params request))
src-text (:src params) src-text (:src params)
content (:content params) page (or (:page params) "Introduction")
file-name (str "/content/" content ".md") file-path (str (io/resource-path) "content/" page ".md")
file-path (str (io/resource-path) file-name)
exists? (.exists (clojure.java.io/as-file file-path))] exists? (.exists (clojure.java.io/as-file file-path))]
(cond src-text (process-source params) (cond src-text (process-source params)
true true
(layout/render "edit.html" (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")) :left-bar (local-links (util/md->html "/content/_edit-left-bar.md"))
:header (local-links (util/md->html "/content/_header.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) :user (session/get :user)
:exists exists?})))) :exists exists?}))))
@ -82,19 +82,19 @@
"Render the markdown page specified in this `request`, if any. If none found, redirect to edit-page" "Render the markdown page specified in this `request`, if any. If none found, redirect to edit-page"
[request] [request]
(let [params (keywordize-keys (:params request)) (let [params (keywordize-keys (:params request))
content (or (:content params) "Introduction") page (or (:content params) (:page params) "Introduction")
file-name (str "/content/" content ".md") file-name (str "/content/" page ".md")
file-path (str (io/resource-path) file-name) file-path (str (io/resource-path) file-name)
exists? (.exists (clojure.java.io/as-file file-path))] exists? (.exists (clojure.java.io/as-file file-path))]
(cond exists? (cond exists?
(layout/render "wiki.html" (layout/render "wiki.html"
{:title content {:title page
:page content :page page
:left-bar (local-links (util/md->html "/content/_left-bar.md")) :left-bar (local-links (util/md->html "/content/_left-bar.md"))
:header (local-links (util/md->html "/content/_header.md")) :header (local-links (util/md->html "/content/_header.md"))
:content (local-links (util/md->html file-name)) :content (local-links (util/md->html file-name))
:user (session/get :user)}) :user (session/get :user)})
true (response/redirect (str "/edit?content=" content))))) true (response/redirect (str "/edit?page=" page)))))
(defn history-page (defn history-page
"Render the history for the markdown page specified in this `request`, "Render the history for the markdown page specified in this `request`,