Skip to content

Commit

Permalink
add in retrieval-lifed flashes
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Granger <ibdknox@gmail.com>
  • Loading branch information
ibdknox committed Jul 23, 2011
1 parent 889b1ed commit aa50c48
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/noir/session.clj
Expand Up @@ -9,12 +9,6 @@
(declare *noir-session*)
(defonce mem (atom {}))

(defn noir-session [handler]
(fn [request]
(binding [*noir-session* (atom (:session request))]
(let [resp (handler request)]
(assoc resp :session @*noir-session*)))))

(defn put!
"Associates the key with the given value in the session"
[k v]
Expand All @@ -36,6 +30,27 @@
[k]
(swap! *noir-session* dissoc k))

(defn flash-put!
"Store a value with a lifetime of one retrieval (on the first flash-get,
it is removed). This is often used for passing small messages to pages
after a redirect."
[v]
(put! :_flash v))

(defn flash-get
"Retrieve the flash stored value. This will remove the flash from the
session."
[]
(let [flash (get :_flash)]
(remove! :_flash)
flash))

(defn noir-session [handler]
(fn [request]
(binding [*noir-session* (atom (:session request))]
(when-let [resp (handler request)]
(assoc resp :session @*noir-session*)))))

(defn wrap-noir-session [handler]
(-> handler
(noir-session)
Expand Down

0 comments on commit aa50c48

Please sign in to comment.