(defn wrap-route [url func & params](swap! wrappers conj {:url (noir/route->name url) :func #(apply func % params)}))
(defn ^{:skip-wiki true} route->name"Parses a set of route args into the keyword name for the route"[route](cond(keyword? route) route(fn? route) (keyword (:name (meta route))):else (let [res (first (parse-route [{} [route]] 'compojure.core/GET))](keyword (:fn-name res)))))
I've been using (defpage somename "/somename" ...) now for a while
and now I hear you say it's not recommended. The look of the (def
start "/start")
(defpage start []
)
is, to me, not as nice. What are the pitfalls of (defpage somename
"/somename" ...) ?
"Usually the point of using the named routes is for url-for and if you
have pages that have links to eachother in them, it's very hard to
make that work."
Makes total sense, thank you. What do you think about people solving
this by assiduous/minimal use of (declare ...) at the top of the file?
Good points. I tried writing something that used a different mechanism
but I found that interrogating the routes wasn't easy: ended up with a
40-line function that worked 75% of the time: a sign I was barking up
the wrong tree. Thanks and sorry if I might have hijacked this thread
a bit.
All my efforts came from a desire to have something like
`reverse("route-name")` from Django equivalent a while back. I settled
on url-for with some frobbing and haven't had a problem yet, but I
feel like I will...
I was actually going to take a crack at this myself, but will hold
back pending your thoughts.
All my efforts came from a desire to have something like
`reverse("route-name")` from Django equivalent a while back. I settled
on url-for with some frobbing and haven't had a problem yet, but I
feel like I will...