Permalink
Browse files

resilience in exception page and cookies fix

Signed-off-by: Chris Granger <chris@readyforzero.com>
  • Loading branch information...
Chris Granger
Chris Granger committed Aug 10, 2011
2 parents 3364cb5 + d9b7306 commit 584a0328ea0682e92d9668cacd9fe71e83175692
Showing with 22 additions and 22 deletions.
  1. +2 −2 project.clj
  2. +2 −2 src/noir/cookies.clj
  3. +8 −8 src/noir/core.clj
  4. +1 −1 src/noir/options.clj
  5. +4 −4 src/noir/server.clj
  6. +1 −1 src/noir/session.clj
  7. +3 −3 src/noir/statuses.clj
  8. +1 −1 src/noir/validation.clj
View
@@ -1,14 +1,14 @@
(defproject noir "1.1.1-SNAPSHOT"
:description "Noir - a clojure web framework"
:dependencies [[org.clojure/clojure "1.2.1"]
- [compojure "0.6.4"]
+ [compojure "0.6.5"]
[org.clojure/tools.namespace "0.1.0"]
[clj-json "0.3.2"]
[ring "0.3.11"]
[cssgen "0.2.4"]
[hiccup "0.3.6"]
[clj-stacktrace "0.2.3"]
- [ring-reload-modified "0.1.0"]
+ [org.ibdknox.clojars/ring-reload-modified "0.1.1"]
[net.java.dev.jets3t/jets3t "0.8.0"]
[org.mindrot/jbcrypt "0.3m"]]
:dev-dependencies [[marginalia "0.6.0"]
View
@@ -4,8 +4,8 @@
(:require [noir.util.crypt :as crypt])
(:use ring.middleware.cookies))
-(def *cur-cookies* nil)
-(def *new-cookies* nil)
+(declare ^:dynamic *cur-cookies*)
+(declare ^:dynamic *new-cookies*)
(defn put!
"Add a new cookie whose name is k and has the value v. If v is a string
View
@@ -5,10 +5,10 @@
(:require [clojure.string :as string]
[compojure.route :as c-route]))
-(defonce *noir-routes* (atom {}))
-(defonce *route-funcs* (atom {}))
-(defonce *pre-routes* (atom (sorted-map)))
-(defonce *spec-routes* [(c-route/resources "/")
+(defonce noir-routes (atom {}))
+(defonce route-funcs (atom {}))
+(defonce pre-routes (atom (sorted-map)))
+(defonce spec-routes [(c-route/resources "/")
(ANY "*" [] {:status 404 :body nil})])
(defn- keyword->symbol [namesp kw]
@@ -39,8 +39,8 @@
`(do
(defn ~fn-name# [~destruct]
~@body)
- (swap! *route-funcs* assoc ~(keyword fn-name#) ~fn-name#)
- (swap! *noir-routes* assoc ~(keyword fn-name#) (~action# ~url# {params# :params} (~fn-name# params#))))))
+ (swap! route-funcs assoc ~(keyword fn-name#) ~fn-name#)
+ (swap! noir-routes assoc ~(keyword fn-name#) (~action# ~url# {params# :params} (~fn-name# params#))))))
(defmacro defpartial
"Create a function that returns html using hiccup. The function is callable with the given name."
@@ -55,7 +55,7 @@
e.g. [:post '/vals']"
[route & [params]]
(let [{fn-name :route-fn} (parse-route route)
- func (get @*route-funcs* (keyword fn-name))]
+ func (get @route-funcs (keyword fn-name))]
(func params)))
(defmacro pre-route
@@ -68,4 +68,4 @@
(pre-route '/admin/*' {} (when-not (is-admin?) (redirect '/login')))"
[route destruct & body]
(let [{action# :action url# :url} (parse-route route)]
- `(swap! *pre-routes* assoc ~url# (~action# ~url# {:as request#} ((fn [~destruct] ~@body) request#)))))
+ `(swap! pre-routes assoc ~url# (~action# ~url# {:as request#} ((fn [~destruct] ~@body) request#)))))
View
@@ -2,7 +2,7 @@
"Allows access to Noir's server options"
(:refer-clojure :exclude [get]))
-(declare *options*)
+(declare ^:dynamic *options*)
(def default-opts {:ns (gensym)
:mode :dev})
View
@@ -18,7 +18,7 @@
[noir.session :as session]
[noir.validation :as validation]))
-(defonce *middleware* (atom #{}))
+(defonce middleware (atom #{}))
(defn- wrap-route-updating [handler]
(if (options/dev-mode?)
@@ -27,15 +27,15 @@
(defn- wrap-custom-middleware [handler]
(loop [cur handler
- mware (seq @*middleware*)]
+ mware (seq @middleware)]
(if-not mware
cur
(let [[func args] (first mware)
neue (apply func cur args)]
(recur neue (next mware))))))
(defn- pack-routes []
- (apply routes (concat (vals @noir/*pre-routes*) (vals @noir/*noir-routes*) noir/*spec-routes*)))
+ (apply routes (concat (vals @noir/pre-routes) (vals @noir/noir-routes) noir/spec-routes)))
(defn- init-routes [opts]
(binding [options/*options* (options/compile-options opts)]
@@ -85,7 +85,7 @@
function, which will be passed the handler. Any extra args to be applied should be
supplied along with the function."
[func & args]
- (swap! *middleware* conj [func args]))
+ (swap! middleware conj [func args]))
(defn start
"Create a noir server bound to the specified port with a map of options and return it.
View
@@ -7,7 +7,7 @@
ring.middleware.session.memory)
(:require [noir.options :as options]))
-(declare *noir-session*)
+(declare ^:dynamic *noir-session*)
(defonce mem (atom {}))
(defn put!
View
@@ -4,19 +4,19 @@
or set these status pages."
(:require [noir.content.defaults :as defaults]))
-(def *status-pages* (atom {404 (defaults/not-found)
+(def status-pages (atom {404 (defaults/not-found)
500 (defaults/internal-error)}))
(defn get-page
"Gets the content to display for the given status code"
[code]
- (get @*status-pages* code))
+ (get @status-pages code))
(defn set-page!
"Sets the content to be displayed if there is a response with the given status
code. This is used for custom 404 pages, for example."
[code content]
- (swap! *status-pages* assoc code content))
+ (swap! status-pages assoc code content))
(defn wrap-status-pages [handler]
(fn [request]
View
@@ -39,7 +39,7 @@
[v]
(re-matches #"(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b" v))
-(declare *errors*)
+(declare ^:dynamic *errors*)
;;errors and rules
(defn get-errors

0 comments on commit 584a032

Please sign in to comment.