mirror of
https://github.com/metosin/reitit.git
synced 2025-12-16 16:01:11 +00:00
Strip nil routes from all positions
This commit is contained in:
parent
d53bbdfdf4
commit
d48515e084
3 changed files with 31 additions and 12 deletions
12
CHANGELOG.md
12
CHANGELOG.md
|
|
@ -1,5 +1,17 @@
|
||||||
## 0.1.2-SNAPSHOT
|
## 0.1.2-SNAPSHOT
|
||||||
|
|
||||||
|
### `reitit-core`
|
||||||
|
|
||||||
|
* Better handling of `nil` routes - they filtered away from route syntax before routes are expanded:
|
||||||
|
|
||||||
|
```clj
|
||||||
|
(testing "nil routes are allowed ans stripped"
|
||||||
|
(is (= [] (r/routes (r/router nil))))
|
||||||
|
(is (= [] (r/routes (r/router [nil [nil] [[nil nil nil]]]))))
|
||||||
|
(is (= [["/ping" {} nil]] (r/routes (r/router [nil [nil] ["/ping"]]))))
|
||||||
|
(is (= [["/ping" {} nil]] (r/routes (r/router [[[nil [nil] ["/ping"]]]])))))
|
||||||
|
```
|
||||||
|
|
||||||
### `reitit-schema`
|
### `reitit-schema`
|
||||||
|
|
||||||
* updated dependencies:
|
* updated dependencies:
|
||||||
|
|
|
||||||
|
|
@ -37,16 +37,17 @@
|
||||||
[(walk-many [p m r]
|
[(walk-many [p m r]
|
||||||
(reduce #(into %1 (walk-one p m %2)) [] r))
|
(reduce #(into %1 (walk-one p m %2)) [] r))
|
||||||
(walk-one [pacc macc routes]
|
(walk-one [pacc macc routes]
|
||||||
(if (vector? (first routes))
|
(if-let [routes (seq (keep identity routes))]
|
||||||
(walk-many pacc macc routes)
|
(if (vector? (first routes))
|
||||||
(let [[path & [maybe-arg :as args]] routes
|
(walk-many pacc macc routes)
|
||||||
[data childs] (if (vector? maybe-arg)
|
(let [[path & [maybe-arg :as args]] routes
|
||||||
[{} args]
|
[data childs] (if (vector? maybe-arg)
|
||||||
[maybe-arg (rest args)])
|
[{} args]
|
||||||
macc (into macc (expand data opts))]
|
[maybe-arg (rest args)])
|
||||||
(if (seq childs)
|
macc (into macc (expand data opts))]
|
||||||
(walk-many (str pacc path) macc childs)
|
(if (seq childs)
|
||||||
[[(str pacc path) macc]]))))]
|
(walk-many (str pacc path) macc childs)
|
||||||
|
[[(str pacc path) macc]])))))]
|
||||||
(walk-one path (mapv identity data) raw-routes)))
|
(walk-one path (mapv identity data) raw-routes)))
|
||||||
|
|
||||||
(defn map-data [f routes]
|
(defn map-data [f routes]
|
||||||
|
|
@ -87,10 +88,10 @@
|
||||||
(conflicts-str conflicts)
|
(conflicts-str conflicts)
|
||||||
{:conflicts conflicts})))
|
{:conflicts conflicts})))
|
||||||
|
|
||||||
(defn name-lookup [[_ {:keys [name]}] opts]
|
(defn name-lookup [[_ {:keys [name]}] _]
|
||||||
(if name #{name}))
|
(if name #{name}))
|
||||||
|
|
||||||
(defn find-names [routes opts]
|
(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}]
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,12 @@
|
||||||
r/segment-router :segment-router
|
r/segment-router :segment-router
|
||||||
r/mixed-router :mixed-router))
|
r/mixed-router :mixed-router))
|
||||||
|
|
||||||
|
(testing "nil routes are allowed ans stripped"
|
||||||
|
(is (= [] (r/routes (r/router nil))))
|
||||||
|
(is (= [] (r/routes (r/router [nil [nil] [[nil nil nil]]]))))
|
||||||
|
(is (= [["/ping" {} nil]] (r/routes (r/router [nil [nil] ["/ping"]]))))
|
||||||
|
(is (= [["/ping" {} nil]] (r/routes (r/router [[[nil [nil] ["/ping"]]]])))))
|
||||||
|
|
||||||
(testing "route coercion & compilation"
|
(testing "route coercion & compilation"
|
||||||
|
|
||||||
(testing "custom compile"
|
(testing "custom compile"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue