css_grid 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- css_grid (0.0.2)
4
+ css_grid (1.0.0)
5
5
  hash_extend
6
6
  railties (>= 3.1.0)
7
7
 
@@ -24,11 +24,11 @@ GEM
24
24
  activesupport (3.2.8)
25
25
  i18n (~> 0.6)
26
26
  multi_json (~> 1.0)
27
- builder (3.0.0)
27
+ builder (3.0.3)
28
28
  erubis (2.7.0)
29
29
  hash_extend (1.0.1)
30
30
  hike (1.2.1)
31
- i18n (0.6.0)
31
+ i18n (0.6.1)
32
32
  journey (1.0.4)
33
33
  json (1.7.5)
34
34
  multi_json (1.3.6)
@@ -37,7 +37,7 @@ GEM
37
37
  rack (>= 0.4)
38
38
  rack-ssl (1.3.2)
39
39
  rack
40
- rack-test (0.6.1)
40
+ rack-test (0.6.2)
41
41
  rack (>= 1.0)
42
42
  railties (3.2.8)
43
43
  actionpack (= 3.2.8)
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # CssGrid
2
2
 
3
- In Dev Gem, please, come back later.
3
+ This Gem allow you to use a css grid, and provide several helpers.
4
+
5
+ __Grid__ is a 12 column alignment system, based on 1140px width. That fit for 1280*720 screens. This is responsive design and adapt for smaller screens, and mobile screens.
6
+
7
+ __Helpers__ facilitate the use of the grid syntax, to produce correct html markdown. This allow you to pass collections and block, and map the result to insert it into correct html tags.
4
8
 
5
9
  ## Installation
6
10
 
@@ -16,9 +20,269 @@ Or install it yourself as:
16
20
 
17
21
  $ gem install css_grid
18
22
 
23
+ ## Use
24
+
25
+ ### Css Grid
26
+
27
+ To use the css class for grid, you need to require the grid.css file in you'r asset pipeline.
28
+
29
+ app/assets/stylesheets/application.css
30
+ ```css
31
+ /*
32
+ *= require grid
33
+ */
34
+ ```
35
+
36
+ ### Grid Helpers
37
+
38
+ To use the methods helper provide, you need to include GridHelper
39
+
40
+ app/helpers/application_helper.rb
41
+ ```ruby
42
+ include GridHelper
43
+ ```
44
+
19
45
  ## Usage
20
46
 
