Permalink
Browse files

Added let-routes macro

  • Loading branch information...
1 parent 4ddcd50 commit 0d0d21c798bf9e6518ce72d03f400200cba83db3 @weavejester committed Dec 2, 2011
Showing with 15 additions and 0 deletions.
  1. +6 −0 src/compojure/core.clj
  2. +9 −0 test/compojure/test/core.clj
View
@@ -174,3 +174,9 @@
(fn [request#]
(let-request [~args request#]
(routing request# ~@routes))))))
+
+(defmacro let-routes
+ "Takes a vector of bindings and a body of routes. Equivalent to:
+ (let [...] (routes ...))"
+ [bindings & body]
+ `(let ~bindings (routes ~@body)))
@@ -111,3 +111,12 @@
"/foo/10/" "root"
"/foo/10/id" "10"
"/foo/1/x/2" "2"))))
+
+(deftest let-routes-test
+ (let [handler (let-routes [a "foo", b "bar"]
+ (GET "/foo" [] a)
+ (GET "/bar" [] b))]
+ (are [url body] (= (:body (handler (request :get url)))
+ body)
+ "/foo" "foo"
+ "/bar" "bar")))

0 comments on commit 0d0d21c

Please sign in to comment.