summaryrefslogtreecommitdiff
path: root/src/mulk/benki/main.clj
blob: 59aa512c62f058e838f86b3f1004f41ef12ba08a (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
(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"]))