21
- TODO: Write usage instructions here
47
+ ### Css Grid Tags
48
+
49
+ __Container__ is a full width div that allows layouts to have a background that spans the full width of the browser
50
+
51
+ __Row__ is a row of columns. It centres them and defines the 1140px max-width.
52
+
53
+ __Span__ is the column, there are twelve classes to define the width for each column. Defined from 'one_span' to 'twelve_span'
54
+
55
+ There is some example of what you can do :
56
+ ```html
57
+ <div class="container">
58
+ <div class="row">
59
+ <div class="six_span">
60
+ <!-- this is a half width column -->
61
+ </div>
62
+ <div class="six_span">
63
+ <!-- this is a half width column -->
64
+ </div>
65
+ </div>
66
+ </div>
67
+ </div>
68
+ ```
69
+
70
+ ```html
71
+ <div class="container">
72
+ <div class="row">
73
+ <div class="three_span">
74
+ <!-- this is a quart width column -->
75
+ </div>
76
+ <div class="three_span">
77
+ <!-- this is a quart width column -->
78
+ </div>
79
+ <div class="six_span">
80
+ <!-- this is a half width column -->
81
+ </div>
82
+ </div>
83
+
84
+ <div class="row">
85
+ <div class="twelve_span">
86
+ <!-- this is a full width column -->
87
+ </div>
88
+ </div>
89
+ </div>
90
+ ```
91
+
92
+
93
+ ### Grid Helpers
94
+
95
+ The grid helpers allow you to shortcut creation for the css grid tags.
96
+
97
+ #### Basics
98
+
99
+ You can call 'container', 'row' or '*_span' functions that create the corresponding divs
100
+
101
+ Code
102
+
103
+ erb code
104
+ ```erb
105
+ <%= container do %>
106
+ <!-- some html -->
107
+ <% end %>
108
+ ```
109
+
110
+ will produce
111
+ ```html
112
+ <div class="container">
113
+ <!-- some html -->
114
+ </div>
115
+ ```
116
+
117
+ You can pass specific html ids or class as arguments
118
+
119
+ erb code
120
+ ```erb
121
+ <%= row :class=>:some_class do %>
122
+ <!-- some html -->
123
+ <% end %>
124
+ ```
125
+
126
+ will produce
127
+ ```html
128
+ <div class="row some_class">
129
+ <!-- some html -->
130
+ </div>
131
+ ```
132
+
133
+ --
134
+ erb code
135
+ ```erb
136
+ <%= six_span :id=>:some_id, :class=>"class_one class_two" do %>
137
+ <!-- some html -->
138
+ <% end %>
139
+ ```
140
+
141
+ will produce
142
+ ```html
143
+ <div class="six_span class_one class_two" id="some_id">
144
+ <!-- some html -->
145
+ </div>
146
+ ```
147
+
148
+ You can also pass 'offset' as an argument for the '*_span' helpers. Offset will slide the column to the left. (like you insert a empty *_span before)
149
+
150
+ erb code
151
+ ```erb
152
+ <%= four_span :offset=>:two do %>
153
+ <!-- some html -->
154
+ <% end %>
155
+ ```
156
+
157
+ will produce
158
+ ```html
159
+ <div class="four_span offset_two">
160
+ <!-- some html -->
161
+ </div>
162
+ ```
163
+
164
+ --
165
+ erb code
166
+ ```erb
167
+ <%= four_span :offset=>2 do %>
168
+ <!-- some html -->
169
+ <% end %>
170
+ ```
171
+
172
+ will produce
173
+ ```html
174
+ <div class="four_span offset_two">
175
+ <!-- some html -->
176
+ </div>
177
+ ```
178
+
179
+ #### Collections
180
+
181
+ The most interesting part if you ask me!
182
+ GridHelper allow you to create severals columns in one time. And include them directly into row or container.
183
+
184
+ Imagine I have this yml file
185
+ ```yml
186
+ en:
187
+ array:
188
+ name: Array
189
+ description: It's an array !
190
+
191
+ hash:
192
+ name: Hash
193
+ descrption: I love hash, it's so fun !
194
+
195
+ string:
196
+ name: Text
197
+ description: Just read the text.
198
+ ```
199
+
200
+ I can do in my view
201
+ ```erb
202
+ <%= two_col_container :collection=>[:array, :hash, :string] do |i18n_key| %>
203
+ <h2><%=t "#{ i18n_key }.name" %></h2>
204
+ <p><%=t "#{ i18n_key }.description" %></p>
205
+ <% end %>
206
+ ```
207
+
208
+ This will use two col per row (so six_span width), yield the block for each element, and place them into correct rows / container
209
+ So the produced html will be
210
+ ```html
211
+ <div class="container">
212
+ <div class="row">
213
+ <div class="six_span">
214
+ <h2>Array</h2>
215
+ <p>It's an array !</p>
216
+ </div>
217
+ <div class="six_span">
218
+ <h2>Hash</h2>
219
+ <p>I love hash, it's so fun !</p>
220
+ </div>
221
+ </div>
222
+
223
+ <div class="row">
224
+ <div class="six_span">
225
+ <h2>Text</h2>
226
+ <p>Just read the text.</p>
227
+ </div>
228
+ </div>
229
+ </div>
230
+ ```
231
+
232
+ So You can play easily with grid and your collections. Users.all for example ;)
233
+
234
+ --
235
+ If you just want to create a single row, you can just do
236
+ ```erb
237
+ <%= four_col_row :collection=>[1, 2, 3, 4], :id=>:count_style do |i| %>
238
+ <p>count <%= i %></p>
239
+ <% end %>
240
+ ```
241
+
242
+ will use four col per row (so three_span width), will produce
243
+ ```html
244
+ <div class="row count_style">
245
+ <div class="three_span">
246
+ <p>count 1</p>
247
+ </div>
248
+ <div class="three_span">
249
+ <p>count 2</p>
250
+ </div>
251
+ <div class="three_span">
252
+ <p>count 3</p>
253
+ </div>
254
+ <div class="three_span">
255
+ <p>count 4</p>
256
+ </div>
257
+ </div>
258
+ ```
259
+
260
+ FYI: 'id' and 'class' options can also be used for *_col_ccontainer and *_col_row, wich is applied to the container / row
261
+
262
+
263
+ ## Future ameliorations
264
+
265
+ I will add the possibility, in *_col_container, to use several *_span for the same object.
266
+ I think this will be great, forms for example.
267
+
268
+ ```html
269
+ <div class="row">
270
+ <div class="three_span">
271
+ <label>Email</label>
272
+ </div>
273
+ <div class="nine_span">
274
+ <input id="email">
275
+ </div>
276
+ </div>
277
+ ```
278
+
279
+ by passing
280
+ ```erb
281
+ <%= twelve_col_container :collection=>[:email], :auto_span=>:disabled do |field| %>
282
+ <%= three_span{ label_tag field }%>
283
+ <%= nine_span{ text_field_tag field }%>
284
+ <% end %>
285
+ ```
22
286
 
