Sha256: 34c7bdb24adecd8cb70daf4aae46cc76a874ec33e2ae7f8ab8b818c1522517ce

Contents?: true

Size: 704 Bytes

Versions: 1

Compression:

Stored size: 704 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stimulus_attrs-0.1.0 lib/stimulus_attrs/helpers.rb