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

Returns a new instance of Row.



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

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

Instance Method Details

#<<(content) ⇒ Object



20
21
22
23
# File 'lib/foundation_helper.rb', line 20

def <<(content)
  @content << content
  self
end

#col(*args, &block) ⇒ Object



15
16
17
18
# File 'lib/foundation_helper.rb', line 15

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

#render(depth = 0) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/foundation_helper.rb', line 25

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

  out = "  " * depth
  out += "<div class='row'>\n"
  @content.each do |content|
    if content.is_a? Foundation::Column
      out += content.render(depth + 1, width)
    else
      out += ("  " * (depth + 1))
      out += content.to_s
      out += "\n"
    end
  end
  out += ("  " * depth)
  out += "</div>\n"
  out
end