Module: Maglove::Widgets::Columns::Helpers

Defined in:
lib/maglove/widgets/columns.rb

Instance Method Summary collapse

Instance Method Details

#column(row, &block) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/maglove/widgets/columns.rb', line 48

def column(row, &block)
  # get and increase span
  next_span = row.next_span
  if next_span
    phone_cols = row.options[:collapse_options] == "xs" ? next_span : "12"
    haml_tag :div, class: "column col-#{phone_cols} col-tablet-#{next_span} col-#{row.options[:collapse_options]}-#{next_span}" do
      yield if block
      drop_container
    end
  else
    haml_tag :pre do
      haml_concat "ERROR: Row does not allow column at position #{row.column_count}"
    end
  end
end

#columns_widget(options = {}, &block) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/maglove/widgets/columns.rb', line 64

def columns_widget(options = {}, &block)
  widget_block(Widgets::Columns.new(options)) do |widget|
    haml_tag :div, widget.row_options do
      yield(widget) if block
    end
  end
end

#columns_widget_compose(key, options = {}, &block) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/maglove/widgets/columns.rb', line 72

def columns_widget_compose(key, options = {}, &block)
  columns_widget = Widgets::Columns.new(options)
  items = variable(key, [])
  # calculate row and column count
  row_count = (items.length.to_f / columns_widget.total_columns).ceil
  col_count = columns_widget.total_columns
  (0...row_count).each do |row_index|
    columns_widget(options) do |row|
      (0...col_count).each do |col_index|
        index = (row_index * col_count) + col_index
        yield(row, items[index]) unless items[index].nil?
      end
    end
  end
end