parent
da8fb77fc0
commit
a2bd971596
@ -0,0 +1,24 @@
|
|||||||
|
.devbar {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
font-family: monospace;
|
||||||
|
background-color: #ccc;
|
||||||
|
|
||||||
|
ol {
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
li {
|
||||||
|
padding: .5rem;
|
||||||
|
border: 1px solid black;
|
||||||
|
margin: .5rem;
|
||||||
|
|
||||||
|
pre {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
(ns wanijo.devmode
|
||||||
|
(:require [hiccup.core :as hcore]))
|
||||||
|
|
||||||
|
(def bar-entries (atom []))
|
||||||
|
|
||||||
|
(defn send-to-bar [msg]
|
||||||
|
(swap! bar-entries #(conj % msg)))
|
||||||
|
|
||||||
|
(defn devmode-on? [req]
|
||||||
|
(let [query-param (get-in req [:query-params "dev"])
|
||||||
|
cookie (get-in req [:cookies "devmode" :value])]
|
||||||
|
(or (= query-param "on")
|
||||||
|
(and (= cookie "1")
|
||||||
|
(not= query-param "off")))))
|
||||||
|
|
||||||
|
(defn devbar []
|
||||||
|
(hcore/html
|
||||||
|
[:section.devbar
|
||||||
|
[:ol
|
||||||
|
(for [entry @bar-entries]
|
||||||
|
[:li [:pre entry]])]]))
|
||||||
|
|
||||||
|
(defn append-devbar [resp]
|
||||||
|
(let [body (:body resp)
|
||||||
|
new-body (clojure.string/replace
|
||||||
|
body "</body>" (str (devbar) "</body>"))]
|
||||||
|
(assoc resp :body new-body)))
|
||||||
|
|
||||||
|
(defn wrap-devmode [handler]
|
||||||
|
(fn [req]
|
||||||
|
(let [on? (devmode-on? req)
|
||||||
|
query-param? (get-in req [:query-params "dev"])
|
||||||
|
new-req (assoc-in req [:session :devmode] on?)
|
||||||
|
resp (handler new-req)
|
||||||
|
new-resp (cond
|
||||||
|
on? (-> resp
|
||||||
|
append-devbar
|
||||||
|
(assoc-in [:cookies :devmode] 1))
|
||||||
|
(some? query-param?) (assoc-in
|
||||||
|
resp
|
||||||
|
[:cookies :devmode]
|
||||||
|
(if on? 1 0))
|
||||||
|
:else resp)]
|
||||||
|
(reset! bar-entries [])
|
||||||
|
new-resp)))
|
Loading…
Reference in new issue