Class: Card::Set::All::Bootstrap::Table::TableHelper
- Defined in:
- platypus/tmp/set/gem-defaults/mod024-bootstrap/all/bootstrap/table.rb
Overview
support class for bootstrap tables
Instance Method Summary collapse
-
#body ⇒ Object
-
#cell(cell) ⇒ Object
-
#header ⇒ Object
-
#initialize(format, content, opts = {}) ⇒ TableHelper
constructor
A new instance of TableHelper.
-
#render ⇒ Object
-
#row(row) ⇒ Object
-
#tag(elem, *args, &block) ⇒ Object
Constructor Details
#initialize(format, content, opts = {}) ⇒ TableHelper
Returns a new instance of TableHelper.
22 23 24 25 26 27 28 29 |
# File 'platypus/tmp/set/gem-defaults/mod024-bootstrap/all/bootstrap/table.rb', line 22 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
#body ⇒ Object
49 50 51 52 53 54 55 |
# File 'platypus/tmp/set/gem-defaults/mod024-bootstrap/all/bootstrap/table.rb', line 49 def body tag :tbody do @rows.map do |row_content| row row_content end.join "\n" end end |
#cell(cell) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'platypus/tmp/set/gem-defaults/mod024-bootstrap/all/bootstrap/table.rb', line 74 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 |
#header ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'platypus/tmp/set/gem-defaults/mod024-bootstrap/all/bootstrap/table.rb', line 37 def header return unless @header tag :thead do tag :tr do @header.map do |item| tag(:th) { item } end.join "\n" end end end |
#render ⇒ Object
31 32 33 34 35 |
# File 'platypus/tmp/set/gem-defaults/mod024-bootstrap/all/bootstrap/table.rb', line 31 def render tag :table, class: @opts[:class] do [header, body] end end |
#row(row) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'platypus/tmp/set/gem-defaults/mod024-bootstrap/all/bootstrap/table.rb', line 57 def row row row_data, row_class = case row when Hash [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
87 88 89 90 91 92 93 |
# File 'platypus/tmp/set/gem-defaults/mod024-bootstrap/all/bootstrap/table.rb', line 87 def tag elem, *args, &block if @div_table add_div_table_class elem, *args elem = :div end @format.wrap_with elem, *args, &block end |