Class: TableFor::TableBuilder

Inherits:
Struct
  • Object
show all
Defined in:
lib/table_for/table_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tableObject

Returns the value of attribute table

Returns:

  • (Object)

    the current value of table



2
3
4
# File 'lib/table_for/table_builder.rb', line 2

def table
  @table
end

Instance Method Details

#body(*columns, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/table_for/table_builder.rb', line 20

def body(*columns, &block)
  (:tbody) do
    table.row_builders.map do |builder|
      if TableFor.row_filter.call(table, builder.record)
        (:tr) do
          if block then capture(builder, &block) else builder.cells(*columns) end
        end
      end
    end.compact.join.html_safe
  end
end

#columns(*columns) ⇒ Object



6
7
8
# File 'lib/table_for/table_builder.rb', line 6

def columns(*columns)
  head(*columns) + body(*columns)
end

#foot(&block) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/table_for/table_builder.rb', line 32

def foot(&block)
  if TableFor.footer_filter.call(table)
    (:tfoot) do
      (:tr) do
        (:td, capture(&block), :colspan => table.columns.size)
      end
    end.html_safe
  end
end

#head(*columns) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/table_for/table_builder.rb', line 10

def head(*columns)
  table.columns = columns

  (:thead) do
    (:tr) do
      human_column_names.map { |column| (:th, column) }.join.html_safe
    end
  end
end