hanami/router

Using a variable in a namespace

malin-as opened this issue · 7 comments

Hi,

In order to have some internationalisation support on a project, I decided to give a try to URLs of the form https://server/en/home where en is the chosen locale for the interface. I played a bit with namespace:

root to: 'root#detect_locale'

namespace ':locale' do
  get     '/',       to: 'root#index',   as: :root
  get     '/home',   to: 'home#index',   as: :home
end

This actually works, but I'm afraid it was not designed for that purpose (and might stop working in a future version), since it's impossible to set a filter on it, and since it breaks the path name generation of resources.

What are your thoughts on such a feature? I could give a try at a PR.

@malin-as This looks as a great addition. Please give it a try.

@malin-as maybe we don't need to amend namespace, what I think is we can add a new word for that porpuse and the word comes to my mind is scope, what do you think?

IMO namespace is designed to other purpose so I prefer to add a new word like scope or other name.

@AlfonsoUceda I don't see clearly what the difference would be between them, from the point of view of a Hanami user. The way I see it, namespace would become just a special case of scope, when there's no variable involved.

Either way, I'm having trouble with the internal plumbing, trying to figure out how hanami-router and http_router interact exactly, and what http_router is compiling for each route, and how to debug that. I'm afraid that's too complicated for me.

@AlfonsoUceda Can you please expand what you mean and what are the differences between namespace and scope? Thanks!

Just if it makes easier the implementation, namespace will create a namespace in ruby and scope just to work with variables.

@AlfonsoUceda but having #namespace to dynamically create a Ruby namespace is a breaking change. Am I missing something?

Closing as stale conversation. Is someone wants to take care of this feature, please reopen this issue.