Class: GovukComponent::TableComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/govuk_component/table_component.rb

Defined Under Namespace

Classes: BodyComponent, CaptionComponent, CellComponent, ColGroupComponent, FootComponent, HeadComponent, RowComponent

Instance Attribute Summary collapse

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Methods inherited from Base

#brand, #class_prefix

Constructor Details

#initialize(id: nil, rows: nil, head: nil, foot: nil, caption: nil, first_cell_is_header: false, classes: [], html_attributes: {}) ⇒ TableComponent

Returns a new instance of TableComponent.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/components/govuk_component/table_component.rb', line 12

def initialize(id: nil, rows: nil, head: nil, foot: nil, caption: nil, first_cell_is_header: false, classes: [], html_attributes: {})
  @id                   = id
  @first_cell_is_header = first_cell_is_header
  @caption_text         = caption

  super(classes:, html_attributes:)

  # when no rows are passed in it's likely we're taking the slot approach
  return unless rows.presence

  # if no head is passed in,use the first row for headers
  build(*(head ? [head, rows] : [rows[0], rows[1..]]), foot, caption_text)
end

Instance Attribute Details

#caption_textObject

Returns the value of attribute caption_text.



10
11
12
# File 'app/components/govuk_component/table_component.rb', line 10

def caption_text
  @caption_text
end

#first_cell_is_headerObject

Returns the value of attribute first_cell_is_header.



10
11
12
# File 'app/components/govuk_component/table_component.rb', line 10

def first_cell_is_header
  @first_cell_is_header
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'app/components/govuk_component/table_component.rb', line 10

def id
  @id
end

Instance Method Details

#callObject



26
27
28
# File 'app/components/govuk_component/table_component.rb', line 26

def call
  tag.table(**html_attributes) { safe_join([caption, colgroups, head, bodies, foot]) }
end