Class: ColumnPack::ColumnPacker

Inherits:
Object
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper
Defined in:
lib/column_pack/column_packer.rb

Overview

Arranges HTML elements into a fixed number of columns.

Instance Method Summary collapse

Constructor Details

#initialize(total_columns, options = {}) ⇒ ColumnPacker

Uses a fixed number of columns (total_columns).

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)



16
17
18
# File 'lib/column_pack/column_packer.rb', line 16

def initialize(total_columns, options = {})
  @bin_packer = BinPacker.new(total_columns, options)
end

Instance Method Details

#add(height, content) ⇒ Object



20
21
22
# File 'lib/column_pack/column_packer.rb', line 20

def add(height, content)
  @bin_packer.add(height.to_i, content)
end

#renderObject

Renders all elements into columns.



25
26
27
# File 'lib/column_pack/column_packer.rb', line 25

def render
  wrap(@bin_packer.bins).html_safe
end