ash-project / igniter

A code generation and project patching framework.
https://hexdocs.pm/igniter/readme.html
MIT License
180 stars 21 forks source link

Phoenix Path / Module Utilities #81

Open maennchen opened 2 months ago

maennchen commented 2 months ago

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 commented 2 months ago

Summary from discussions with @zachdaniel and on Twitter

zachdaniel commented 2 months ago

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.