Class: Foundation::Column

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

Constant Summary collapse

WIDTHS =
{ 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six', 7 => 'seven', 8 => 'eight', 9 => 'nine', 10 => 'ten', 11 => 'eleven', 12 => 'twelve' }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Column



38
39
40
41
42
43
44
# File 'lib/foundation_helper.rb', line 38

def initialize(*args, &block)
  @content, @classes, @width = [], args.select { |arg| !arg.is_a? Fixnum }, args.find{ |arg| arg.is_a? Fixnum }
  if block
    content = instance_exec(self, &block)
    @content << content if content
  end
end

Instance Attribute Details

#widthObject (readonly)

Returns the value of attribute width.



37
38
39
# File 'lib/foundation_helper.rb', line 37

def width
  @width
end

Instance Method Details

#render(depth = 0, w = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/foundation_helper.rb', line 51

def render(depth=0, w=nil)
  out = ("  " * depth)
  out += "<div class='#{[WIDTHS[(width || w || 12).i!], 'columns', *@classes].join(' ')}'>\n"
  @content.each do |content|
    if content.is_a?(Foundation::Row)
      out += content.render(depth + 1)
    else
      out += ("  " * (depth + 1))
      out += content.to_s
      out += "\n"
    end
  end
  out += ("  " * depth)
  out += "</div>\n"
  out
end

#row(max = 12, &block) ⇒ Object



46
47
48
49
# File 'lib/foundation_helper.rb', line 46

def row(max=12, &block)
  @content << Row.new(max, &block)
  nil
end