Class: HTMX::Prefixer

Inherits:
Object
  • Object
show all
Defined in:
lib/htmx/prefixer.rb

Overview

Prefixes HTML element attributes for proper consumption by the HTMX JavaScript library.

Constant Summary collapse

ALLOWED =
%w[hx data-hx].freeze

Instance Method Summary collapse

Constructor Details

#initialize(default = "hx", allowed: ALLOWED) ⇒ Prefixer

Returns a new instance of Prefixer.



12
13
14
15
16
# File 'lib/htmx/prefixer.rb', line 12

def initialize default = "hx", allowed: ALLOWED
  @default = default
  @allowed = allowed
  validate
end

Instance Method Details

#call(**attributes) ⇒ Object



18
# File 'lib/htmx/prefixer.rb', line 18

def call(**attributes) = attributes.transform_keys! { |key| "#{default}-#{key}".tr "_", "-" }