Skip to content

Commit 3f92625

Browse files
committed
backport routing print-method and specialized invoke
1 parent f81554e commit 3f92625

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/compojure/api/routes.clj

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
[linked.core :as linked]
1111
[compojure.response]
1212
[schema.core :as s])
13-
(:import [clojure.lang AFn IFn Var]))
13+
(:import (clojure.lang AFn IFn Var IDeref)
14+
(java.io Writer)))
1415

1516
;;
1617
;; Route records
@@ -47,6 +48,19 @@
4748
(update-in route [0] (fn [uri] (if (str/blank? uri) "/" uri))))
4849
(-get-routes handler options))))
4950

51+
(defn get-static-context-routes
52+
([handler]
53+
(get-static-context-routes handler nil))
54+
([handler options]
55+
(filter (fn [[_ _ info]] (get info :static-context?))
56+
(get-routes handler options))))
57+
58+
(defn- realize-childs [route]
59+
(update route :childs #(if (instance? IDeref %) @% %)))
60+
61+
(defn- filter-childs [route]
62+
(update route :childs (partial filter (partial satisfies? Routing))))
63+
5064
(defrecord Route [path method info childs handler]
5165
Routing
5266
(-get-routes [this options]
@@ -72,12 +86,25 @@
7286
IFn
7387
(invoke [_ request]
7488
(handler request))
89+
(invoke [_ request respond raise]
90+
(handler request respond raise))
91+
7592
(applyTo [this args]
7693
(AFn/applyToHelper this args)))
7794

7895
(defn create [path method info childs handler]
7996
(->Route path method info childs handler))
8097

98+
(defmethod print-method Route
99+
[this ^Writer w]
100+
(let [childs (some-> this realize-childs filter-childs :childs seq vec)]
101+
(.write w (str "#Route"
102+
(cond-> (dissoc this :handler :childs)
103+
(not (:path this)) (dissoc :path)
104+
(not (seq (:info this))) (dissoc :info)
105+
(not (:method this)) (dissoc :method)
106+
childs (assoc :childs childs))))))
107+
81108
;;
82109
;; Invalid route handlers
83110
;;

0 commit comments

Comments
 (0)