Class: Glimmer::DSL::Web::ComponentExpression

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

Instance Method Summary collapse

Instance Method Details

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/glimmer/dsl/web/component_expression.rb', line 19

def add_content(parent, keyword, *args, &block)
  options = args.last.is_a?(Hash) ? args.last : {}
  slot = options[:slot] || options['slot']
  slot = slot.to_s unless slot.nil?
  # TODO consider avoiding source_location since it does not work in Opal
  if block.source_location && (block.source_location == parent.content&.__getobj__&.source_location)
    parent.content.call(parent) unless parent.content.called?
  else
    if slot
      if slot == 'markup_root_slot'
        super(parent, keyword, *args, &block)
      else
        slot_element = parent.slot_elements[slot]
        slot_element&.content(&block)
      end
    else
      if parent.default_slot
        slot = parent.default_slot
        slot_element = parent.slot_elements[slot]
        slot_element&.content(&block)
      else
        super(parent, keyword, *args, &block)
      end
    end
  end
  parent.post_add_content
end

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

Returns:

  • (Boolean)


10
11
12
# File 'lib/glimmer/dsl/web/component_expression.rb', line 10

def can_interpret?(parent, keyword, *args, &block)
  Glimmer::Web::Component.for(keyword)
end

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



14
15
16
17
# File 'lib/glimmer/dsl/web/component_expression.rb', line 14

def interpret(parent, keyword, *args, &block)
  component_class = Glimmer::Web::Component.for(keyword)
  component_class.new(parent, args, {}, &block)
end