mirror of
https://github.com/metosin/reitit.git
synced 2025-12-29 04:38:26 +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]
|
||||
(into [] (keep #(compile-route % opts) routes)))
|
||||
|
||||
(defn route-info [route]
|
||||
(select-keys (impl/create route) [:path :parts :params :result :meta]))
|
||||
|
||||
(defprotocol Router
|
||||
(router-name [this])
|
||||
(routes [this])
|
||||
|
|
@ -256,6 +259,7 @@
|
|||
(mixed-router routes {}))
|
||||
([routes opts]
|
||||
(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)
|
||||
wildcard-router (linear-router linear opts)
|
||||
static-router (->static-router lookup opts)
|
||||
|
|
@ -264,7 +268,7 @@
|
|||
(router-name [_]
|
||||
:mixed-router)
|
||||
(routes [_]
|
||||
routes)
|
||||
compiled)
|
||||
(options [_]
|
||||
opts)
|
||||
(route-names [_]
|
||||
|
|
|
|||
|
|
@ -105,22 +105,19 @@
|
|||
|
||||
(defn create [[path meta result]]
|
||||
(let [path #?(:clj (.intern ^String path) :cljs path)]
|
||||
(if (contains-wilds? path)
|
||||
(as-> (parse-path path) $
|
||||
(assoc $ :path-re (path-regex $))
|
||||
(merge $ {:path path
|
||||
:matcher (path-matcher $)
|
||||
:result result
|
||||
:meta meta})
|
||||
(dissoc $ :path-re :path-constraints)
|
||||
(update $ :path-params set)
|
||||
(set/rename-keys $ {:path-parts :parts
|
||||
:path-params :params})
|
||||
(map->Route $))
|
||||
(map->Route {:path path
|
||||
:meta meta
|
||||
:matcher #(if (#?(:clj .equals, :cljs =) path %) {})
|
||||
:result result}))))
|
||||
(as-> (parse-path path) $
|
||||
(assoc $ :path-re (path-regex $))
|
||||
(merge $ {:path path
|
||||
:matcher (if (contains-wilds? path)
|
||||
(path-matcher $)
|
||||
#(if (#?(:clj .equals, :cljs =) path %) {}))
|
||||
:result result
|
||||
:meta meta})
|
||||
(dissoc $ :path-re :path-constraints)
|
||||
(update $ :path-params set)
|
||||
(set/rename-keys $ {:path-parts :parts
|
||||
:path-params :params})
|
||||
(map->Route $))))
|
||||
|
||||
(defn segments [path]
|
||||
(let [ss (-> (str/split path #"/") rest vec)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue