Class: Maglev::BlockComponent

Inherits:
BaseComponent show all
Extended by:
Forwardable
Includes:
TagHelper
Defined in:
app/components/maglev/block_component.rb

Instance Attribute Summary collapse

Attributes inherited from BaseComponent

#view_context

Instance Method Summary collapse

Methods included from TagHelper

#setting_tag, #wrapper_tag

Methods inherited from BaseComponent

#build, #build_content, #build_settings_map, #settings_proxy

Constructor Details

#initialize(section:, attributes:, definition:) ⇒ BlockComponent

rubocop:disable Lint/MissingSuper



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/components/maglev/block_component.rb', line 14

def initialize(section:, attributes:, definition:)
  @section = section
  @id = attributes[:id]
  @name = attributes[:name]
  @type = attributes[:type]
  @children = children
  @definition = definition

  @settings = settings_proxy(
    build_settings_map(attributes[:settings])
  )
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



10
11
12
# File 'app/components/maglev/block_component.rb', line 10

def attributes
  @attributes
end

#childrenObject

Returns the value of attribute children.



11
12
13
# File 'app/components/maglev/block_component.rb', line 11

def children
  @children
end

#definitionObject (readonly)

Returns the value of attribute definition.



10
11
12
# File 'app/components/maglev/block_component.rb', line 10

def definition
  @definition
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'app/components/maglev/block_component.rb', line 10

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'app/components/maglev/block_component.rb', line 10

def name
  @name
end

#sectionObject (readonly)

Returns the value of attribute section.



10
11
12
# File 'app/components/maglev/block_component.rb', line 10

def section
  @section
end

#settingsObject (readonly)

Returns the value of attribute settings.



10
11
12
# File 'app/components/maglev/block_component.rb', line 10

def settings
  @settings
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'app/components/maglev/block_component.rb', line 10

def type
  @type
end

Instance Method Details

#children?Boolean

rubocop:enable Lint/MissingSuper

Returns:

  • (Boolean)


28
29
30
# File 'app/components/maglev/block_component.rb', line 28

def children?
  children.present?
end

#dom_dataObject

rubocop:disable Rails/OutputSafety



37
38
39
# File 'app/components/maglev/block_component.rb', line 37

def dom_data
  "data-maglev-block-id=\"#{id}\"".html_safe
end

#dom_idObject



32
33
34
# File 'app/components/maglev/block_component.rb', line 32

def dom_id
  "block-#{id}"
end

#tag_dataObject

rubocop:enable Rails/OutputSafety



42
43
44
# File 'app/components/maglev/block_component.rb', line 42

def tag_data
  { maglev_block_id: id }
end