Class: Card::Set::All::Bootstrap::Table::HtmlFormat::TableHelper

Inherits:
Object
  • Object
show all
Defined in:
platypus/tmp/set/gem-defaults/mod024-bootstrap/all/bootstrap/table.rb

Instance Method Summary collapse

Constructor Details

#initialize(format, content, opts = {}) ⇒ TableHelper

Returns a new instance of TableHelper.



10
11
12
13
14
15
16
17
# File 'platypus/tmp/set/gem-defaults/mod024-bootstrap/all/bootstrap/table.rb', line 10

def initialize format, content, opts={}
  @format = format
  @div_table = opts.delete :div_table
  @header = initialize_header opts[:header], content
  @rows = content
  @opts = opts
  @format.add_class opts, :table
end

Instance Method Details

#bodyObject



37
38
39
40
41
42
43
# File 'platypus/tmp/set/gem-defaults/mod024-bootstrap/all/bootstrap/table.rb', line 37

def body
  tag :tbody do
    @rows.map do |row_content|
      row row_content
    end.join "\n"
  end
end

#cell(cell) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'platypus/tmp/set/gem-defaults/mod024-bootstrap/all/bootstrap/table.rb', line 62

def cell cell
  if cell.is_a? Hash
    content = cell.delete(:content).to_s
    tag :td, cell do
      content
    end
  else
    tag :td do
      String(cell)
    end
  end
end

#headerObject



25
26
27
28
29
30
31
32
33
34
35
# File 'platypus/tmp/set/gem-defaults/mod024-bootstrap/all/bootstrap/table.rb', line 25

def header
  return unless @header

  tag :thead do
    tag :tr do
      @header.map do |item|
        tag(:th) { item }
      end.join "\n"
    end
  end
end

#renderObject



19
20
21
22
23
# File 'platypus/tmp/set/gem-defaults/mod024-bootstrap/all/bootstrap/table.rb', line 19

def render
  tag :table, class: @opts[:class] do
    [header, body]
  end
end

#row(row) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'platypus/tmp/set/gem-defaults/mod024-bootstrap/all/bootstrap/table.rb', line 45

def row row
  row_data, row_class =
    case row
    when Hash then
      [row.delete(:content), row]
    else
      [row, {}]
    end
  row_content =
    if row_data.is_a?(Array)
      row_data.map { |item| cell item }.join "\n"
    else
      row_data
    end
  tag :tr, row_content, row_class
end

#tag(elem, *args, &block) ⇒ Object



75
76
77
78
79
80
81
# File 'platypus/tmp/set/gem-defaults/mod024-bootstrap/all/bootstrap/table.rb', line 75

def tag elem, *args, &block
  if @div_table
    add_div_table_class elem, *args
    elem = :div
  end
  @format.wrap_with elem, *args, &block
end