domkm / silk

Routing for Clojure & ClojureScript
222 stars 13 forks source link

Feature requests: non-encoded and not-blank parameter based departs #11

Closed whodidthis closed 9 years ago

whodidthis commented 9 years ago

Non-encoded departs:

UTF-8 in URLs seems to have been fine for a long time so it would be nice to have an option to not not encode departs. https://blog.mozilla.org/gen/2008/05/23/firefox-3-utf-8-support-in-location-bar/

Departs based on non-nil parameters

I would like to create routes like

[[:front-page [[""]]]
 [:front-page [["search" :search]]]

In a way that would enable me to depart based on whether a parameter is not-blank, like

(depart routes :front-page {:search nil}) ;=> "/"
(depart routes :front-page {:search "this"}) ;=> "/search/this

I see arrives are fine as they are matched against the sequence of vectors, but the depart map should be modified from

{:front-page <Route>}

to something around

{:front-page {#{} <Route> #{:search} <Route2>}}

So basically kind of like using query-params except not looking super ugly to the user.

Anyways do you think silk would be fit to support such features? I wrote infer ages ago but would be nice to use a community supported router.

domkm commented 9 years ago

Hi @whodidthis,

Thanks for the suggestions!

Non-encoded departs

The current behavior of splitting on path segments is buggy by default because it treats "/foo" the same as "/foo/". Because of this, Silk 1.0.0 will not split at path segments and therefore neither encode or decode by default.

I'll take a look at your PR but I'm hesitant to introduce your suggested functionality at this time because I am hoping to release 1.0.0 within the next month or two.

Departs based on non-nil parameters

This syntax will never be supported because route names are meant to be unique:

[[:front-page [[""]]]
 [:front-page [["search" :search]]]

However, you will be able to achieve what I think are your intended results with something like this:

[[:front-page [(silk/|
                (silk/cat "/search/" :search)
                "/")]]]

That syntax isn't finalized but Silk 1.0.0 will have functionality similar to that.

So, I think the answer to both of your questions is "yes."

whodidthis commented 9 years ago

Sweet, silk/| seems exactly what i was looking for