smpallen99/coherence

Custom url path for controller actions

Open

#292 opened on Oct 9, 2017

View on GitHub
 (6 comments) (0 reactions) (0 assignees)Elixir (220 forks)batch import
enhancementhelp wanted

Repository metrics

Stars
 (1,259 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

The issue: when developing in phoenix (phx) we want to have a custom path for our Coherence resources. But we currently can't.

In the current file lib/router.ex the resource paths are hardcoded, instead we can have them as default arguments to that they can be customized in each project.

For example:

defmodule Coherence.Router do
...
defmacro coherence_routes(mode \\ [], opts \\ []) do # <--- we have an opportunity here
  ....
  if Coherence.Config.has_action?(:registerable, :new) do
    get "/registrations/new", Coherence.RegistrationController, :new
  end

# And we use this macro in our Phx router as: 
coherence_routes()

While we could do something like this:

defmodule Coherence.Router do
...
defmacro coherence_routes(mode \\ [], opts \\ [:registrations_path: "registrations", ...]) do 
  ....
  if Coherence.Config.has_action?(:registerable, :new) do
    get "/#{opts[:registrations_path]}/new", Coherence.RegistrationController, :new
  end

# And we use this macro in our Phx router as: 
coherence_routes([], [:registrations_path: "accounts"])

I could prepare and open a PR to address that 👍 What do you think?

Contributor guide