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

Added config for controllers path used by generator #119

Closed
wants to merge 3 commits into from
Closed

Added config for controllers path used by generator #119

wants to merge 3 commits into from

Conversation

wJoenn
Copy link

@wJoenn wJoenn commented May 6, 2023

I am using vite_rails in my project and because of that I don't have a app/javascript folder but a app/frontend/javascript folder.
Because the path in the Stimulus generator is hardcoded every time I try to use it to generate a new controller it would recreate the app/javascript folder and add the controller there instead of inside my existing folder.

Here's a fix that would make any file structure compatible by using Dir.glob("**/javascript/controllers").first instead of "app/javascript/controllers"

I tested it locally and it's working as expected as far as I can see

@wJoenn
Copy link
Author

wJoenn commented May 21, 2023

Scrap this, it was raised to my attention that this could have conflicts if any other javascript/controllers directory exist.
I'll work on a different way that would use the config file of Rails.
Something like

config.generators do |generate|
  generate.stimulus_path "path/to/controllers"
end

@wJoenn wJoenn changed the title Changed javascript/controller path to Dir.glob Added config for controllers path used by generator May 27, 2023
@wJoenn
Copy link
Author

wJoenn commented May 27, 2023

In the end I created a stimulus initializer file in which I can configurate the path by doind

Stimulus.configure do |config|
  config.controllers_path = "path/to/controllers"
end

The value of Stimulus.controllers_path is then read in the generator and task to respect the user's preference

@wJoenn
Copy link
Author

wJoenn commented Jul 29, 2023

@dhh May I ask why ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants