foundation-helper 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/foundation_helper.rb +30 -9
  2. metadata +1 -1
@@ -5,23 +5,39 @@ module Foundation
5
5
  class Row
6
6
 
7
7
  def initialize(max=12, &block)
8
- @max, @cols = max, []
9
- instance_exec(self, &block) if block
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
- @cols << Column.new(*args, &block)
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
- unsized = @cols.select { |c| c.width.nil? }.count
18
- remaining = @max - @cols.map(&:width).msum
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
- @cols.each do |column|
24
- out += column.render(depth + 1, width)
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
- nil
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foundation-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: