mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +00:00
Fix expand, fixes #201
This commit is contained in:
parent
a1be00842a
commit
35ff62a1da
3 changed files with 26 additions and 10 deletions
|
|
@ -1,3 +1,10 @@
|
||||||
|
## UNRELEASED
|
||||||
|
|
||||||
|
|
||||||
|
### `reitit-core`
|
||||||
|
|
||||||
|
* `reitit.core/Expand` can be extended, fixes [#201](https://github.com/metosin/reitit/issues/201).
|
||||||
|
|
||||||
## 0.2.10 (2018-12-30)
|
## 0.2.10 (2018-12-30)
|
||||||
|
|
||||||
### `reitit-core`
|
### `reitit-core`
|
||||||
|
|
|
||||||
|
|
@ -112,10 +112,10 @@
|
||||||
(f conflicts)
|
(f conflicts)
|
||||||
{:conflicts conflicts})))
|
{:conflicts conflicts})))
|
||||||
|
|
||||||
(defn name-lookup [[_ {:keys [name]}] _]
|
(defn- name-lookup [[_ {:keys [name]}] _]
|
||||||
(if name #{name}))
|
(if name #{name}))
|
||||||
|
|
||||||
(defn find-names [routes _]
|
(defn- find-names [routes _]
|
||||||
(into [] (keep #(-> % second :name)) routes))
|
(into [] (keep #(-> % second :name)) routes))
|
||||||
|
|
||||||
(defn- compile-route [[p m :as route] {:keys [compile] :as opts}]
|
(defn- compile-route [[p m :as route] {:keys [compile] :as opts}]
|
||||||
|
|
@ -164,13 +164,6 @@
|
||||||
([match query-params]
|
([match query-params]
|
||||||
(some-> match :path (cond-> query-params (str "?" (impl/query-string query-params))))))
|
(some-> match :path (cond-> query-params (str "?" (impl/query-string query-params))))))
|
||||||
|
|
||||||
(def default-router-options
|
|
||||||
{:lookup name-lookup
|
|
||||||
:expand expand
|
|
||||||
:coerce (fn [route _] route)
|
|
||||||
:compile (fn [[_ {:keys [handler]}] _] handler)
|
|
||||||
:conflicts (partial throw-on-conflicts! path-conflicts-str)})
|
|
||||||
|
|
||||||
(defn linear-router
|
(defn linear-router
|
||||||
"Creates a linear-router from resolved routes and optional
|
"Creates a linear-router from resolved routes and optional
|
||||||
expanded options. See [[router]] for available options."
|
expanded options. See [[router]] for available options."
|
||||||
|
|
@ -415,6 +408,13 @@
|
||||||
(or (match-by-name mixed-router name path-params)
|
(or (match-by-name mixed-router name path-params)
|
||||||
(match-by-name linear-router name path-params)))))))
|
(match-by-name linear-router name path-params)))))))
|
||||||
|
|
||||||
|
(defn ^:no-doc default-router-options []
|
||||||
|
{:lookup name-lookup
|
||||||
|
:expand expand
|
||||||
|
:coerce (fn [route _] route)
|
||||||
|
:compile (fn [[_ {:keys [handler]}] _] handler)
|
||||||
|
:conflicts (partial throw-on-conflicts! path-conflicts-str)})
|
||||||
|
|
||||||
(defn router
|
(defn router
|
||||||
"Create a [[Router]] from raw route data and optionally an options map.
|
"Create a [[Router]] from raw route data and optionally an options map.
|
||||||
Selects implementation based on route details. The following options
|
Selects implementation based on route details. The following options
|
||||||
|
|
@ -435,7 +435,7 @@
|
||||||
([raw-routes]
|
([raw-routes]
|
||||||
(router raw-routes {}))
|
(router raw-routes {}))
|
||||||
([raw-routes opts]
|
([raw-routes opts]
|
||||||
(let [{:keys [router] :as opts} (merge default-router-options opts)
|
(let [{:keys [router] :as opts} (merge (default-router-options) opts)
|
||||||
routes (resolve-routes raw-routes opts)
|
routes (resolve-routes raw-routes opts)
|
||||||
path-conflicting (path-conflicting-routes routes)
|
path-conflicting (path-conflicting-routes routes)
|
||||||
name-conflicting (name-conflicting-routes routes)
|
name-conflicting (name-conflicting-routes routes)
|
||||||
|
|
|
||||||
|
|
@ -314,3 +314,12 @@
|
||||||
(-> ["/api"
|
(-> ["/api"
|
||||||
(list "/ipa")]
|
(list "/ipa")]
|
||||||
(r/router))))))
|
(r/router))))))
|
||||||
|
|
||||||
|
(defrecord Named [n]
|
||||||
|
r/Expand
|
||||||
|
(r/expand [_ _] {:name n}))
|
||||||
|
|
||||||
|
(deftest default-expand-test
|
||||||
|
(let [router (r/router ["/endpoint" (->Named :kikka)])]
|
||||||
|
(is (= [["/endpoint" {:name :kikka}]]
|
||||||
|
(r/routes router)))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue