Class: Foundation::Column

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Column

Returns a new instance of Column.



52
53
54
55
56
57
58
# File 'lib/foundation_helper.rb', line 52

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 != self
  end
end

Instance Attribute Details

#widthObject (readonly)

Returns the value of attribute width.



51
52
53
# File 'lib/foundation_helper.rb', line 51

def width
  @width
end

Instance Method Details

#<<(content) ⇒ Object



65
66
67
68
# File 'lib/foundation_helper.rb', line 65

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

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



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/foundation_helper.rb', line 70

def render(depth=0, w=nil)
  out = ("  " * depth)
  wval = (width || w || 12).i!
  out += "<div class='#{["small-#{wval} large-#{wval}", '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(*args, &block) ⇒ Object



60
61
62
63
# File 'lib/foundation_helper.rb', line 60

def row(*args, &block)
  @content << Row.new(*args, &block)
  self
end