23
287
  ## Contributing
24
288
 
data/css_grid.gemspec CHANGED
@@ -4,8 +4,8 @@ require File.expand_path('../lib/css_grid/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Thomas Petrachi"]
6
6
  gem.email = ["thomas.petrachi@vodeclic.com"]
7
- gem.description = %q{In DEV GEM : Provide CSS grid stylesheet, plus several helpers}
8
- gem.summary = %q{In DEV GEM : 1140_grid.css and GridHelper module}
7
+ gem.description = %q{Provide CSS grid stylesheet, plus several helpers}
8
+ gem.summary = %q{grid.css and GridHelper module}
9
9
  gem.homepage = "https://github.com/petrachi/css_grid"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
data/lib/.DS_Store CHANGED
Binary file
@@ -1,3 +1,3 @@
1
1
  module CssGrid
2
- VERSION = "0.0.2"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/css_grid.rb CHANGED
@@ -1,99 +1,80 @@
1
1
  require "css_grid/version"
2
2
  require "css_grid/engine"
3
3
 
4
- module CssGridHelper
5
-
6
-
7
- #module GridHelper
8
- TWELVE_STRING_INTS = {:one => 1, :two => 2, :three => 3, :four => 4, :five => 5, :six => 6, :seven => 7, :eight => 8, :nine => 9, :ten => 10, :evelen => 11, :twelve => 12}
9
-
10
- def grid element_class, options = Hash.new, &block
11
- html_id, html_class, offset = options.delete_many :id, :class, :offset
12
- offset = TWELVE_STRING_INTS.invert[offset] if offset.class == Fixnum
13
-
14
- content_tag(:div, nil, :id => html_id, :class => "#{ element_class } #{ html_class } #{ "offset_#{ offset }" if offset }" , &block)
15
- end
4
+ module GridHelper
5
+ TWELVE_STRING_INTS = {:one => 1, :two => 2, :three => 3, :four => 4, :five => 5, :six => 6, :seven => 7, :eight => 8, :nine => 9, :ten => 10, :evelen => 11, :twelve => 12}
16
6
 
17
- def col col_number, options = Hash.new, &block
18
- html_id, html_class, collection = options.delete_many :id, :class, :collection
19
- collection ||= [1]
7
+ def grid element_class, options = Hash.new, &block
8
+ html_id, html_class, offset = options.delete_many :id, :class, :offset
9
+ offset = TWELVE_STRING_INTS.invert[offset] if offset.class == Fixnum
10
+
11
+ content_tag(:div, nil, :id => html_id, :class => "#{ element_class } #{ html_class } #{ "offset_#{ offset }" if offset }" , &block)
12
+ end
20
13
 
21
- collection_length = TWELVE_STRING_INTS[col_number.to_sym]
22
- span_width = TWELVE_STRING_INTS.invert[ 12 / collection_length ]
14
+ def col col_number, options = Hash.new, &block
15
+ html_id, html_class, collection = options.delete_many :id, :class, :collection
16
+ collection ||= [1]
23
17
 
24
- raise ArgumentError, "collection.size must be <= #{ collection_length }" if collection.size > collection_length
18
+ collection_length = TWELVE_STRING_INTS[col_number.to_sym]
19
+ span_width = TWELVE_STRING_INTS.invert[ 12 / collection_length ]
25
20
 
26
- cols = collection.map do |elt|
27
- eval %{
28
- #{ span_width }_span do
29
- capture(elt, &block)
30
- end }
31
- end
21
+ raise ArgumentError, "collection.size must be <= #{ collection_length }" if collection.size > collection_length
32
22
 
33
- row :id => html_id, :class => html_class do
34
- cols.inject(ActiveSupport::SafeBuffer.new){ |buffer, col| buffer.safe_concat(col) }
35
- end
23
+ cols = collection.map do |elt|
24
+ eval %{
25
+ #{ span_width }_span do
26
+ capture(elt, &block)
27
+ end }
36
28
  end
37
29
 
38
- def recollect size, collection
39
- recollected = Array.new
40
- 0.step(collection.size - 1, size) do |i|
41
- recollected << collection[i..i + size - 1]
42
- end
43
- recollected
30
+ row :id => html_id, :class => html_class do
31
+ cols.inject(ActiveSupport::SafeBuffer.new){ |buffer, col| buffer.safe_concat(col) }
44
32
  end
33
+ end
45
34
 
46
- def rows col_number, options = Hash.new, &block
47
- html_id, html_class, collection = options.delete_many :id, :class, :collection
48
- collection ||= [1]
35
+ def recollect size, collection
36
+ recollected = Array.new
37
+ 0.step(collection.size - 1, size) do |i|
38
+ recollected << collection[i..i + size - 1]
39
+ end
40
+ recollected
41
+ end
49
42
 
50
- recollection_size = TWELVE_STRING_INTS[col_number.to_sym]
43
+ def rows col_number, options = Hash.new, &block
44
+ html_id, html_class, collection = options.delete_many :id, :class, :collection
45
+ collection ||= [1]
51
46
 
52
- rows = recollect(recollection_size, collection).map do |collection_mini|
53
- col col_number, {:collection => collection_mini}, &block
54
- end
47
+ recollection_size = TWELVE_STRING_INTS[col_number.to_sym]
55
48
 
56
- container :id => html_id, :class => html_class do
57
- rows.inject(ActiveSupport::SafeBuffer.new){ |buffer, col| buffer.safe_concat(col) }
58
- end
49
+ rows = recollect(recollection_size, collection).map do |collection_mini|
50
+ col col_number, {:collection => collection_mini}, &block
59
51
  end
60
-
61
-
62
- def method_missing method_name, *args, &block
63
- case method_name.to_s
64
- when /^(container|row|(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)_span)$/
65
- self.grid($1, *args, &block)
66
- when /^(one|two|three|four|six|twelve)_col_row$/
67
- self.col($1, *args, &block)
68
- when /^(one|two|three|four|six|twelve)_col_container$/
69
- self.rows($1, *args, &block)
70
- else super
71
- end
52
+
53
+ container :id => html_id, :class => html_class do
54
+ rows.inject(ActiveSupport::SafeBuffer.new){ |buffer, col| buffer.safe_concat(col) }
72
55
  end
73
-
74
- def respond_to? method_name, include_private = false
75
- case method_name.to_s
76
- when /^(container|row|(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)_span)$/,
77
- /^(one|two|three|four|six|twelve)_col_row$/,
78
- /^(one|two|three|four|six|twelve)_col_container$/
79
- true
80
- else super
81
- end
56
+ end
57
+
58
+
59
+ def method_missing method_name, *args, &block
60
+ case method_name.to_s
61
+ when /^(container|row|(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)_span)$/
62
+ self.grid($1, *args, &block)
63
+ when /^(one|two|three|four|six|twelve)_col_row$/
64
+ self.col($1, *args, &block)
65
+ when /^(one|two|three|four|six|twelve)_col_container$/
66
+ self.rows($1, *args, &block)
67
+ else super
82
68
  end
83
-
84
-
85
- =begin
86
- def dynamic_method method_name, *args, &block
87
- case method_name.to_s
88
- when /^(container|row|(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)_span)$/
89
- lambda{ self.grid($1, *args, &block) }
90
- when /^(one|two|three|four|six|twelve)_col_row$/
91
- lambda{ self.col($1, *args, &block) }
92
- when /^(one|two|three|four|six|twelve)_col_container$/
93
- lambda{ self.rows($1, *args, &block) }
94
- else super
95
- end
69
+ end
70
+
71
+ def respond_to? method_name, include_private = false
72
+ case method_name.to_s
73
+ when /^(container|row|(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)_span)$/,
74
+ /^(one|two|three|four|six|twelve)_col_row$/,
75
+ /^(one|two|three|four|six|twelve)_col_container$/
76
+ true
77
+ else super
96
78
  end
97
- =end
98
- #end
79
+ end
99
80
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: css_grid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,7 +43,7 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- description: ! 'In DEV GEM : Provide CSS grid stylesheet, plus several helpers'
46
+ description: Provide CSS grid stylesheet, plus several helpers
47
47
  email:
48
48
  - thomas.petrachi@vodeclic.com
49
49
  executables: []
@@ -79,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  segments:
81
81
  - 0
82
- hash: 3898628511873595243
82
+ hash: -3545808649529635569
83
83
  required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
@@ -88,11 +88,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  segments:
90
90
  - 0
91
- hash: 3898628511873595243
91
+ hash: -3545808649529635569
92
92
  requirements: []
93
93
  rubyforge_project:
94
94
  rubygems_version: 1.8.24
95
95
  signing_key:
96
96
  specification_version: 3
97
- summary: ! 'In DEV GEM : 1140_grid.css and GridHelper module'
97
+ summary: grid.css and GridHelper module
98
98
  test_files: []