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

#admin?Boolean

Returns:

  • (Boolean)


40
41
42
43
# File 'lib/table_for/table_builder.rb', line 40

def admin?
  return true unless template.respond_to?(:admin?)
  template.admin?
end

#body(*columns, &block) ⇒ Object



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

def body(*columns, &block)
  (:tbody) do
    table.row_builders.map do |builder|
      (:tr) do
        if block then capture(builder, &block) else builder.cells(*columns) end
      end
    end.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



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

def foot(&block)
  if admin?
    (: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
    end
  end.html_safe
end