Class: GovukComponent::TableComponent
- Defined in:
- app/components/govuk_component/table_component.rb
Defined Under Namespace
Classes: BodyComponent, CaptionComponent, CellComponent, ColGroupComponent, FootComponent, HeadComponent, RowComponent
Instance Attribute Summary collapse
-
#caption_text ⇒ Object
Returns the value of attribute caption_text.
-
#first_cell_is_header ⇒ Object
Returns the value of attribute first_cell_is_header.
-
#id ⇒ Object
Returns the value of attribute id.
Attributes inherited from Base
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(id: nil, rows: nil, head: nil, foot: nil, caption: nil, first_cell_is_header: false, classes: [], html_attributes: {}) ⇒ TableComponent
constructor
A new instance of TableComponent.
Methods inherited from Base
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 = 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, ) end |
Instance Attribute Details
#caption_text ⇒ Object
Returns the value of attribute caption_text.
10 11 12 |
# File 'app/components/govuk_component/table_component.rb', line 10 def @caption_text end |
#first_cell_is_header ⇒ Object
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 |
#id ⇒ Object
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
#call ⇒ Object
26 27 28 |
# File 'app/components/govuk_component/table_component.rb', line 26 def call tag.table(**html_attributes) { safe_join([, colgroups, head, bodies, foot]) } end |