Class: CustomElementsManifestParser::Structs::CustomElementLikeStruct

Inherits:
BaseStruct
  • Object
show all
Includes:
Structs::ClassLikeStruct
Defined in:
lib/custom_elements_manifest_parser/structs/custom_element_like_struct.rb

Overview

The additional fields that a custom element adds to classes and mixins.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#attributesArray<Attribute>?

Returns - The attributes that this element is known to understand.

Returns:

  • (Array<Attribute>, nil)
    • The attributes that this element is known to understand.


26
# File 'lib/custom_elements_manifest_parser/structs/custom_element_like_struct.rb', line 26

attribute :attributes, Types::Strict::Array.optional.meta(required: false)

#cssPartsArray<CssPart>?

Returns - Array of CSS Parts.

Returns:

  • (Array<CssPart>, nil)
    • Array of CSS Parts


37
# File 'lib/custom_elements_manifest_parser/structs/custom_element_like_struct.rb', line 37

attribute :cssParts, Types::Strict::Array.optional.meta(required: false)

#cssPropertiesArray<CssCustomProperty>?

Returns:

  • (Array<CssCustomProperty>, nil)


33
# File 'lib/custom_elements_manifest_parser/structs/custom_element_like_struct.rb', line 33

attribute :cssProperties, Types::Strict::Array.optional.meta(required: false)

#customElementTrue

Returns - Distinguishes a regular JavaScript class from a custom element class.

Returns:

  • (True)
    • Distinguishes a regular JavaScript class from a custom element class


13
# File 'lib/custom_elements_manifest_parser/structs/custom_element_like_struct.rb', line 13

attribute :customElement, Types::Strict::True.optional.meta(required: false)

#eventsArray<Event>?

Returns - The events that this element fires.

Returns:

  • (Array<Event>, nil)
    • The events that this element fires.


45
# File 'lib/custom_elements_manifest_parser/structs/custom_element_like_struct.rb', line 45

attribute :events, Types::Strict::Array.optional.meta(required: false)

#slotsArray<Slot>?

Returns - The shadow dom content slots that this element accepts.

Returns:

  • (Array<Slot>, nil)
    • The shadow dom content slots that this element accepts.


41
# File 'lib/custom_elements_manifest_parser/structs/custom_element_like_struct.rb', line 41

attribute :slots, Types::Strict::Array.optional.meta(required: false)

#tagNameString?

Returns - An optional tag name that should be specified if this is a self-registering element.

Self-registering elements must also include a CustomElementExport in the module's exports.

Returns:

  • (String, nil)

    - An optional tag name that should be specified if this is a self-registering element.

    Self-registering elements must also include a CustomElementExport in the module's exports.



22
# File 'lib/custom_elements_manifest_parser/structs/custom_element_like_struct.rb', line 22

attribute :tagName, Types::Strict::String.optional.meta(required: false)

Class Method Details

.build_hash(parser:, struct:) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/custom_elements_manifest_parser/structs/custom_element_like_struct.rb', line 47

def self.build_hash(parser:, struct:)
  hash = {}

  # This is a special case because DryStruct reserves the `attributes` namespace.
  hash[:attributes] = struct.attributes[:attributes].map { |attr| parser.data_types[:attribute].new(attr).visit(parser: parser) } unless struct.attributes[:attributes].nil?

  hash[:cssProperties] = struct.cssProperties.map { |css_custom_property| parser.data_types[:css_custom_property].new(css_custom_property).visit(parser: parser) } unless struct.cssProperties.nil?

  hash[:cssParts] = struct.cssParts.map { |css_part| parser.data_types[:css_part].new(css_part).visit(parser: parser) } unless struct.cssParts.nil?
  hash[:demos] = struct.demos.map { |demo| parser.data_types[:demo].new(demo).visit(parser: parser) } unless struct.demos.nil?
  hash[:slots] = struct.slots.map { |slot| parser.data_types[:slot].new(slot).visit(parser: parser) } unless struct.slots.nil?
  hash[:events] = struct.events.map { |event| parser.data_types[:event].new(event).visit(parser: parser) } unless struct.events.nil?

  hash = hash.merge(ClassLikeStruct.build_hash(parser: parser, struct: struct))
  hash
end