aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2009-02-28 21:55:21 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2009-02-28 21:55:21 +0100
commit7b72dc66663fb98c9820ad6a67c7143adea143a8 (patch)
tree466ca5d0a052263e0b6af16525f389d751d85997
parentba49528e4ba3952da10b3ebd3222761c04571394 (diff)
Add macro with-web-vars.
-rw-r--r--cljssss-g.clj33
1 files changed, 25 insertions, 8 deletions
diff --git a/cljssss-g.clj b/cljssss-g.clj
index 1fc7bec..e52f487 100644
--- a/cljssss-g.clj
+++ b/cljssss-g.clj
@@ -26,6 +26,20 @@
(sql/transaction
~@body)))
+(def web-vars '(context cookies headers method params request response
+ route session))
+
+(defmacro define-web-vars []
+ `(do
+ ~@(into () (map (fn [varname] `(def ~varname)) web-vars))))
+
+(define-web-vars)
+
+(defmacro with-web-vars [& body]
+ `(binding ~(into [] (mapcat (fn [varname] `[~varname ~varname])
+ web-vars))
+ ~@body))
+
(defn opml-string [user]
(with-dbt
(sql/with-query-results
@@ -92,14 +106,17 @@
"link" link})
results)})))))))
-(defmacro with-session [& body]
- `(if (not (~'session :id))
- (if (= (~'params :valuesofbetawillgiverisetodom) "true")
- (.toString (doto (.getInstanceOf templates "login")
- (.setAttributes {"logintext" "Login failed"})))
- (.toString (doto (.getInstanceOf templates "login")
- (.setAttributes {"logintext" "Login"}))))
- (do ~@body)))
+(defmacro with-session
+ "Rebind Compojure's magic lexical variables as vars."
+ [& body]
+ `(with-web-vars
+ (if (not (session :id))
+ (if (= (params :valuesofbetawillgiverisetodom) "true")
+ (.toString (doto (.getInstanceOf templates "login")
+ (.setAttributes {"logintext" "Login failed"})))
+ (.toString (doto (.getInstanceOf templates "login")
+ (.setAttributes {"logintext" "Login"}))))
+ (do ~@body))))
(defservlet cljssss-g