From 3005e04a6efc90aa692bba930a97492ff6f3a528 Mon Sep 17 00:00:00 2001 From: Tommi Reiman Date: Mon, 12 Feb 2018 07:49:24 +0200 Subject: [PATCH] Inject Match and Router under reitit.core ns in ring --- modules/reitit-ring/src/reitit/ring.cljc | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/modules/reitit-ring/src/reitit/ring.cljc b/modules/reitit-ring/src/reitit/ring.cljc index cb3cacdf..151d1d6a 100644 --- a/modules/reitit-ring/src/reitit/ring.cljc +++ b/modules/reitit-ring/src/reitit/ring.cljc @@ -32,7 +32,7 @@ ([{:keys [not-found method-not-allowed not-acceptable]}] (fn ([request] - (if-let [match (::match request)] + (if-let [match (::r/match request)] (let [method (:request-method request :any) result (:result match) handler? (or (-> result method :handler) (-> result :any :handler)) @@ -40,7 +40,7 @@ (error-handler request)) (not-found request))) ([request respond _] - (if-let [match (::match request)] + (if-let [match (::r/match request)] (let [method (:request-method request :any) result (:result match) handler? (or (-> result method :handler) (-> result :any :handler)) @@ -66,8 +66,10 @@ result (:result match) handler (or (-> result method :handler) (-> result :any (:handler default-handler))) - request (cond-> (impl/fast-assoc request ::match match) - (seq path-params) (impl/fast-assoc :path-params path-params)) + request (-> request + (impl/fast-assoc ::r/match match) + (impl/fast-assoc ::r/router router) + (cond-> (seq path-params) (impl/fast-assoc :path-params path-params))) response (handler request)] (if (nil? response) (default-handler request) @@ -80,17 +82,19 @@ result (:result match) handler (or (-> result method :handler) (-> result :any (:handler default-handler))) - request (cond-> (impl/fast-assoc request ::match match) - (seq path-params) (impl/fast-assoc :path-params path-params))] + request (-> request + (impl/fast-assoc ::r/match match) + (impl/fast-assoc ::r/router router) + (cond-> (seq path-params) (impl/fast-assoc :path-params path-params)))] (handler request respond raise)) (default-handler request respond raise)))) - {::router router})))) + {::r/router router})))) (defn get-router [handler] - (some-> handler meta ::router)) + (-> handler meta ::r/router)) (defn get-match [request] - (::match request)) + (::r/match request)) (defn coerce-handler [[path data] {:keys [expand] :as opts}] [path (reduce