Class: ObjectView::Table

Inherits:
Element
  • Object
show all
Defined in:
lib/object_view/table.rb

Instance Attribute Summary collapse

Attributes inherited from Element

#acceptable_children, #children, #single_line, #tag

Instance Method Summary collapse

Methods inherited from Element

#<<, #add, #add_with_tag, #attr, #attributes, #css_class=, #find_element_with_tag, #id=, #is_acceptable_child?, #on_click=, #render, #render_attributes, #render_children, #style, #style=

Constructor Details

#initializeTable

Returns a new instance of Table.


8
9
10
11
12
# File 'lib/object_view/table.rb', line 8

def initialize
  super()
  @tag = "table"
  self.acceptable_children = [TBody, THead]
end

Instance Attribute Details

#tbodyObject (readonly)

Returns the value of attribute tbody.


6
7
8
# File 'lib/object_view/table.rb', line 6

def tbody
  @tbody
end

#theadObject (readonly)

Returns the value of attribute thead.


6
7
8
# File 'lib/object_view/table.rb', line 6

def thead
  @thead
end

Instance Method Details

#header_row(labels = nil) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/object_view/table.rb', line 14

def header_row(labels = nil)
  self.add @thead = THead.new
  row = THeadRow.new
  @thead.add row
  if (labels != nil)
    labels.each do |label|
      row.cell(label)
    end
  end
  return row
end

#row(cell_data = nil, cell_attributes = nil) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/object_view/table.rb', line 26

def row(cell_data = nil, cell_attributes = nil)
  if (@tbody == nil)
    self.add @tbody = TBody.new
  end
  row = @tbody.row
  if (cell_data != nil)
    cell_data.each do |element|
      cell = row.cell(element)
      if (cell_attributes != nil)
        cell_attributes.each do |name, value|
          cell.attr(name.to_s, value)
        end
      end
    end
  end
  return row
end