Class: Monolith::Components::Table
- Defined in:
- app/components/monolith/table.rb
Instance Method Summary collapse
-
#initialize(collection) ⇒ Table
constructor
A new instance of Table.
- #row(header, &row) ⇒ Object
- #view_template ⇒ Object
Constructor Details
#initialize(collection) ⇒ Table
Returns a new instance of Table.
2 3 4 5 |
# File 'app/components/monolith/table.rb', line 2 def initialize(collection) @collection = collection @columns = [] end |
Instance Method Details
#row(header, &row) ⇒ Object
7 8 9 |
# File 'app/components/monolith/table.rb', line 7 def row(header, &row) @columns << [ header, row ] end |
#view_template ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/components/monolith/table.rb', line 11 def view_template(&) vanish(&) headers, rows = @columns.transpose div(class: "overflow-x-auto") do table class: "table" do thead do tr do headers.each do |header| th { header } end end end tbody do @collection.each do |item| tr do rows.each do |cell| td { cell.call item } end end end end end end end |