From 7b72dc66663fb98c9820ad6a67c7143adea143a8 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sat, 28 Feb 2009 21:55:21 +0100 Subject: Add macro with-web-vars. --- cljssss-g.clj | 33 +++++++++++++++++++++++++-------- 1 file 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 -- cgit v1.2.3