Module: Tableasy::TablesHelper
- Included in:
- ActionView::Base
- Defined in:
- lib/tableasy/tables_helper.rb
Instance Method Summary collapse
- #content_row(row) ⇒ Object
- #data_list(object, *columns) ⇒ Object
- #table_for(klass, list, *columns) ⇒ Object
Instance Method Details
#content_row(row) ⇒ Object
40 41 42 43 44 |
# File 'lib/tableasy/tables_helper.rb', line 40 def content_row(row) content_tag('tr', row.html) do row.cells.collect {|cell| content_tag(cell.tag, cell.value, cell.html) }.join end end |
#data_list(object, *columns) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/tableasy/tables_helper.rb', line 27 def data_list(object, *columns) = columns. table = Table.new columns.each do |column| table.add_row([header_cell(column, object.class), Table::Cell.new(object, column)].compact) end content_tag('table', [:html]) do table.rows.collect {|row| content_row(row) }.join end end |
#table_for(klass, list, *columns) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tableasy/tables_helper.rb', line 3 def table_for(klass, list, *columns) = columns. table = Table.new # Add header row row = columns.collect {|column| header_cell(column, klass) } table.add_row(row, :header => true) list.each_with_index do |object, index| table.add_row(table_row(object, columns), :id => dom_id(object, :row), :class => "#{dom_class(object)} #{index.even? ? "odd" : "even"}") end if [:total] item = Total.new(list) = I18n.t('tableasy.total', :raise => true) rescue 'Total: ' table.add_row(table_row(item, columns[1..-1]).unshift(Table::Cell.new(item, , true)), :class => 'total-row', :total => true) end content_tag('table', [:html]) do table.rows[1..-1].each {|row| yield row } if block_given? table.rows.collect {|row| content_row(row) }.join end end |