mirror of
https://github.com/metosin/reitit.git
synced 2026-02-01 10:20:35 +00:00
Add reitit.core/route-info
This commit is contained in:
parent
264266ee43
commit
26308bcb92
2 changed files with 18 additions and 17 deletions
|
|
@ -98,6 +98,9 @@
|
||||||
(defn- compile-routes [routes opts]
|
(defn- compile-routes [routes opts]
|
||||||
(into [] (keep #(compile-route % opts) routes)))
|
(into [] (keep #(compile-route % opts) routes)))
|
||||||
|
|
||||||
|
(defn route-info [route]
|
||||||
|
(select-keys (impl/create route) [:path :parts :params :result :meta]))
|
||||||
|
|
||||||
(defprotocol Router
|
(defprotocol Router
|
||||||
(router-name [this])
|
(router-name [this])
|
||||||
(routes [this])
|
(routes [this])
|
||||||
|
|
@ -256,6 +259,7 @@
|
||||||
(mixed-router routes {}))
|
(mixed-router routes {}))
|
||||||
([routes opts]
|
([routes opts]
|
||||||
(let [{linear true, lookup false} (group-by impl/wild-route? routes)
|
(let [{linear true, lookup false} (group-by impl/wild-route? routes)
|
||||||
|
compiled (compile-routes routes opts)
|
||||||
->static-router (if (= 1 (count lookup)) single-static-path-router lookup-router)
|
->static-router (if (= 1 (count lookup)) single-static-path-router lookup-router)
|
||||||
wildcard-router (linear-router linear opts)
|
wildcard-router (linear-router linear opts)
|
||||||
static-router (->static-router lookup opts)
|
static-router (->static-router lookup opts)
|
||||||
|
|
@ -264,7 +268,7 @@
|
||||||
(router-name [_]
|
(router-name [_]
|
||||||
:mixed-router)
|
:mixed-router)
|
||||||
(routes [_]
|
(routes [_]
|
||||||
routes)
|
compiled)
|
||||||
(options [_]
|
(options [_]
|
||||||
opts)
|
opts)
|
||||||
(route-names [_]
|
(route-names [_]
|
||||||
|
|
|
||||||
|
|
@ -105,22 +105,19 @@
|
||||||
|
|
||||||
(defn create [[path meta result]]
|
(defn create [[path meta result]]
|
||||||
(let [path #?(:clj (.intern ^String path) :cljs path)]
|
(let [path #?(:clj (.intern ^String path) :cljs path)]
|
||||||
(if (contains-wilds? path)
|
(as-> (parse-path path) $
|
||||||
(as-> (parse-path path) $
|
(assoc $ :path-re (path-regex $))
|
||||||
(assoc $ :path-re (path-regex $))
|
(merge $ {:path path
|
||||||
(merge $ {:path path
|
:matcher (if (contains-wilds? path)
|
||||||
:matcher (path-matcher $)
|
(path-matcher $)
|
||||||
:result result
|
#(if (#?(:clj .equals, :cljs =) path %) {}))
|
||||||
:meta meta})
|
:result result
|
||||||
(dissoc $ :path-re :path-constraints)
|
:meta meta})
|
||||||
(update $ :path-params set)
|
(dissoc $ :path-re :path-constraints)
|
||||||
(set/rename-keys $ {:path-parts :parts
|
(update $ :path-params set)
|
||||||
:path-params :params})
|
(set/rename-keys $ {:path-parts :parts
|
||||||
(map->Route $))
|
:path-params :params})
|
||||||
(map->Route {:path path
|
(map->Route $))))
|
||||||
:meta meta
|
|
||||||
:matcher #(if (#?(:clj .equals, :cljs =) path %) {})
|
|
||||||
:result result}))))
|
|
||||||
|
|
||||||
(defn segments [path]
|
(defn segments [path]
|
||||||
(let [ss (-> (str/split path #"/") rest vec)]
|
(let [ss (-> (str/split path #"/") rest vec)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue