Class: TableCloth::Presenters::Default

Inherits:
TableCloth::Presenter show all
Defined in:
lib/table_cloth/presenters/default.rb

Instance Attribute Summary

Attributes inherited from TableCloth::Presenter

#objects, #table, #view_context

Instance Method Summary collapse

Methods inherited from TableCloth::Presenter

#column_names, #columns, #initialize, #row_values, #rows, #wrapper_tag

Constructor Details

This class inherits a constructor from TableCloth::Presenter

Instance Method Details

#render_headerObject



36
37
38
39
40
41
42
# File 'lib/table_cloth/presenters/default.rb', line 36

def render_header
  wrapper_tag :thead do
    wrapper_tag :tr do
      v.raw column_names.inject("") {|tags, name| tags + wrapper_tag(:th, name) }
    end
  end
end

#render_row(object) ⇒ Object



16
17
18
19
20
# File 'lib/table_cloth/presenters/default.rb', line 16

def render_row(object)
  wrapper_tag :tr do
    v.raw columns.inject("") {|tds, column| tds + render_td(column, object) }
  end
end

#render_rowsObject



10
11
12
13
14
# File 'lib/table_cloth/presenters/default.rb', line 10

def render_rows
  wrapper_tag :tbody do
    v.raw objects.inject("") {|r, object| r + render_row(object) }
  end
end

#render_tableObject



4
5
6
7
8
# File 'lib/table_cloth/presenters/default.rb', line 4

def render_table
  wrapper_tag :table do
    render_header + render_rows
  end
end

#render_td(column, object) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/table_cloth/presenters/default.rb', line 22

def render_td(column, object)
  td_options = column.options[:td_options] || {}
  value = column.value(object, view_context, table)

  if value.is_a?(Array)
    options = value.pop
    value   = value.shift

    td_options.update(options)
  end

  wrapper_tag(:td, value, td_options)
end