module StimulusAttrs::Helpers %i[controller target values classes actions params outlets].each do |method| define_method("stimulus_#{method}") do |*args, **kwargs| kwargs[:identifier] ||= identifier_for_stimulus_attrs if respond_to?(:identifier_for_stimulus_attrs) if self.class.respond_to?(:identifier_for_stimulus_attrs) kwargs[:identifier] ||= self.class.identifier_for_stimulus_attrs end StimulusAttrs.public_send(method, *args, **kwargs) end end ActiveSupport.on_load(:action_view) do include StimulusAttrs::Helpers end ViewComponent::Base.include(self) if defined?(ViewComponent::Base) Phlex::HTML.include(self) if defined?(Phlex::HTML) end