Class: TableHelper::BodyRow

Inherits:
Row show all
Defined in:
lib/table_helper/body_row.rb

Overview

Represents a single row within the body of a table. The row can consist of either data cells or header cells.

Alternating rows

Alternating rows can be automated by setting the alternate property. For example,

r = BodyRow.new(object, parent)
r.alternate = true

Constant Summary collapse

@@result_class =
'ui-collection-result'
@@alternate_class =
'ui-state-alternate'

Instance Attribute Summary collapse

Attributes inherited from Row

#builder, #cells, #parent

Instance Method Summary collapse

Methods inherited from Row

#cell, #cell_names, #clear

Constructor Details

#initialize(object, parent) ⇒ BodyRow

:nodoc:



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

def initialize(object, parent) #:nodoc:
  super(parent)

  @alternate = false
  self[:class] = "#{self[:class]} #{table.object_name} #{result_class}".strip

  # For each column defined in the table, see if we can prepopulate the
  # cell based on the data in the object.  If not, we can at least
  # provide shortcut accessors to the cell
  table.header.column_names.each do |column|
    value = object.respond_to?(column) ? object.send(column) : nil
    cell(column, value)
  end
end

Instance Attribute Details

#alternateObject

True if this is an alternating row, otherwise false. Default is false.



24
25
26
# File 'lib/table_helper/body_row.rb', line 24

def alternate
  @alternate
end

Instance Method Details

#htmlObject

Generates the html for this row in additional to the border row (if specified)



43
44
45
46
47
48
49
# File 'lib/table_helper/body_row.rb', line 43

def html
  original_options = @html_options.dup
  self[:class] = "#{self[:class]} #{alternate_class}".strip if alternate
  html = super
  @html_options = original_options
  html
end