Class: Tablemaker::TableHelper
- Inherits:
-
Object
- Object
- Tablemaker::TableHelper
- Defined in:
- lib/tablemaker/table_helper.rb
Instance Method Summary collapse
- #column(&block) ⇒ Object
-
#initialize(context, &block) ⇒ TableHelper
constructor
A new instance of TableHelper.
- #line(&block) ⇒ Object
- #row(&block) ⇒ Object
- #td(*args, &blk) ⇒ Object
- #th(*args, &blk) ⇒ Object
- #to_html(attrs = {}) ⇒ Object
Constructor Details
#initialize(context, &block) ⇒ TableHelper
Returns a new instance of TableHelper.
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/tablemaker/table_helper.rb', line 3 def initialize(context, &block) @context = context @stack = [] @root = Tablemaker.column do |r| stack(r) do yield self end end end |
Instance Method Details
#column(&block) ⇒ Object
22 23 24 25 26 |
# File 'lib/tablemaker/table_helper.rb', line 22 def column(&block) current.column do |c| stack(c, &block) end end |
#line(&block) ⇒ Object
28 29 30 |
# File 'lib/tablemaker/table_helper.rb', line 28 def line(&block) current.respond_to?(:row) ? row(&block) : column(&block) end |
#row(&block) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/tablemaker/table_helper.rb', line 14 def row(&block) current.row do |r| stack(r) do yield end end end |
#td(*args, &blk) ⇒ Object
32 33 34 |
# File 'lib/tablemaker/table_helper.rb', line 32 def td(*args, &blk) cell("td", *args, &blk) end |
#th(*args, &blk) ⇒ Object
36 37 38 |
# File 'lib/tablemaker/table_helper.rb', line 36 def th(*args, &blk) cell("th", *args, &blk) end |
#to_html(attrs = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/tablemaker/table_helper.rb', line 40 def to_html(attrs = {}) context.content_tag("table", attrs) do @root.each_row do |r| s = context.content_tag("tr") do r.each do |c| attrs = {} attrs[:rowspan] = c.real_rows if c.real_rows > 1 attrs[:colspan] = c.real_cols if c.real_cols > 1 s2 = context.content_tag(c.data[:name], c.data[:opts].merge(attrs)) do c.data[:text] end context.concat(s2) end end context.concat(s) end end end |