Module: ColumnPack::ViewHelpers
- Defined in:
- lib/column_pack/view_helpers.rb
Instance Method Summary collapse
-
#pack_element(height, content = nil, &block) ⇒ Object
Packs a single element with a given height into a column.
-
#pack_in_columns(total_columns, options = {}) ⇒ Object
Packs content into columns.
Instance Method Details
#pack_element(height, content = nil, &block) ⇒ Object
Packs a single element with a given height into a column.
pack_element should be called withing pack_in_columns’s block:
pack_in_columns(3) do
pack_element(100) do
"A"
end
end
Accepts parameter strings or block content (ERB, strings, etc).
40 41 42 43 44 45 46 47 48 |
# File 'lib/column_pack/view_helpers.rb', line 40 def pack_element(height, content = nil, &block) return if @column_packer.nil? if block_given? @column_packer.add(height.to_i, capture(&block)) else @column_packer.add(height.to_i, content) end end |
#pack_in_columns(total_columns, options = {}) ⇒ Object
Packs content into columns.
pack_in_columns expect a block to be passed:
pack_in_columns(3) do
pack_element(100) do
"A"
end
end
Options: :algorithm specify a different bin packing algorithm (default :best_fit_decreasing)
available algorithms are :best_fit_decreasing, :best_fit_increasing
:shuffle_in_col after packing columns, shuffle the elements in each column (defaults to true)
20 21 22 23 24 25 26 |
# File 'lib/column_pack/view_helpers.rb', line 20 def pack_in_columns(total_columns, = {}) @column_packer = ColumnPacker.new(total_columns, ) yield @column_packer.render end |