Class: Emjay::Components::MjAttributes

Inherits:
HeadComponent show all
Defined in:
lib/emjay/components/head/mj_attributes.rb

Instance Attribute Summary

Attributes inherited from Emjay::Component

#attributes, #context, #props

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HeadComponent

#handler_children

Methods inherited from Emjay::Component

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

Constructor Details

This class inherits a constructor from Emjay::Component

Class Method Details

.component_nameObject



9
10
11
# File 'lib/emjay/components/head/mj_attributes.rb', line 9

def self.component_name
  "mj-attributes"
end

Instance Method Details

#handlerObject



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

def handler
  add = @context[:add]
  children = @props[:children] || []

  children.each do |child|
    tag_name = child[:tag_name]
    attributes = child[:attributes] || {}
    child_children = child[:children] || []

    if tag_name == "mj-class"
      name = attributes["name"]
      add.call(:classes, name, attributes.except("name"))
      add.call(:classes_default, name,
        child_children.each_with_object({}) { |cc, acc|
          acc[cc[:tag_name]] = cc[:attributes] || {}
        })
    else
      add.call(:default_attributes, tag_name, attributes)
    end
  end
end