Permalink
Browse files

add destructive get! and updated docs. Fix hiccup issue

Signed-off-by: Chris Granger <ibdknox@gmail.com>
  • Loading branch information...
1 parent 36507d1 commit 35341826c69ba68d046b53368239a94fa81a91cf @ibdknox committed Mar 20, 2012
Showing with 15 additions and 3 deletions.
  1. +1 −1 doc/index.html
  2. +3 −2 doc/noir.session.html
  3. +1 −0 history.md
  4. +1 −0 src/noir/content/getting_started.clj
  5. +9 −0 src/noir/session.clj
View
@@ -8,7 +8,7 @@
</pre><div class="index"><p>Public variables and functions:</p><ul><li><a href="noir.server.html#var-add-middleware"><span>add-middleware</span></a></li><li><a href="noir.server.html#var-gen-handler"><span>gen-handler</span></a></li><li><a href="noir.server.html#var-load-views"><span>load-views</span></a></li><li><a href="noir.server.html#var-load-views-ns"><span>load-views-ns</span></a></li><li><a href="noir.server.html#var-restart"><span>restart</span></a></li><li><a href="noir.server.html#var-start"><span>start</span></a></li><li><a href="noir.server.html#var-stop"><span>stop</span></a></li><li><a href="noir.server.html#var-wrap-route"><span>wrap-route</span></a></li></ul></div></div><div class="namespace"><h3><a href="noir.server.handler.html"><span>noir.server.handler</span></a></h3><pre class="doc">Handler generation functions used by noir.server and other ring handler libraries.
</pre><div class="index"><p>Public variables and functions:</p><ul><li><a href="noir.server.handler.html#var-add-custom-middleware"><span>add-custom-middleware</span></a></li><li><a href="noir.server.handler.html#var-base-handler"><span>base-handler</span></a></li><li><a href="noir.server.handler.html#var-wrap-noir-middleware"><span>wrap-noir-middleware</span></a></li><li><a href="noir.server.handler.html#var-wrap-spec-routes"><span>wrap-spec-routes</span></a></li></ul></div></div><div class="namespace"><h3><a href="noir.session.html"><span>noir.session</span></a></h3><pre class="doc">Stateful session handling functions. Uses a memory-store by
default, but can use a custom store by supplying a :session-store
-option to server/start.</pre><div class="index"><p>Public variables and functions:</p><ul><li><a href="noir.session.html#var-clear%21"><span>clear!</span></a></li><li><a href="noir.session.html#var-flash-get"><span>flash-get</span></a></li><li><a href="noir.session.html#var-flash-put%21"><span>flash-put!</span></a></li><li><a href="noir.session.html#var-get"><span>get</span></a></li><li><a href="noir.session.html#var-put%21"><span>put!</span></a></li><li><a href="noir.session.html#var-remove%21"><span>remove!</span></a></li><li><a href="noir.session.html#var-swap%21"><span>swap!</span></a></li></ul></div></div><div class="namespace"><h3><a href="noir.statuses.html"><span>noir.statuses</span></a></h3><pre class="doc">If no pages are defined that match a request, a status page is used based on the
+option to server/start.</pre><div class="index"><p>Public variables and functions:</p><ul><li><a href="noir.session.html#var-clear%21"><span>clear!</span></a></li><li><a href="noir.session.html#var-flash-get"><span>flash-get</span></a></li><li><a href="noir.session.html#var-flash-put%21"><span>flash-put!</span></a></li><li><a href="noir.session.html#var-get"><span>get</span></a></li><li><a href="noir.session.html#var-get%21"><span>get!</span></a></li><li><a href="noir.session.html#var-put%21"><span>put!</span></a></li><li><a href="noir.session.html#var-remove%21"><span>remove!</span></a></li><li><a href="noir.session.html#var-swap%21"><span>swap!</span></a></li></ul></div></div><div class="namespace"><h3><a href="noir.statuses.html"><span>noir.statuses</span></a></h3><pre class="doc">If no pages are defined that match a request, a status page is used based on the
the HTTP status code of the response. This contains the function necessary to get
or set these status pages.</pre><div class="index"><p>Public variables and functions:</p><ul><li><a href="noir.statuses.html#var-get-page"><span>get-page</span></a></li><li><a href="noir.statuses.html#var-set-page%21"><span>set-page!</span></a></li></ul></div></div><div class="namespace"><h3><a href="noir.util.crypt.html"><span>noir.util.crypt</span></a></h3><pre class="doc">Simple functions for hashing strings and comparing them. Typically used for storing passwords.
</pre><div class="index"><p>Public variables and functions:</p><ul><li><a href="noir.util.crypt.html#var-compare"><span>compare</span></a></li><li><a href="noir.util.crypt.html#var-encrypt"><span>encrypt</span></a></li></ul></div></div><div class="namespace"><h3><a href="noir.util.gae.html"><span>noir.util.gae</span></a></h3><pre class="doc">Functions to help run noir on Google App Engine.
View
@@ -1,11 +1,12 @@
<!DOCTYPE html>
-<html><head><link href="css/default.css" rel="stylesheet" type="text/css"><script src="js/jquery.min.js" type="text/javascript"></script><script src="js/page_effects.js" type="text/javascript"></script><title>noir.session documentation</title></head><body><div id="header"><h1><a href="index.html">Noir 1.3.0-beta1 API documentation</a></h1></div><div class="sidebar" id="namespaces"><h3>Namespaces</h3><ul><li><a href="noir.cookies.html"><span>noir.cookies</span></a></li><li><a href="noir.core.html"><span>noir.core</span></a></li><li><a href="noir.options.html"><span>noir.options</span></a></li><li><a href="noir.request.html"><span>noir.request</span></a></li><li><a href="noir.response.html"><span>noir.response</span></a></li><li><a href="noir.server.html"><span>noir.server</span></a></li><li><a href="noir.server.handler.html"><span>noir.server.handler</span></a></li><li class="current"><a href="noir.session.html"><span>noir.session</span></a></li><li><a href="noir.statuses.html"><span>noir.statuses</span></a></li><li><a href="noir.util.crypt.html"><span>noir.util.crypt</span></a></li><li><a href="noir.util.gae.html"><span>noir.util.gae</span></a></li><li><a href="noir.util.test.html"><span>noir.util.test</span></a></li><li><a href="noir.validation.html"><span>noir.validation</span></a></li></ul></div><div class="sidebar" id="vars"><h3>Public Vars</h3><ul><li><a href="noir.session.html#var-clear%21"><span>clear!</span></a></li><li><a href="noir.session.html#var-flash-get"><span>flash-get</span></a></li><li><a href="noir.session.html#var-flash-put%21"><span>flash-put!</span></a></li><li><a href="noir.session.html#var-get"><span>get</span></a></li><li><a href="noir.session.html#var-put%21"><span>put!</span></a></li><li><a href="noir.session.html#var-remove%21"><span>remove!</span></a></li><li><a href="noir.session.html#var-swap%21"><span>swap!</span></a></li></ul></div><div class="namespace-docs" id="content"><h2>noir.session documentation</h2><pre class="doc">Stateful session handling functions. Uses a memory-store by
+<html><head><link href="css/default.css" rel="stylesheet" type="text/css"><script src="js/jquery.min.js" type="text/javascript"></script><script src="js/page_effects.js" type="text/javascript"></script><title>noir.session documentation</title></head><body><div id="header"><h1><a href="index.html">Noir 1.3.0-beta1 API documentation</a></h1></div><div class="sidebar" id="namespaces"><h3>Namespaces</h3><ul><li><a href="noir.cookies.html"><span>noir.cookies</span></a></li><li><a href="noir.core.html"><span>noir.core</span></a></li><li><a href="noir.options.html"><span>noir.options</span></a></li><li><a href="noir.request.html"><span>noir.request</span></a></li><li><a href="noir.response.html"><span>noir.response</span></a></li><li><a href="noir.server.html"><span>noir.server</span></a></li><li><a href="noir.server.handler.html"><span>noir.server.handler</span></a></li><li class="current"><a href="noir.session.html"><span>noir.session</span></a></li><li><a href="noir.statuses.html"><span>noir.statuses</span></a></li><li><a href="noir.util.crypt.html"><span>noir.util.crypt</span></a></li><li><a href="noir.util.gae.html"><span>noir.util.gae</span></a></li><li><a href="noir.util.test.html"><span>noir.util.test</span></a></li><li><a href="noir.validation.html"><span>noir.validation</span></a></li></ul></div><div class="sidebar" id="vars"><h3>Public Vars</h3><ul><li><a href="noir.session.html#var-clear%21"><span>clear!</span></a></li><li><a href="noir.session.html#var-flash-get"><span>flash-get</span></a></li><li><a href="noir.session.html#var-flash-put%21"><span>flash-put!</span></a></li><li><a href="noir.session.html#var-get"><span>get</span></a></li><li><a href="noir.session.html#var-get%21"><span>get!</span></a></li><li><a href="noir.session.html#var-put%21"><span>put!</span></a></li><li><a href="noir.session.html#var-remove%21"><span>remove!</span></a></li><li><a href="noir.session.html#var-swap%21"><span>swap!</span></a></li></ul></div><div class="namespace-docs" id="content"><h2>noir.session documentation</h2><pre class="doc">Stateful session handling functions. Uses a memory-store by
default, but can use a custom store by supplying a :session-store
option to server/start.</pre><div class="public" id="var-clear%21"><h3>clear!</h3><div class="usage"><code>(clear!)</code></div><pre class="doc">Remove all data from the session and start over cleanly.
</pre></div><div class="public" id="var-flash-get"><h3>flash-get</h3><div class="usage"><code>(flash-get k)</code><code>(flash-get k not-found)</code></div><pre class="doc">Retrieve the flash stored value.
</pre></div><div class="public" id="var-flash-put%21"><h3>flash-put!</h3><div class="usage"><code>(flash-put! k v)</code></div><pre class="doc">Store a value that will persist for this request and the next.
</pre></div><div class="public" id="var-get"><h3>get</h3><div class="usage"><code>(get k)</code><code>(get k default)</code></div><pre class="doc">Get the key's value from the session, returns nil if it doesn't exist.
-</pre></div><div class="public" id="var-put%21"><h3>put!</h3><div class="usage"><code>(put! k v)</code></div><pre class="doc">Associates the key with the given value in the session
+</pre></div><div class="public" id="var-get%21"><h3>get!</h3><div class="usage"><code>(get! k)</code><code>(get! k default)</code></div><pre class="doc">Destructive get from the session. This returns the current value of the key
+and then removes it from the session.</pre></div><div class="public" id="var-put%21"><h3>put!</h3><div class="usage"><code>(put! k v)</code></div><pre class="doc">Associates the key with the given value in the session
</pre></div><div class="public" id="var-remove%21"><h3>remove!</h3><div class="usage"><code>(remove! k)</code></div><pre class="doc">Remove a key from the session
</pre></div><div class="public" id="var-swap%21"><h3>swap!</h3><div class="usage"><code>(swap! f &amp; args)</code></div><pre class="doc">Replace the current session's value with the result of executing f with
the current value and args.</pre></div></div></body></html>
View
@@ -4,6 +4,7 @@
* BREAKING CHANGE: clj-json has been replaced with cheshire.
* BREAKING CHANGE: noir.util.middleware was removed as wrap-utf8 is done by default in ring.
* BREAKING CHANGE: noir.util.s3 has been removed. See https://github.com/weavejester/clj-aws-s3 for a replacement.
+* Added noir.session/get! to have a destructive get like the old flashes
* Added noir.server/wrap-route to wrap middleware around specific routes
* Added noir.core/custom-handler* for adding dynamic route functions to the routing table.
* Added noir.util.test/send-request-map for sending full ring maps
@@ -3,6 +3,7 @@
noir.content.getting-started
(:use noir.core
noir.content.defaults
+ hiccup.element
hiccup.page))
(def header-links [{:url "http://www.webnoir.org/tutorials" :text "Tutorials"}
View
@@ -40,6 +40,15 @@
[k]
(clojure.core/swap! *noir-session* dissoc k))
+(defn get!
+ "Destructive get from the session. This returns the current value of the key
+ and then removes it from the session."
+ ([k] (get! k nil))
+ ([k default]
+ (let [cur (get k default)]
+ (remove! k)
+ cur)))
+
(defn noir-session [handler]
(fn [request]
(binding [*noir-session* (atom (:session request))]

0 comments on commit 3534182

Please sign in to comment.