Class: TableData
- Inherits:
-
ActionView::Base
- Object
- ActionView::Base
- TableData
- Defined in:
- lib/table_data.rb
Instance Method Summary collapse
-
#initialize(label_size) ⇒ TableData
constructor
A new instance of TableData.
- #row(label, data, colspan = false) ⇒ Object
- #section(name = nil) ⇒ Object
Constructor Details
#initialize(label_size) ⇒ TableData
Returns a new instance of TableData.
5 6 7 |
# File 'lib/table_data.rb', line 5 def initialize(label_size) @label_size = label_size end |
Instance Method Details
#row(label, data, colspan = false) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/table_data.rb', line 9 def row(label, data, colspan=false) data = data.to_s.html_safe label = label.to_s.html_safe unless @set_label_size && @label_size unless colspan result = content_tag :tr do content_tag(:td, label, :class => "label", :width => @label_size) << content_tag(:td, data) end else result = content_tag :tr do content_tag(:td, content_tag(:span, label, :class => "label", :style => "display: block; float: left; width: #{@label_size}px;") << data, :colspan => 2, :width => @label_size) end end @set_label_size = true else unless colspan result = content_tag :tr do content_tag(:td, label, :class => "label") << content_tag(:td, data) end else result = content_tag :tr do content_tag(:td, content_tag(:span, label, :class => "label", :style => "display: block; float: left; width: #{@label_size}px;") << data, :colspan => 2, :width => @label_size) end end end result end |
#section(name = nil) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/table_data.rb', line 42 def section(name=nil) name = name.to_s.html_safe if name.present? content_tag :tr do content_tag :td, content_tag(:div, name, :class => "section"), :colspan => 2 end else content_tag :tr do content_tag :td, tag(:hr, :class => "section"), :colspan => 2 end end end |