Browse files

Change url-for to handle qualified keys


(def routes [[:get "/todo/:todo-id/tag/:id"]])

(url-for {:todo/id 1 :id 2}) ; =>


(def routes [[:get "/todo/:todo-id/tag/:id"]])

(url-for {:todo/id 1 :id 2}) ; => "/todo/1/tag/2"

So, all qualified keywords get matched with their dashed equivalents:

:todo/id -> :todo-id
:customer/name -> :customer-name

Closes #29
  • Loading branch information...
swlkr committed Sep 27, 2018
1 parent fab6c6b commit 0f0299e04012f5ac6d04493f146f1a8d7d6a1ab9
Showing with 10 additions and 2 deletions.
  1. +10 −2 src/coast/router.clj
@@ -7,10 +7,18 @@
(def param-re #":([\w-_]+)")
(defn qualify-ident [k]
(when (and (ident? k)
(re-find #"-" (name k)))
(let [[kns kn] (string/split (name k) #"-")]
(keyword (or kns "") (or kn "")))))
(defn replacement [match m]
(let [fallback (first match)
k (-> match last keyword)]
(str (get m k fallback))))
k (-> match last keyword)
s1 (get m k)
s2 (get m (qualify-ident k))]
(str (or s1 s2 fallback))))
(defn route-str [s m]
(when (and (string? s)

0 comments on commit 0f0299e

Please sign in to comment.