Class: TableHelper::Footer

Inherits:
HtmlElement show all
Defined in:
lib/table_helper/footer.rb

Overview

Represents the header of the table. In HTML, you can think of this as the <tfoot> tag of the table.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Footer) initialize(table)

:nodoc:



19
20
21
22
23
24
25
# File 'lib/table_helper/footer.rb', line 19

def initialize(table) #:nodoc:
  super()
  
  @table = table
  @row = Row.new(self)
  @hide_when_empty = true
end

Instance Attribute Details

- (Object) hide_when_empty

Whether or not the footer should be hidden when the collection is empty. Default is true.



15
16
17
# File 'lib/table_helper/footer.rb', line 15

def hide_when_empty
  @hide_when_empty
end

- (Object) row (readonly)

The actual footer row



11
12
13
# File 'lib/table_helper/footer.rb', line 11

def row
  @row
end

- (Object) table (readonly)

The table this footer is a part of



8
9
10
# File 'lib/table_helper/footer.rb', line 8

def table
  @table
end

Instance Method Details

- (Object) html

:nodoc:



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/table_helper/footer.rb', line 27

def html #:nodoc:
  # Force the last cell to span the remaining columns
  cells = row.cells.values
  colspan = table.header.columns.length - cells[0..-2].inject(0) {|count, cell| count += (cell[:colspan] || 1).to_i}
  cells.last[:colspan] ||= colspan if colspan > 1
  
  html_options = @html_options.dup
  html_options[:style] = "display: none; #{html_options[:style]}".strip if table.empty? && hide_when_empty
  
  (tag_name, content, html_options)
end