Class: ViewAttributeMerge::Merger

Inherits:
Object
  • Object
show all
Defined in:
lib/view_attribute_merge/merger.rb

Overview

Merges HTML view attributes from multiple sources while handling special cases:

  • Stimulus 2.0 data attributes (controller/action/target)

  • Nested data/aria attributes

  • Class attribute concatenation

  • Attribute precedence (First specified wins)

Instance Method Summary collapse

Instance Method Details

#merge(*sources) ⇒ Hash

Merges multiple attribute hashes into a single normalized hash

Parameters:

  • sources (Array<Hash>)

    attribute hashes to merge

Returns:

  • (Hash)

    merged attributes with:

    • Stimulus attributes concatenated

    • Class attributes as arrays

    • Nested data/aria attributes merged

    • Later values overriding earlier ones



19
20
21
22
23
24
25
# File 'lib/view_attribute_merge/merger.rb', line 19

def merge(*sources)
  @output = {}

  sources.each { |source| process_source(source) }

  @output
end