Module: DataTable

Defined in:
lib/data-table.rb,
lib/data-table/table.rb,
lib/data-table/column.rb,
lib/data-table/version.rb

Defined Under Namespace

Classes: Column, Table

Constant Summary collapse

VERSION =
'2.0.1'.freeze

Class Method Summary collapse

Class Method Details

.default_css_stylesObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/data-table.rb', line 22

def self.default_css_styles
  <<-CSS_STYLE
    .data_table {width: 100%; empty-cells: show}
    .data_table td, .data_table th {padding: 3px}

    .data_table caption {font-size: 2em; font-weight: bold}

    .data_table thead th {background-color: #ddd; border-bottom: 1px solid #bbb;}

    .data_table tbody tr.alt {background-color: #eee;}

    .data_table .group_header th {text-align: left;}

    .data_table .subtotal.first td,
    .data_table .parent_subtotal.first td
    {
      border-top: 1px solid #000;
    }

    .data_table tfoot .total.index_0 td
    {
      border-top: 1px solid #000;
    }

    .empty_data_table {text-align: center; background-color: #ffc;}

    /* Data Types */
    .data_table .number, .data_table .money {text-align: right}
    .data_table .text {text-align: left}

    .level_1,
    .level_2 {
      text-align: left
    }

    .level_2 th {
      padding-left: 35px;
    }
  CSS_STYLE
end

.render(collection) {|t| ... } ⇒ Object

Yields:

  • (t)


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/data-table.rb', line 8

def self.render(collection, &_blk)
  # make a new table
  t = DataTable::Table.new(collection)

  # yield it to the block for configuration
  yield t

  # modify the data structure if necessary and do calculations
  t.prepare_data

  # render the table
  t.render
end