foundation-helper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +4 -0
  2. data/lib/foundation_helper.rb +93 -0
  3. metadata +94 -0
@@ -0,0 +1,4 @@
1
+ foundation-helper
2
+ =================
3
+
4
+ Helper for building Foundation 3 grids
@@ -0,0 +1,93 @@
1
+ require 'mobj'
2
+
3
+ module Foundation
4
+
5
+ class Row
6
+
7
+ def initialize(max=12, &block)
8
+ @max, @cols = max, []
9
+ instance_exec(self, &block) if block
10
+ end
11
+
12
+ def col(*args, &block)
13
+ @cols << Column.new(*args, &block)
14
+ end
15
+
16
+ def render(depth=0)
17
+ unsized = @cols.select { |c| c.width.nil? }.count
18
+ remaining = @max - @cols.map(&:width).msum
19
+ width = [(remaining / unsized), 1].max unless unsized.z0?
20
+
21
+ out = " " * depth
22
+ out += "<div class='row'>\n"
23
+ @cols.each do |column|
24
+ out += column.render(depth + 1, width)
25
+ end
26
+ out += (" " * depth)
27
+ out += "</div>\n"
28
+ out
29
+ end
30
+
31
+ end
32
+
33
+ class Column
34
+
35
+ 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' }
36
+
37
+ attr_reader :width
38
+ def initialize(*args, &block)
39
+ @content, @classes, @width = [], args.select { |arg| !arg.is_a? Fixnum }, args.find{ |arg| arg.is_a? Fixnum }
40
+ if block
41
+ content = instance_exec(self, &block)
42
+ @content << content if content
43
+ end
44
+ end
45
+
46
+ def row(max=12, &block)
47
+ @content << Row.new(max, &block)
48
+ nil
49
+ end
50
+
51
+ def render(depth=0, w=nil)
52
+ out = (" " * depth)
53
+ out += "<div class='#{[WIDTHS[(width || w || 12).i!], 'columns', *@classes].join(' ')}'>\n"
54
+ @content.each do |content|
55
+ if content.is_a?(Foundation::Row)
56
+ out += content.render(depth + 1)
57
+ else
58
+ out += (" " * (depth + 1))
59
+ out += content.to_s
60
+ out += "\n"
61
+ end
62
+ end
63
+ out += (" " * depth)
64
+ out += "</div>\n"
65
+ out
66
+ end
67
+ end
68
+
69
+ class Grid
70
+
71
+ def initialize(&block)
72
+ @rows = []
73
+ instance_exec(&block) if block
74
+ end
75
+
76
+ def row(max=12, &block)
77
+ @rows << Row.new(max, &block)
78
+ end
79
+
80
+ def to_s
81
+ g = ""
82
+ @rows.each do |r|
83
+ g += r.render
84
+ end
85
+
86
+ g
87
+ end
88
+ alias_method :to_str, :to_s
89
+
90
+ end
91
+
92
+ end
93
+
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foundation-helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mason
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mobj
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: awesome_print
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Helper for building foundation 3 grids more cleanly, in ruby
63
+ email: foundation.helper@chipped.net
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - lib/foundation_helper.rb
69
+ - README.md
70
+ homepage: https://github.com/gnovos/foundation-helper
71
+ licenses: []
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.25
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Helper for building foundation 3 grids more cleanly, in ruby
94
+ test_files: []