From 5ff55cd6309d570a5297c0b26dfd623b1fadd604 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sat, 5 Nov 2011 18:45:04 +0100 Subject: Initial checkin. --- src/mulk/benki/auth.clj | 14 ++++++++++++++ src/mulk/benki/main.clj | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/mulk/benki/util.clj | 26 ++++++++++++++++++++++++++ src/mulk/benki/wiki.clj | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 src/mulk/benki/auth.clj create mode 100644 src/mulk/benki/main.clj create mode 100644 src/mulk/benki/util.clj create mode 100644 src/mulk/benki/wiki.clj (limited to 'src') 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" [] + "

Hello World

+ +

Hi!

") + +(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)]))) -- cgit v1.2.3