Class: EasyTable::TableBuilder
- Inherits:
-
Object
- Object
- EasyTable::TableBuilder
- Includes:
- Components::Columns, Components::Spans
- Defined in:
- lib/easy_table/table_builder.rb
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(collection, template, options) ⇒ TableBuilder
constructor
A new instance of TableBuilder.
Methods included from Components::Spans
Methods included from Components::Columns
Constructor Details
#initialize(collection, template, options) ⇒ TableBuilder
Returns a new instance of TableBuilder.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/easy_table/table_builder.rb', line 9 def initialize(collection, template, ) @collection = collection @options = tr_opts = @options.select { |k, _v| k =~ /^tr_.*/ } tr_opts.each { |k, _v| @options.delete(k) } @tr_opts = tr_opts.inject({}) do |h, e| k, v = *e h[k[3..-1]] = v h end @template = template @node = Tree::TreeNode.new('root') end |
Instance Method Details
#build ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/easy_table/table_builder.rb', line 24 def build content_tag(:table, @options) do concat(content_tag(:thead) do thead end) concat(content_tag(:tbody) do @collection.each do |record| concat(content_tag(:tr, tr_opts(record)) do node.each_leaf do |leaf| leaf.content.td(record) end end) end end) end end |