Module: Tableasy::TablesHelper

Included in:
ActionView::Base
Defined in:
lib/tableasy/tables_helper.rb

Instance Method Summary collapse

Instance Method Details

#content_row(row) ⇒ Object



40
41
42
43
44
# File 'lib/tableasy/tables_helper.rb', line 40

def content_row(row)
  ('tr', row.html) do
    row.cells.collect {|cell| (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)
  options = columns.extract_options!
  table = Table.new

  columns.each do |column|
    table.add_row([header_cell(column, object.class), Table::Cell.new(object, column)].compact)
  end

  ('table', options[: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)
  options = columns.extract_options!

  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 options[:total]
    item = Total.new(list)
    caption = I18n.t('tableasy.total', :raise => true) rescue 'Total: '
    table.add_row(table_row(item, columns[1..-1]).unshift(Table::Cell.new(item, caption, true)), :class => 'total-row', :total => true)
  end

  ('table', options[:html]) do
    table.rows[1..-1].each {|row| yield row } if block_given?
    table.rows.collect {|row| content_row(row) }.join
  end
end