Class: Katalyst::SummaryTableComponent
- Inherits:
-
TableComponent
- Object
- ViewComponent::Base
- TableComponent
- Katalyst::SummaryTableComponent
- Defined in:
- app/components/katalyst/summary_table_component.rb
Overview
A component for rendering a summary table for a model. Generates:
<table>
<tr><th>Name</th><td><a href="/people/1">Aaron</a></td></tr>
<tr><th>Email</th><td>[email protected]</td></tr>
</table>
Instance Attribute Summary
Attributes inherited from TableComponent
Instance Method Summary collapse
-
#initialize(model:) ⇒ SummaryTableComponent
constructor
A new instance of SummaryTableComponent.
- #with_cell(cell) ⇒ Object
Methods inherited from TableComponent
#before_render, #boolean, #currency, #date, #datetime, #enum, #html_attributes=, #inspect, #number, #record, #rich_text, #row, #text
Methods included from Tables::HasTableContent
Constructor Details
#initialize(model:) ⇒ SummaryTableComponent
Returns a new instance of SummaryTableComponent.
20 21 22 23 24 25 26 |
# File 'app/components/katalyst/summary_table_component.rb', line 20 def initialize(model:, **) super(collection: [model], **) @summary_rows = [] update_html_attributes(class: "summary-table") end |
Instance Method Details
#with_cell(cell) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/components/katalyst/summary_table_component.rb', line 28 def with_cell(cell, &) if row.header? @summary_rows << with_summary_row do |row| row.with_header do |header| header.with_cell(cell) end end @index = 0 else @summary_rows[@index].with_body do |body| body.with_cell(cell, &) end @index += 1 end end |