Class: TableHelper::Row

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

Overview

Represents a single row within a table. A row can consist of either data cells or header cells.

Direct Known Subclasses

BodyRow

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from HtmlElement

#html

Constructor Details

#initialize(parent) ⇒ Row

:nodoc:



65
66
67
68
69
70
71
# File 'lib/table_helper/row.rb', line 65

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

  @parent = parent
  @cells = ActiveSupport::OrderedHash.new
  @builder = RowBuilder.new(self)
end

Instance Attribute Details

#builderObject (readonly)

The proxy class used externally to build the actual cells



54
55
56
# File 'lib/table_helper/row.rb', line 54

def builder
  @builder
end

#cellsObject (readonly)

The current cells in this row, in the order in which they will be built



57
58
59
# File 'lib/table_helper/row.rb', line 57

def cells
  @cells
end

#parentObject (readonly)

The parent element for this row



60
61
62
# File 'lib/table_helper/row.rb', line 60

def parent
  @parent
end

Instance Method Details

#cell(name, *args) ⇒ Object

Creates a new cell with the given name and generates shortcut accessors for the method.



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/table_helper/row.rb', line 75

def cell(name, *args)
  name = name.to_s if name

  options = args.last.is_a?(Hash) ? args.pop : {}
  options[:namespace] = table.object_name
  args << options

  cell = Cell.new(name, *args)
  cells[name] = cell
  builder.define_cell(name) if name

  cell
end

#cell_namesObject

The names of all cells in this row



90
91
92
# File 'lib/table_helper/row.rb', line 90

def cell_names
  cells.keys
end

#clearObject

Clears all of the current cells from the row



95
96
97
98
99
# File 'lib/table_helper/row.rb', line 95

def clear
  # Remove all of the shortcut methods
  cell_names.each {|name| builder.undef_cell(name)}
  cells.clear
end