/
grid_spec.rb
357 lines (325 loc) · 7.85 KB
/
grid_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
require 'spec_helper'
RSpec.describe "Container" do
it "creates a container table" do
input = '<container></container>'
expected = <<-HTML
<table class="container" align="center">
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
HTML
compare(input, expected)
end
it 'works when parsing a full HTML document' do
input = <<-INKY
<!doctype html> <html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
<body>
<container></container>
</body>
</html>
INKY
expected = <<-HTML
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
<body>
<table class="container" align="center">
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>
HTML
compare(input, expected)
end
end
RSpec.describe 'Grid' do
it 'creates a row' do
input = '<row></row>'
expected = <<-HTML
<table class="row">
<tbody>
<tr></tr>
</tbody>
</table>
HTML
compare(input, expected)
end
it 'creates a single column with default large and small classes' do
input = '<columns>One</columns>'
expected = <<-HTML
<th class="small-12 large-12 columns first last">
<table>
<tr>
<th>One</th>
<th class="expander"></th>
</tr>
</table>
</th>
HTML
compare(input, expected)
end
it 'creates a single column with default large and small classes using the column_count option' do
begin
@previous_column_count = Inky.configuration.column_count
Inky.configure do |config|
config.column_count = 5
end
input = '<columns>One</columns>'
expected = <<-HTML
<th class="small-5 large-5 columns first last">
<table>
<tr>
<th>One</th>
<th class="expander"></th>
</tr>
</table>
</th>
HTML
compare(input, expected)
ensure
Inky.configure do |config|
config.column_count = @previous_column_count
end
end
end
it 'creates a single column with first and last classes' do
input = '<columns large="12" small="12">One</columns>'
expected = <<-HTML
<th class="small-12 large-12 columns first last">
<table>
<tr>
<th>One</th>
<th class="expander"></th>
</tr>
</table>
</th>
HTML
compare(input, expected)
end
it 'creates two columns, one first, one last' do
input = <<-INKY
<body>
<columns large="6" small="12">One</columns>
<columns large="6" small="12">Two</columns>
</body>
INKY
expected = <<-HTML
<body>
<th class="small-12 large-6 columns first">
<table>
<tr>
<th>One</th>
</tr>
</table>
</th>
<th class="small-12 large-6 columns last">
<table>
<tr>
<th>Two</th>
</tr>
</table>
</th>
</body>
HTML
compare(input, expected)
end
it 'creates 3+ columns, first is first, last is last' do
input = <<-INKY
<body>
<columns large="4" small="12">One</columns>
<columns large="4" small="12">Two</columns>
<columns large="4" small="12">Three</columns>
</body>
INKY
expected = <<-INKY
<body>
<th class="small-12 large-4 columns first">
<table>
<tr>
<th>One</th>
</tr>
</table>
</th>
<th class="small-12 large-4 columns">
<table>
<tr>
<th>Two</th>
</tr>
</table>
</th>
<th class="small-12 large-4 columns last">
<table>
<tr>
<th>Three</th>
</tr>
</table>
</th>
</body>
INKY
compare(input, expected)
end
it 'transfers classes to the final HTML' do
input = '<columns class="small-offset-8 hide-for-small">One</columns>'
expected = <<-HTML
<th class="small-12 large-12 columns small-offset-8 hide-for-small first last">
<table>
<tr>
<th>One</th>
<th class="expander"></th>
</tr>
</table>
</th>
HTML
compare(input, expected)
end
# if it just has small, borrow from small for large
it 'automatically assigns large columns if no large attribute is assigned' do
input = <<-HTML
<body>
<columns small="4">One</columns>
<columns small="8">Two</columns>
</body>
HTML
expected = <<-INKY
<body>
<th class="small-4 large-4 columns first">
<table>
<tr>
<th>One</th>
</tr>
</table>
</th>
<th class="small-8 large-8 columns last">
<table>
<tr>
<th>Two</th>
</tr>
</table>
</th>
</body>
INKY
compare(input, expected)
end
it 'automatically assigns small columns as full width if only large defined' do
input = <<-INKY
<body>
<columns large="4">One</columns>
<columns large="8">Two</columns>
</body>
INKY
expected = <<-HTML
<body>
<th class="small-12 large-4 columns first">
<table>
<tr>
<th>One</th>
</tr>
</table>
</th>
<th class="small-12 large-8 columns last">
<table>
<tr>
<th>Two</th>
</tr>
</table>
</th>
</body>
HTML
compare(input, expected)
end
it 'assigns small as full width and large as half width if neither is defined and there are two columns' do
input = <<-INKY
<body>
<columns>One</columns>
<columns>Two</columns>
</body>
INKY
expected = <<-HTML
<body>
<th class="small-12 large-6 columns first">
<table>
<tr>
<th>One</th>
</tr>
</table>
</th>
<th class="small-12 large-6 columns last">
<table>
<tr>
<th>Two</th>
</tr>
</table>
</th>
</body>
HTML
compare(input, expected)
end
it 'supports nested grids' do
input = '<row><columns><row></row></columns></row>'
expected = <<-HTML
<table class="row">
<tbody>
<tr>
<th class="small-12 large-12 columns first last">
<table>
<tr>
<th>
<table class="row">
<tbody>
<tr></tr>
</tbody>
</table>
</th>
</tr>
</table>
</th>
</tr>
</tbody>
</table>
HTML
compare(input, expected)
end
it 'transfers attributes like valign' do
input = '<columns small="6" valign="middle" foo="bar">x</columns>'
expected = <<-HTML
<th class="small-6 large-6 columns first last" valign="middle" foo="bar">
<table>
<tr>
<th>
x
</th>
</tr>
</table>
</th>
HTML
compare(input, expected)
end
end
RSpec.describe 'Block Grid' do
it 'returns the correct block grid syntax' do
input = '<block-grid up="4"></block-grid>'
expected = <<-HTML
<table class="block-grid up-4">
<tr></tr>
</table>
HTML
compare(input, expected)
end
it 'copies classes to the final HTML output' do
input = '<block-grid up="4" class="show-for-large"></block-grid>'
expected = <<-HTML
<table class="block-grid up-4 show-for-large">
<tr></tr>
</table>
HTML
compare(input, expected)
end
end