Module: LocoMotion::Patches::ViewComponent::SlotPatch
- Defined in:
- lib/loco_motion/patches/view_component/slot_loco_parent_patch.rb
Overview
Monkey patches ViewComponent::Slot so the LocoMotion component it
wraps can reach its parent — ViewComponent::Slot has no built-in way
to do that on its own. Slot-based components (tabs, accordion, drawer,
and others) depend on this patch to inherit config and state from
their parent via loco_parent.
Instance Method Summary collapse
-
#__vc_component_instance=(instance) ⇒ Object
Set the loco parent any time the instance changes.
-
#set_loco_parent(parent = @parent) ⇒ Object
Guard-clause logic the overrides above rely on: sets the parent on the wrapped instance, skipping when the parent is missing, no instance is set yet, or the instance already has a loco parent.
-
#to_s ⇒ Object
Set the loco parent again right before the slot renders.
Instance Method Details
#__vc_component_instance=(instance) ⇒ Object
Set the loco parent any time the instance changes
15 16 17 18 19 20 21 |
# File 'lib/loco_motion/patches/view_component/slot_loco_parent_patch.rb', line 15 def __vc_component_instance=(instance) # Call the original implementation super # And set the Loco parent set_loco_parent end |
#set_loco_parent(parent = @parent) ⇒ Object
Guard-clause logic the overrides above rely on: sets the parent on the wrapped instance, skipping when the parent is missing, no instance is set yet, or the instance already has a loco parent.
33 34 35 36 37 38 39 |
# File 'lib/loco_motion/patches/view_component/slot_loco_parent_patch.rb', line 33 def set_loco_parent(parent = @parent) return if parent.nil? return if @__vc_component_instance.nil? return if @__vc_component_instance.loco_parent.present? @__vc_component_instance.set_loco_parent(parent) end |
#to_s ⇒ Object
Set the loco parent again right before the slot renders.
24 25 26 27 28 |
# File 'lib/loco_motion/patches/view_component/slot_loco_parent_patch.rb', line 24 def to_s set_loco_parent super end |