Class: Glimmer::DSL::Web::ComponentSlotContentExpression

Inherits:
Expression
  • Object
show all
Defined in:
lib/glimmer/dsl/web/component_slot_content_expression.rb

Instance Method Summary collapse

Instance Method Details

#can_interpret?(parent, keyword, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
# File 'lib/glimmer/dsl/web/component_slot_content_expression.rb', line 30

def can_interpret?(parent, keyword, *args, &block)
  component = parent.is_a?(Glimmer::Web::Component) ? parent : parent&.ancestor_component
  slot = keyword.to_s
  block_given? &&
    !component.nil? &&
    (
      component.slot_elements.keys.include?(slot) ||
      component.slot_elements.keys.include?(slot.to_sym)
    )
end

#interpret(parent, keyword, *args, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/glimmer/dsl/web/component_slot_content_expression.rb', line 41

def interpret(parent, keyword, *args, &block)
  slot = keyword.to_s
  component = parent.is_a?(Glimmer::Web::Component) ? parent : parent.ancestor_component
  if slot == 'markup_root_slot'
    component.content(slot: slot.to_sym, &block)
  else
    slot_element = component.slot_elements[slot] || component.slot_elements[slot.to_sym]
    slot_element.content(&block)
  end
end