Module: Weft::Context::Expansion

Included in:
Weft::Context
Defined in:
lib/weft/context/expansion.rb

Overview

The element-kwarg expansion engine: turns Weft kwargs on any element into htmx attributes. Mixed into Weft::Context; Interception#insert_tag invokes it on the root context (via arbre_context).

This module owns the INTERACTION rank of the kwarg grammar — the kwargs that generate request wiring, first match wins: action: (Symbol), navigate: (Hash), loads: (Class), or a registered preset name (Class or URL String). Value shape is the claim — a String action: stays honest form HTML — and a claimed kwarg that cannot resolve raises Weft::InvalidUsage rather than leaking into the HTML. The MODIFIER rank (trigger:/push_url:/confirm:/swap:/target:) lives in Context::Modifiers; the hx-* builders and tree lookups the expanders assemble from live in Context::Wiring.

Instance Method Summary collapse

Instance Method Details

#expand_weft_attrs(attrs, for_class: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
30
31
32
33
34
# File 'lib/weft/context/expansion.rb', line 27

def expand_weft_attrs(attrs, for_class: nil)
  attrs = attrs.dup
  mods = Modifiers::MODIFIER_KEYS.to_h { |k| [k, attrs.delete(k)] }
  validate_with_ownership!(attrs)
  expanded = expand_action(attrs, for_class: for_class) || expand_navigate(attrs) ||
             expand_loads(attrs, mods) || expand_preset(attrs, mods)
  expanded ? overlay_modifiers(expanded, mods) : passthrough_modifiers(attrs, mods)
end

#weft_kwarg?(hash) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Whether an attrs hash carries any Weft kwarg.

Returns:

  • (Boolean)


38
# File 'lib/weft/context/expansion.rb', line 38

def weft_kwarg?(hash) = interaction_kwarg?(hash) || modifier_kwarg?(hash) || claimed?(hash, :with)