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 |
Initial checkin.
-rw-r--r-- | project.clj | 39 | ||||
-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 |
5 files changed, 164 insertions, 0 deletions
diff --git a/project.clj b/project.clj new file mode 100644 index 0000000..d7e976c --- /dev/null +++ b/project.clj @@ -0,0 +1,39 @@ +(defproject benki "0.0.0" + :description "The Benkard Family Hub" + :dependencies [;;[org.clojure/clojure "1.4.0-master-SNAPSHOT"] + [org.clojure/clojure "1.3.0"] + ;;[org.clojure.contrib/standalone "1.3.0-alpha4"] + [org.clojure.contrib/standalone "1.3.0-SNAPSHOT"] + ;;[match "0.2.0-SNAPSHOT"] + ;; https://oss.sonatype.org/content/repositories/snapshots/org/clojure/ + [org.clojure/core.match "0.2.0-SNAPSHOT"] + [org.clojure/core.logic "0.6.6-SNAPSHOT"] + [org.clojure/core.unify "0.5.2-SNAPSHOT"] + [org.clojure/data.finger-tree "0.0.2-SNAPSHOT"] + [ring "1.0.0-RC1"] + [noir "1.2.0"] + [korma "0.2.0"] + ;;[clj-http "0.2.3"] + [hiccup "0.3.7"] + [cssgen "0.2.5-SNAPSHOT"] + + [clojureql "1.1.0-SNAPSHOT"] + + ;;[useful "0.7.4-alpha4"] + ;; [trafficdb "0.5.0-SNAPSHOT"] + ;; [org.clojars.zakwilson/plasma "0.3.0-SNAPSHOT"] + ;; ;;[plaza "0.0.5-SNAPSHOT"] + ;; [plaza-fork "0.0.5.2-SNAPSHOT"] + ;; [clj-oauth2 "0.0.1"] + ;; [org.clojars.zef/jopenid "1.05"] + ;; ;;[uk.co.magus.fourstore/4store-client "1.0"] + ] + :dev-dependencies [;;[swank-clojure "1.3.2"] + [swank-clojure "1.4.0-SNAPSHOT"] + ;;[ring-serve "0.1.1"] + [clj-stacktrace "0.2.3"]] + :repositories [["sonatype-snapshots" + ;;https confuses leiningen (but not cake) + "http://oss.sonatype.org/content/repositories/snapshots/"] + ["clojars" "http://clojars.org/repo/"]]) + 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)]))) |