|
10 | 10 | [linked.core :as linked] |
11 | 11 | [compojure.response] |
12 | 12 | [schema.core :as s]) |
13 | | - (:import [clojure.lang AFn IFn Var])) |
| 13 | + (:import (clojure.lang AFn IFn Var IDeref) |
| 14 | + (java.io Writer))) |
14 | 15 |
|
15 | 16 | ;; |
16 | 17 | ;; Route records |
|
47 | 48 | (update-in route [0] (fn [uri] (if (str/blank? uri) "/" uri)))) |
48 | 49 | (-get-routes handler options)))) |
49 | 50 |
|
| 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 | + |
50 | 64 | (defrecord Route [path method info childs handler] |
51 | 65 | Routing |
52 | 66 | (-get-routes [this options] |
|
72 | 86 | IFn |
73 | 87 | (invoke [_ request] |
74 | 88 | (handler request)) |
| 89 | + (invoke [_ request respond raise] |
| 90 | + (handler request respond raise)) |
| 91 | + |
75 | 92 | (applyTo [this args] |
76 | 93 | (AFn/applyToHelper this args))) |
77 | 94 |
|
78 | 95 | (defn create [path method info childs handler] |
79 | 96 | (->Route path method info childs handler)) |
80 | 97 |
|
| 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 | + |
81 | 108 | ;; |
82 | 109 | ;; Invalid route handlers |
83 | 110 | ;; |
|
0 commit comments