Class: Weft::Context
- Inherits:
-
Arbre::Context
- Object
- Arbre::Context
- Weft::Context
- Includes:
- Interception
- Defined in:
- lib/weft/context.rb,
lib/weft/context/interception.rb
Overview
Arbre::Context subclass that intercepts element creation to expand Weft kwargs into htmx attributes.
Works at every nesting depth because Arbre instance_evals the top-level block, making the Context the receiver for all insert_tag calls throughout the element tree.
Supported kwargs:
action: :name— expands into htmx attrs for a declared performs/transfers actionnavigate: { key: val }— expands into htmx GET to self with overridden attrstrigger: "event"— sets hx-trigger (standalone or alongside action:/navigate:)
Defined Under Namespace
Modules: Interception
Instance Method Summary collapse
-
#expand_weft_attrs(attrs, for_class: nil) ⇒ Object
private
Expands Weft kwargs into htmx attributes.
-
#weft_kwarg?(hash) ⇒ Boolean
private
Guard check for whether an attrs hash carries any Weft kwarg.
Methods included from Interception
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.
Expands Weft kwargs into htmx attributes. Invoked by the Interception
mixin's #insert_tag on the root Weft::Context (via arbre_context).
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/weft/context.rb', line 23 def (attrs, for_class: nil) attrs = attrs.dup custom_trigger = attrs.delete(:trigger) push_url = attrs.delete(:push_url) attrs = (attrs, for_class: for_class) || (attrs) || (attrs) || (attrs) || attrs attrs["hx-trigger"] = resolve_trigger(custom_trigger) if custom_trigger attrs["hx-push-url"] = push_url.to_s if push_url attrs 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.
Guard check for whether an attrs hash carries any Weft kwarg. Invoked by
the Interception mixin's #insert_tag on the root Weft::Context (via
arbre_context).
38 39 40 41 |
# File 'lib/weft/context.rb', line 38 def weft_kwarg?(hash) hash[:action].is_a?(Symbol) || hash.key?(:trigger) || hash[:navigate].is_a?(Hash) || hash[:loads].is_a?(Class) || hash.key?(:push_url) || find_shorthand_kwarg(hash) end |