diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2011-11-05 18:45:04 +0100 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2011-11-05 18:45:04 +0100 |
commit | 5ff55cd6309d570a5297c0b26dfd623b1fadd604 (patch) | |
tree | c37e9faae3dde2a56a96cd473abbb5882cbeea4f /src |
Initial checkin.
Diffstat (limited to 'src')
-rw-r--r-- | src/mulk/benki/auth.clj | 14 | ||||
-rw-r--r-- | src/mulk/benki/main.clj | 46 | ||||
-rw-r--r-- | src/mulk/benki/util.clj | 26 | ||||
-rw-r--r-- | src/mulk/benki/wiki.clj | 39 |
4 files changed, 125 insertions, 0 deletions
diff --git a/src/mulk/benki/auth.clj b/src/mulk/benki/auth.clj new file mode 100644 index 0000000..36465f1 --- /dev/null +++ b/src/mulk/benki/auth.clj @@ -0,0 +1,14 @@ +(ns mulk.benki.auth + (:refer-clojure) + (:use [clojure core repl pprint] + [clojure.contrib error-kit] + [hiccup core page-helpers] + [mulk.benki util] + [clojure.core.match.core + :only [match]] + noir.core)) + + +(defpage "/login" [] + (layout "Benki Login" + [])) diff --git a/src/mulk/benki/main.clj b/src/mulk/benki/main.clj new file mode 100644 index 0000000..59aa512 --- /dev/null +++ b/src/mulk/benki/main.clj @@ -0,0 +1,46 @@ +(ns mulk.benki.main + (:refer-clojure) + (:use [clojure core repl pprint] + noir.core + [hiccup core page-helpers] + [mulk.benki util]) + (:require noir.server)) + + +(defonce server (noir.server/start 3000)) + +(defn wrap-utf-8 [handler] + (fn [request] + (let [response (handler request) + ctype (get-in response [:headers "Content-Type"]) + utf8ctype (str ctype "; charset=utf-8")] + (if (and ctype + (re-matches #"^(text/html|text/plain|application/xhtml+xml|text/xml)$" ctype)) + (assoc-in response [:headers "Content-Type"] utf8ctype) + response)))) + +(do-once ::init + (noir.server/add-middleware #'wrap-utf-8) + ;;(set! *base-url* nil) + ) + + +(defpage "/welcome" [] + "<h1>Hello World</h1> + + <p>Hi!</p>") + +(defpage "/hello" {name :name} + (layout + [:h1 "Greeting"] + [:p (fmt nil "Hi~@[ ~A~]!" name)])) + +(defpage "/journal/:id" {id :id} + (layout + [:h1 "Journal Entry #" id] + [:p "Bla bla bla."])) + +(defpage "/journal" {} + (layout + [:h1 "Journal"])) + diff --git a/src/mulk/benki/util.clj b/src/mulk/benki/util.clj new file mode 100644 index 0000000..5b2e484 --- /dev/null +++ b/src/mulk/benki/util.clj @@ -0,0 +1,26 @@ +(ns mulk.benki.util + (:refer-clojure) + (:use [hiccup core page-helpers] + noir.core)) + + +(def fmt clojure.pprint/cl-format) + + +(defonce #^:private finished-initializations (atom #{})) + +(defmacro do-once [key & body] + `(while (not (@(deref #'finished-initializations) key)) + (let [fininit-copy# @(deref #'finished-initializations)] + (when (compare-and-set! (deref #'finished-initializations) + fininit-copy# + (conj fininit-copy# key)) + (do ~@body))))) + + +;; defpartial is just defn + html. +(defpartial layout [title & content] + (html5 + [:head [:title title]] + [:body [:h1 title] + content])) diff --git a/src/mulk/benki/wiki.clj b/src/mulk/benki/wiki.clj new file mode 100644 index 0000000..094bf02 --- /dev/null +++ b/src/mulk/benki/wiki.clj @@ -0,0 +1,39 @@ +(ns mulk.benki.wiki + (:refer-clojure :exclude [distinct conj! case compile drop take sort disj! + resultset-seq]) + (:use [clojure repl pprint] + [clojure.contrib error-kit] + [hiccup core page-helpers] + [mulk.benki util] + [clojure.core.match.core + :only [match]] + [ring.util.response + :only [redirect]] + clojureql.core + [clojure.java.jdbc + :only [transaction]] + noir.core) + (:require mulk.benki.main)) + + +(def page_revisions (table :page_revisions)) +(def pages (table :pages)) + + +(defpage "/wiki" [] + (redirect (resolve-uri "/wiki/Home"))) + +(defpage "/wiki/:id" {id :id, revision-id :revision} + (let [page (-> pages + (select (if (number? id) + (where (= :id id)) + (where (= :title id))))) + revisions (-> page_revisions + (join page (where (= :pages.id :page_revisions.page))) + ;;(project [:page_revisions.*]) + (project page_revisions)) + revision (if revision-id + (select revisions (where (= :id revision-id))) + (first (sort revisions [:published#desc])))] + (layout (fmt nil "~A — Benki~@[/~A~] " id revision-id) + [:pre (prn-str revision)]))) |