Skip to content

Commit

Permalink
Added vector syntax for routes to allow custom regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed May 3, 2010
1 parent b416521 commit cc5546c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/compojure/core.clj
Expand Up @@ -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."
Expand Down
9 changes: 8 additions & 1 deletion test/compojure/core_test.clj
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cc5546c

Please sign in to comment.