Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phoenix Path / Module Utilities #81

Open
maennchen opened this issue Sep 10, 2024 · 2 comments
Open

Phoenix Path / Module Utilities #81

maennchen opened this issue Sep 10, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@maennchen
Copy link
Contributor

Is your feature request related to a problem? Please describe.
When creating phoenix controllers, they are written to a location not adhering to the phoenix conventions.

MyAppWeb.TestController => lib/my_app_web/test_controller.ex instead of lib/my_app_web/controllers/test.ex

Describe the solution you'd like

Provide Igniter.Libs.Phoenix.proper_location/2, and a way to override the path for Igniter.Code.Module.create_module/4.

Additionally, the modules should not be moved to their "correct" location at the end or there should be a convenient function to add it to the do_not_move igniter configuration.

Describe alternatives you've considered

Express the feature either with a change to resource syntax, or with a change to the resource interface

For example

Igniter.Libs.Phoenix.proper_location(igniter, TestWeb.TestController) # => lib/test_web/controllers.test.ex

Additional context

None

@maennchen maennchen added the enhancement New feature or request label Sep 10, 2024
@maennchen
Copy link
Contributor Author

Summary from discussions with @zachdaniel and on Twitter

  • The current phoenix conventions are optional. You can theoretically name controllers / live views etc. however you like.
  • To be able to handle the current conventions with igniter, it would be good to be able to influence Igniter.Code.Module.proper_location/2
    • This could be achieved by allowing to configure extensions in the ingiter configuration.
  • We could theoretically also introduce new conventions.
    • For example MyAppWeb.Controller.Foo instead of MyAppWeb.FooController and keep the paths according to normal elixir best practices.
    • If we decide to implement a new convention, we should provide a migration command. (Best case would also move templates.)
  • To be able to generate correct module names according to any convention, a few Phoenix helpers would be helpful to create module names.
    • controller_name(igniter, "Foo")
      • current convention: MyAppWeb.FooController
      • hypothetical new convention: MyAppWeb.Controller.Foo
    • same for view modules / live views, channels etc.

@zachdaniel
Copy link
Contributor

Alright, so what I've come up with really might not be great. We will have to see. But we now have a Phoenix extension that uses module naming heuristics to figure out where a given newly created module ought to go. We can see where this takes us. It is possible that it will need to be reworked to be able to take the zipper contents of what is being created, to peek inside and see what's going on, etc. But for now it will have to do.

The remaining things are things I probably won't tackle in the near future. Specifically:

  1. coming up with an alternative and more consistent with elixir patterns naming convention for phoenix
  2. adding functions like .controller_name to help with this consistency. These I will add as I need them, and encourage others to do so as well.

There is no seamless way to allow people to magically adopt this new standard, because they may not be using the function we provide in the first place, and relying on igniter to "do its thing". More realistically there would be some kind of migration task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants