Class: Foundation::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/foundation_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(max = 12, &block) ⇒ Row



7
8
9
10
# File 'lib/foundation_helper.rb', line 7

def initialize(max=12, &block)
  @max, @cols = max, []
  instance_exec(self, &block) if block
end

Instance Method Details

#col(*args, &block) ⇒ Object



12
13
14
# File 'lib/foundation_helper.rb', line 12

def col(*args, &block)
  @cols << Column.new(*args, &block)
end

#render(depth = 0) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/foundation_helper.rb', line 16

def render(depth=0)
  unsized = @cols.select { |c| c.width.nil? }.count
  remaining = @max - @cols.map(&:width).msum
  width = [(remaining / unsized), 1].max unless unsized.z0?

  out = "  " * depth
  out += "<div class='row'>\n"
  @cols.each do |column|
    out += column.render(depth + 1, width)
  end
  out += ("  " * depth)
  out += "</div>\n"
  out
end