Module: ViewAttributeMerge

Defined in:
lib/view_attribute_merge.rb,
lib/view_attribute_merge/merger.rb,
lib/view_attribute_merge/version.rb

Overview

Attribute helper for rails partials, ViewComponents, and more.

  • Concatenates when it makes sense: CSS and Stimulus.

  • Merges otherwise.

  • Source attributes are prioritized in ascending order; treats the first hash as the most important.

  • Does its best to reconcile ‘data-*’ and data: { *: }, output will be as a data hash.

Examples:

Merging two attribute hashes

ViewAttributeMerge.attr_merge({ class: "bold", data-tag="user" }, { class: "underlined", data-tag: "admin" })
# => {class: "bold underlined", data: { tag: "user" } }

Defined Under Namespace

Classes: Error, Merger

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.attr_merge(*sources) ⇒ Object



18
19
20
# File 'lib/view_attribute_merge.rb', line 18

def self.attr_merge(*sources)
  Merger.new.merge(*sources)
end