Class: Maglove::Widgets::Columns

Inherits:
Base
  • Object
show all
Defined in:
lib/maglove/widgets/columns.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#options, #scope

Instance Method Summary collapse

Methods inherited from Base

#widget_options

Constructor Details

#initialize(options, scope) ⇒ Columns

Returns a new instance of Columns.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/maglove/widgets/columns.rb', line 8

def initialize(options, scope)
  super(options, scope)
  @column_count = 0
  column_array = @options[:columns].to_s.split("x")
  if column_array.length == 1
    @total_columns = column_array[0].to_i
    @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.



5
6
7
# File 'lib/maglove/widgets/columns.rb', line 5

def column_count
  @column_count
end

#columnsObject (readonly)

Returns the value of attribute columns.



4
5
6
# File 'lib/maglove/widgets/columns.rb', line 4

def columns
  @columns
end

#total_columnsObject (readonly)

Returns the value of attribute total_columns.



6
7
8
# File 'lib/maglove/widgets/columns.rb', line 6

def total_columns
  @total_columns
end

Instance Method Details

#column(&block) ⇒ Object



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

def column(&block)
  span = next_span
  if span
    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 if block
      drop_container
    end
  else
    haml_tag :pre do
      haml_concat "ERROR: Row does not allow column at position #{column_count}"
    end
  end
end

#defaultsObject



37
38
39
40
41
42
43
# File 'lib/maglove/widgets/columns.rb', line 37

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

#identifierObject



33
34
35
# File 'lib/maglove/widgets/columns.rb', line 33

def identifier
  "columns"
end

#next_spanObject



21
22
23
24
25
# File 'lib/maglove/widgets/columns.rb', line 21

def next_span
  value = @columns[@column_count]
  @column_count += 1
  value
end

#row_optionsObject



27
28
29
30
31
# File 'lib/maglove/widgets/columns.rb', line 27

def row_options
  {
    class: "row row-#{@options[:style]}"
  }
end

#template(&block) ⇒ Object



45
46
47
48
49
# File 'lib/maglove/widgets/columns.rb', line 45

def template(&block)
  haml_tag :div, row_options do
    yield(self) if block
  end
end