foundation-helper 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/foundation_helper.rb +30 -9
- metadata +1 -1
data/lib/foundation_helper.rb
CHANGED
@@ -5,23 +5,39 @@ module Foundation
|
|
5
5
|
class Row
|
6
6
|
|
7
7
|
def initialize(max=12, &block)
|
8
|
-
@max, @
|
9
|
-
|
8
|
+
@max, @content = max, []
|
9
|
+
if block
|
10
|
+
content = instance_exec(self, &block)
|
11
|
+
@content << content if content != self
|
12
|
+
end
|
10
13
|
end
|
11
14
|
|
12
15
|
def col(*args, &block)
|
13
|
-
@
|
16
|
+
@content << Column.new(*args, &block)
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def <<(content)
|
21
|
+
@content << content
|
22
|
+
self
|
14
23
|
end
|
15
24
|
|
16
25
|
def render(depth=0)
|
17
|
-
|
18
|
-
|
26
|
+
columns = @content.select { |c| c.is_a? Foundation::Column }
|
27
|
+
unsized = columns.select { |c| c.width.nil? }.count
|
28
|
+
remaining = @max - columns.map(&:width).msum
|
19
29
|
width = [(remaining / unsized), 1].max unless unsized.z0?
|
20
30
|
|
21
31
|
out = " " * depth
|
22
32
|
out += "<div class='row'>\n"
|
23
|
-
@
|
24
|
-
|
33
|
+
@content.each do |content|
|
34
|
+
if content.is_a? Foundation::Column
|
35
|
+
out += content.render(depth + 1, width)
|
36
|
+
else
|
37
|
+
out += (" " * (depth + 1))
|
38
|
+
out += content.to_s
|
39
|
+
out += "\n"
|
40
|
+
end
|
25
41
|
end
|
26
42
|
out += (" " * depth)
|
27
43
|
out += "</div>\n"
|
@@ -39,13 +55,18 @@ module Foundation
|
|
39
55
|
@content, @classes, @width = [], args.select { |arg| !arg.is_a? Fixnum }, args.find{ |arg| arg.is_a? Fixnum }
|
40
56
|
if block
|
41
57
|
content = instance_exec(self, &block)
|
42
|
-
@content << content if content
|
58
|
+
@content << content if content != self
|
43
59
|
end
|
44
60
|
end
|
45
61
|
|
46
62
|
def row(max=12, &block)
|
47
63
|
@content << Row.new(max, &block)
|
48
|
-
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
def <<(content)
|
68
|
+
@content << content
|
69
|
+
self
|
49
70
|
end
|
50
71
|
|
51
72
|
def render(depth=0, w=nil)
|