Class: Emjay::HeadComponent

Inherits:
Component show all
Defined in:
lib/emjay/head_component.rb

Overview

Base class for head components. Port of JS HeadComponent from createComponent.js.

Instance Attribute Summary

Attributes inherited from Component

#attributes, #context, #props

Instance Method Summary collapse

Methods inherited from Component

allowed_attributes, component_name, default_attributes, ending_tag?, #get_attribute, #get_child_context, #get_content, #initialize, raw_element?

Constructor Details

This class inherits a constructor from Emjay::Component

Instance Method Details

#handlerObject



8
9
10
# File 'lib/emjay/head_component.rb', line 8

def handler
  # Subclasses override
end

#handler_childrenObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/emjay/head_component.rb', line 12

def handler_children
  children = @props[:children] || []
  components = @context[:components] || {}

  children.filter_map do |child|
    component_class = components[child[:tag_name]]

    unless component_class
      warn "No matching component for tag: #{child[:tag_name]}"
      next
    end

    component = component_class.new(
      attributes: child[:attributes] || {},
      children: child[:children] || [],
      content: child[:content] || "",
      context: get_child_context
    )

    component.handler if component.respond_to?(:handler)

    component.render if component.respond_to?(:render)
  end
end