Module: Vident::Capabilities::StimulusDataEmitting

Included in:
Vident::Component
Defined in:
lib/vident/capabilities/stimulus_data_emitting.rb

Instance Method Summary collapse

Instance Method Details

#root_element_class_list(extra_classes = nil) ⇒ Object

For components rendering the root via a third-party helper instead of ‘root_element(…)`. `extra_classes` lands at the lowest-priority tier so it cannot be clobbered by a cascade winner.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vident/capabilities/stimulus_data_emitting.rb', line 12

def root_element_class_list(extra_classes = nil)
  extra = resolved_root_element_attributes
  extra_html_options = extra[:html_options] || {}
  combined_classes = [@classes, extra_classes].flatten.compact
  result = ::Vident::Internals::ClassListBuilder.call(
    component_name: component_name,
    root_element_classes: root_element_classes,
    root_element_attributes_classes: extra[:classes],
    html_options_class: @html_options[:class] || extra_html_options[:class],
    classes_prop: combined_classes.empty? ? nil : combined_classes,
    tailwind_merger: tailwind_merger
  )
  result || ""
end

#root_element_data_attributesObject

Seals the Draft on first call (idempotent). Symbol keys.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vident/capabilities/stimulus_data_emitting.rb', line 28

def root_element_data_attributes
  plan = seal_draft
  data_attrs = ::Vident::Internals::AttributeWriter.call(plan)

  extra = resolved_root_element_attributes
  extra_data = (extra[:html_options] || {})[:data] || {}

  merged = data_attrs.dup
  merged.merge!(symbolize_keys(extra_data))
  merged.merge!(symbolize_keys(@html_options[:data] || {}))
  merged
end