Class: Maglove::Widget::LegacyColumns

Inherits:
V1
  • Object
show all
Defined in:
lib/maglove/widget/columns.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#options, #scope

Instance Method Summary collapse

Methods inherited from V1

#drop_container, #widget_options

Methods inherited from Base

#style_string, #widget_options

Constructor Details

#initialize(scope, options = {}) ⇒ LegacyColumns

Returns a new instance of LegacyColumns.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/maglove/widget/columns.rb', line 25

def initialize(scope, options = {})
  super
  @column_count = 0
  column_array = @options[:columns].to_s.split("x").map(&:to_i)
  if column_array.length == 1
    @total_columns = column_array[0]
    @columns = Array.new(@total_columns) { 12 / @total_columns }
  else
    @total_columns = column_array.length
    @columns = column_array
  end
end

Instance Attribute Details

#column_countObject (readonly)

Returns the value of attribute column_count.



22
23
24
# File 'lib/maglove/widget/columns.rb', line 22

def column_count
  @column_count
end

#columnsObject (readonly)

Returns the value of attribute columns.



21
22
23
# File 'lib/maglove/widget/columns.rb', line 21

def columns
  @columns
end

#total_columnsObject (readonly)

Returns the value of attribute total_columns.



23
24
25
# File 'lib/maglove/widget/columns.rb', line 23

def total_columns
  @total_columns
end

Instance Method Details

#column(&block) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/maglove/widget/columns.rb', line 59

def column(&block)
  span = columns[column_count]
  raise "ERROR: Row does not allow column at position #{column_count}" unless span
  @column_count += 1
  phone_cols = (options[:collapse_options] == "xs") ? span : "12"
  haml_tag :div, class: "column col-#{phone_cols} col-tablet-#{span} col-#{options[:collapse_options]}-#{span}" do
    yield self if block_given?
    drop_container
  end
end

#defaultsObject



42
43
44
45
46
47
48
49
# File 'lib/maglove/widget/columns.rb', line 42

def defaults
  {
    columns: "2",
    style: "default",
    margin_bottom: "",
    collapse_options: "sm"
  }
end

#identifierObject



38
39
40
# File 'lib/maglove/widget/columns.rb', line 38

def identifier
  "columns"
end

#render(&block) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/maglove/widget/columns.rb', line 51

def render(&block)
  super do
    haml_tag :div, row_options do
      yield self if block_given?
    end
  end
end