summaryrefslogtreecommitdiff
path: root/src/mulk/benki/util.clj
blob: ea8ceae886493eac00e82e59580dec022279f0ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(ns mulk.benki.util
  (:refer-clojure)
  (:use [hiccup core page-helpers]
        [clojure.core.match.core :only [match]]
        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 {:xml? true}
   [:head
    [:title title]
    ;; jQuery
    [:script {:type "text/javascript"
              :src (resolve-uri "/3rdparty/jquery/jquery-1.7.min.js")}]
    ;; Aloha Editor
    [:link {:rel "stylesheet"
            :href (resolve-uri "/3rdparty/alohaeditor/aloha/css/aloha.css")}]
    [:script {:type "text/javascript"
              :src (resolve-uri "/3rdparty/alohaeditor/aloha/lib/aloha.js")
              :data-aloha-plugins "common/format,common/highlighteditables,common/list,common/link,common/undo,common/paste,common/block"}]
    ;; JavaScript
    [:script {:type "text/javascript"
              :src (resolve-uri "/js/wiki.js")}]]
   [:body [:h1 title]
    content]))


(defn fresolve [s & args]
  (resolve-uri (apply fmt nil s args)))

(defn link [& args]
  (match [(vec args)]
    [[:wiki title & xs]] (fresolve "/wiki/~a~@[~a~]" title (first xs))))