Browse files

Added vector syntax for routes to allow custom regexes

  • Loading branch information...
1 parent b416521 commit cc5546c051589cdafa5ddc8cdf21c63fb2caa993 @weavejester committed May 3, 2010
Showing with 19 additions and 6 deletions.
  1. +11 −5 src/compojure/core.clj
  2. +8 −1 test/compojure/core_test.clj
View
16 src/compojure/core.clj
@@ -17,11 +17,17 @@
(defn- prepare-route
"Pre-compile the route."
[route]
- (if (string? route)
- (route-compile route)
- `(if (string? ~route)
- (route-compile ~route)
- ~route)))
+ (cond
+ (string? route)
+ (route-compile route)
+ (vector? route)
+ (route-compile
+ (first route)
+ (apply hash-map (rest route)))
+ :else
+ `(if (string? ~route)
+ (route-compile ~route)
+ ~route)))
(defn- assoc-route-params
"Associate route parameters with the request map."
View
9 test/compojure/core_test.clj
@@ -3,7 +3,8 @@
clojure.contrib.mock.test-adapter
clojure.contrib.with-ns
compojure.core
- compojure.response)
+ compojure.response
+ clout.core)
(:require [compojure.test-namespace :as testns]))
(deftest route-with-vector-arguments
@@ -31,6 +32,12 @@
route (PUT "/foo" [] resp)]
(is (= (route req) resp))))
+(deftest route-with-custom-regexes
+ (expect [route-compile
+ (has-args ["/foo/:id" {:id "[0-9]+"}]
+ (times 1))]
+ (eval `(GET ["/foo/:id" :id "[0-9]+"] []))))
+
(defn func1 [x] (inc x))
(deftest wrap-var-with-funcion

0 comments on commit cc5546c

Please sign in to comment.