bridgetownrb / bridgetown

A next-generation progressive site generator & fullstack framework, powered by Ruby
https://www.bridgetownrb.com
MIT License
1.11k stars 114 forks source link

Use Global Regex for Stimulus Configuration #865

Closed MSILycanthropy closed 3 months ago

MSILycanthropy commented 3 months ago

This is a 🐛 bug fix.

Summary

When using the Stimulus Configuration, the generated code for loading Stimulus controllers makes a couple replace calls to translate a path to a Stimulus identifier.

This means that if you have a controller whose filename is do_a_thing_controller.js, this gets translated into the Stimulus identifier do-a_thing, when one would expect it to have been do-a-thing. There case for controllers nested in directories is similar.

With the way Stimulus currently works, it's incredibly annoying to debug this, because there are no warnings. Your controller just seemingly doesn't work.

Context

When building my personal site with Bridgetown and Hotwire, I added a controller that used multiple underscores, and then spent an embarrassing amount of time trying to figure out what I had done wrong. Was surprised to see that only one replacement had taken place.

jaredcwhite commented 3 months ago

Thanks @MSILycanthropy! FYI I took the liberty of committing a fix for the regex backslash so it carries over to the JS code from the Ruby heredoc. I know, confusing! (Otherwise the JS file would just have /// istead of /\//.)