From edbe046445defc78420afeecd141820e1860c50e Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Mon, 9 Sep 2013 02:08:28 +1000 Subject: Some utilities for testing (when used in other libraries) --- src/reverse_routing/core.clj | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/reverse_routing/core.clj') diff --git a/src/reverse_routing/core.clj b/src/reverse_routing/core.clj index 1977b2a..edc1f57 100644 --- a/src/reverse_routing/core.clj +++ b/src/reverse_routing/core.clj @@ -45,8 +45,9 @@ lookup-fn `(fn [[route-name# args#]] (if (>= (count args#) ~keylen) (let [~args args# - r# (#'lookup-route [route-name# (vec (drop ~keylen args#))] - ~@routes) + r# (try (#'lookup-route [route-name# (vec (drop ~keylen args#))] + ~@routes) + (catch Exception _#)) {uri# :uri, args# :args} r#] (if r# (assoc r# @@ -68,6 +69,11 @@ (= (count args#) (count ~(vec route-args)))) ~routes-map))))) +(defmacro with-url-fn [f & body] + `(binding [*lookup-route* (fn [x#] (apply ~f x#)) + *root* ""] + ~@body)) + (defn url-for [route & arg-values] (let [spec (*lookup-route* [route arg-values]) {:keys [uri type args]} spec -- cgit v1.2.3