Class: Aureus::Row

Inherits:
Renderable show all
Defined in:
lib/aureus/row.rb

Instance Method Summary collapse

Methods inherited from Renderable

#compact, #compact_render, #content_tag, #init

Constructor Details

#initialize(&block) ⇒ Row

Returns a new instance of Row.



5
6
7
8
9
# File 'lib/aureus/row.rb', line 5

def initialize &block
	init_haml_helpers
	@columns = Array.new
	@content = capture_haml self, &block
end

Instance Method Details

#column(width, &block) ⇒ Object



11
12
13
# File 'lib/aureus/row.rb', line 11

def column width, &block
	@columns << RowColumn.new(width,capture_haml(&block))
end

#renderObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/aureus/row.rb', line 19

def render
	if @columns.empty?
		 "div", @content, :class => "row"
	elsif @columns.length == 1
		 "div", @columns.first.content, :class => "row"
	else
		total_width = @columns.inject 0 do |sum, n|
			sum += n.width
		end
		out = String.new.html_safe
		@columns.each_with_index do |c,i|
			left = 0.5
			right = 0.5
			width = (100.0 / total_width * c.width).round
			if i == 0
				left = 0
				width -= 0.5
			elsif i == @columns.length-1
				right = 0
				width -= 0.5
			else
				width -= 1
			end
			out +=  "div", c.content, :class => :column, :style => "width: #{width}%; margin-left: #{left}%; margin-right: #{right}%"
		end
		 "div", out, :class => "row"
	end
end

#space(width) ⇒ Object



15
16
17
# File 'lib/aureus/row.rb', line 15

def space width
	@columns << RowColumn.new(width,"")
end