This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-09
Channels
- # aws (3)
- # beginners (61)
- # boot (1)
- # cider (80)
- # clara (5)
- # cljs-dev (5)
- # cljsrn (19)
- # clojure (40)
- # clojure-dev (29)
- # clojure-dusseldorf (2)
- # clojure-greece (21)
- # clojure-italy (16)
- # clojure-russia (7)
- # clojure-spec (31)
- # clojure-uk (70)
- # clojurescript (31)
- # cursive (21)
- # data-science (5)
- # emacs (7)
- # fulcro (23)
- # graphql (4)
- # java (18)
- # jobs (1)
- # jobs-discuss (25)
- # juxt (14)
- # nrepl (2)
- # off-topic (18)
- # om-next (2)
- # onyx (3)
- # re-frame (16)
- # reagent (50)
- # ring-swagger (5)
- # shadow-cljs (70)
- # specter (5)
- # sql (24)
- # tools-deps (16)
- # vim (41)
I really like it when my bidi routes are plain data but when working with yada it seems common to just replace the route-id keywords with resources. Is there some way to maintain that separation?
(defrecord DocPage [page-type]
yada.resource/ResourceCoercion
(as-resource [_]
(yada/resource
{:id page-type
:description "The description to this example resource"
:summary "An example resource"
:produces "text/html"
:methods {:get (fn [_] "hello world")}})))
(->DocPage :my-id)
does something like this seem reasonable? This way my route leaves would be basic records…hm, that doesn’t work:
No implementation of method: :resolve-handler of protocol: #’bidi.bidi/Matched found for class: cljdoc.server.doc_pages.DocPage
Extending it with bidi’s protocols gets me to
No implementation of method: :request of protocol: #’bidi.ring/Ring found for class: cljdoc.server.doc_pages.DocPage
@dominicm I think I found some relevant code…
(defrecord DocPage [page-type]
yada.resource/ResourceCoercion
(as-resource [_]
(yada/resource
{:id page-type
:description “The description to this example resource”
:summary “An example resource”
:produces “text/html”
:methods {:get (fn [_] (str “hello world ” page-type))}}))
bidi.bidi/Matched
(resolve-handler [this m]
(let [r (yada.resource/as-resource this)]
(if (:path-info? r)
(assoc m :handler r)
(bidi.bidi/succeed r m))))
(unresolve-handler [this m]
(when
(or (= this (:handler m))
(and page-type (= page-type (:handler m))))
“”)))
is there a way to match all URI segments after a given /
into a collection?
e.g. /article/section1/section2/123
=> {:article-path ["section1" "section2" "123"]}
?
ah neat. it’s matching the URI now but additional segments are not part of the route-params. I assume I have to sort this out myself?
ah remainder
is a thing