skim 0.8.0

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.
@@ -0,0 +1,84 @@
1
+ require 'helper'
2
+
3
+ class TestSkimCodeStructure < TestSkim
4
+ def test_render_with_conditional
5
+ source = %q{
6
+ div
7
+ - if @show_first()
8
+ p The first paragraph
9
+ - else
10
+ p The second paragraph
11
+ }
12
+
13
+ assert_html '<div><p>The second paragraph</p></div>', source
14
+ end
15
+
16
+ def test_render_with_consecutive_conditionals
17
+ source = %q{
18
+ div
19
+ - if @show_first true
20
+ p The first paragraph
21
+ - if @show_first true
22
+ p The second paragraph
23
+ }
24
+
25
+ assert_html '<div><p>The first paragraph</p><p>The second paragraph</p></div>', source
26
+ end
27
+
28
+ def test_render_with_parameterized_conditional
29
+ source = %q{
30
+ div
31
+ - if @show_first false
32
+ p The first paragraph
33
+ - else
34
+ p The second paragraph
35
+ }
36
+
37
+ assert_html '<div><p>The second paragraph</p></div>', source
38
+ end
39
+
40
+ def test_render_with_conditional_and_following_nonconditonal
41
+ source = %q{
42
+ div
43
+ - if true
44
+ p The first paragraph
45
+ - @var = 42
46
+ = @var
47
+ }
48
+
49
+ assert_html '<div><p>The first paragraph</p>42</div>', source
50
+ end
51
+
52
+ def test_render_with_inline_condition
53
+ source = %q{
54
+ p = @hello_world() if true
55
+ }
56
+
57
+ assert_html '<p>Hello World from @env</p>', source
58
+ end
59
+
60
+ def test_render_with_case
61
+ source = %q{
62
+ p
63
+ - switch 42
64
+ - when 41
65
+ | 1
66
+ - when 42
67
+ | 42
68
+ | is the answer
69
+ }
70
+
71
+ assert_html '<p>42 is the answer</p>', source
72
+ end
73
+
74
+ def test_render_with_slim_comments
75
+ source = %q{
76
+ p Hello
77
+ / This is a comment
78
+ Another comment
79
+ p World
80
+ }
81
+
82
+ assert_html '<p>Hello</p><p>World</p>', source
83
+ end
84
+ end
@@ -0,0 +1,48 @@
1
+ require 'helper'
2
+
3
+ class TestSkimHtmlEscaping < TestSkim
4
+ def test_html_will_not_be_escaped
5
+ source = %q{
6
+ p <Hello> World, meet "Skim".
7
+ }
8
+
9
+ with_and_without_asset do
10
+ assert_html '<p><Hello> World, meet "Skim".</p>', source
11
+ end
12
+ end
13
+
14
+ def test_html_with_newline_will_not_be_escaped
15
+ source = %q{
16
+ p
17
+ |
18
+ <Hello> World,
19
+ meet "Skim".
20
+ }
21
+
22
+ with_and_without_asset do
23
+ assert_html "<p><Hello> World,\n meet \"Skim\".</p>", source
24
+ end
25
+ end
26
+
27
+ def test_html_with_escaped_interpolation
28
+ source = %q{
29
+ - x = '"'
30
+ - content = '<x>'
31
+ p class="#{x}" test #{content}
32
+ }
33
+
34
+ with_and_without_asset do
35
+ assert_html '<p class="&quot;">test &lt;x&gt;</p>', source
36
+ end
37
+ end
38
+
39
+ def test_html_nested_escaping
40
+ source = %q{
41
+ = @callback "Test", ->
42
+ | escaped &
43
+ }
44
+ with_and_without_asset do
45
+ assert_html 'Test escaped &amp; Test', source
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,473 @@
1
+ require 'helper'
2
+
3
+ class TestSkimHtmlStructure < TestSkim
4
+ def test_simple_render
5
+ # Keep the trailing space behind "body "!
6
+ source = %q{
7
+ html
8
+ head
9
+ title Simple Test Title
10
+ body
11
+ p Hello World, meet Slim.
12
+ }
13
+
14
+ assert_html '<html><head><title>Simple Test Title</title></head><body><p>Hello World, meet Slim.</p></body></html>', source
15
+ end
16
+
17
+ def test_html_tag_with_text_and_empty_line
18
+ # Keep the trailing space behind "body "!
19
+ source = %q{
20
+ p Hello
21
+
22
+ p World
23
+ }
24
+
25
+ assert_html "<p>Hello</p><p>World</p>", source
26
+ end
27
+
28
+ def test_html_namespaces
29
+ source = %q{
30
+ html:body
31
+ html:p html:id="test" Text
32
+ }
33
+
34
+ assert_html '<html:body><html:p html:id="test">Text</html:p></html:body>', source
35
+ end
36
+
37
+ def test_doctype
38
+ source = %q{
39
+ doctype 1.1
40
+ html
41
+ }
42
+
43
+ assert_html '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html></html>', source, :format => :xhtml
44
+ end
45
+
46
+ def test_doctype_new_syntax
47
+ source = %q{
48
+ doctype 5
49
+ html
50
+ }
51
+
52
+ assert_html '<!DOCTYPE html><html></html>', source, :format => :xhtml
53
+ end
54
+
55
+ def test_doctype_new_syntax_html5
56
+ source = %q{
57
+ doctype html
58
+ html
59
+ }
60
+
61
+ assert_html '<!DOCTYPE html><html></html>', source, :format => :xhtml
62
+ end
63
+
64
+ def test_render_with_shortcut_attributes
65
+ source = %q{
66
+ h1#title This is my title
67
+ #notice.hello.world
68
+ = @hello_world()
69
+ }
70
+
71
+ assert_html '<h1 id="title">This is my title</h1><div class="hello world" id="notice">Hello World from @env</div>', source
72
+ end
73
+
74
+ def test_render_with_overwritten_default_tag
75
+ source = %q{
76
+ #notice.hello.world
77
+ = @hello_world()
78
+ }
79
+
80
+ assert_html '<section class="hello world" id="notice">Hello World from @env</section>', source, :default_tag => 'section'
81
+ end
82
+
83
+ def test_render_with_text_block
84
+ source = %q{
85
+ p
86
+ |
87
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
88
+ }
89
+
90
+ assert_html '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>', source
91
+ end
92
+
93
+ def test_render_with_text_block_with_subsequent_markup
94
+ source = %q{
95
+ p
96
+ |
97
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
98
+ p Some more markup
99
+ }
100
+
101
+ assert_html '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p><p>Some more markup</p>', source
102
+ end
103
+
104
+ def test_render_with_text_block_with_trailing_whitespace
105
+ source = %q{
106
+ ' this is
107
+ a link to
108
+ a href="link" page
109
+ }
110
+
111
+ assert_html "this is\na link to <a href=\"link\">page</a>", source
112
+ end
113
+
114
+ def test_nested_text
115
+ source = %q{
116
+ p
117
+ |
118
+ This is line one.
119
+ This is line two.
120
+ This is line three.
121
+ This is line four.
122
+ p This is a new paragraph.
123
+ }
124
+
125
+ assert_html "<p>This is line one.\n This is line two.\n This is line three.\n This is line four.</p><p>This is a new paragraph.</p>", source
126
+ end
127
+
128
+ def test_nested_text_with_nested_html_one_same_line
129
+ source = %q{
130
+ p
131
+ | This is line one.
132
+ This is line two.
133
+ span.bold This is a bold line in the paragraph.
134
+ | This is more content.
135
+ }
136
+
137
+ assert_html "<p>This is line one.\n This is line two.<span class=\"bold\">This is a bold line in the paragraph.</span> This is more content.</p>", source
138
+ end
139
+
140
+ def test_nested_text_with_nested_html_one_same_line2
141
+ source = %q{
142
+ p
143
+ |This is line one.
144
+ This is line two.
145
+ span.bold This is a bold line in the paragraph.
146
+ | This is more content.
147
+ }
148
+
149
+ assert_html "<p>This is line one.\n This is line two.<span class=\"bold\">This is a bold line in the paragraph.</span> This is more content.</p>", source
150
+ end
151
+
152
+ def test_nested_text_with_nested_html
153
+ source = %q{
154
+ p
155
+ |
156
+ This is line one.
157
+ This is line two.
158
+ This is line three.
159
+ This is line four.
160
+ span.bold This is a bold line in the paragraph.
161
+ | This is more content.
162
+ }
163
+
164
+ assert_html "<p>This is line one.\n This is line two.\n This is line three.\n This is line four.<span class=\"bold\">This is a bold line in the paragraph.</span> This is more content.</p>", source
165
+ end
166
+
167
+ def test_simple_paragraph_with_padding
168
+ source = %q{
169
+ p There will be 3 spaces in front of this line.
170
+ }
171
+
172
+ assert_html '<p> There will be 3 spaces in front of this line.</p>', source
173
+ end
174
+
175
+ def test_paragraph_with_nested_text
176
+ source = %q{
177
+ p This is line one.
178
+ This is line two.
179
+ }
180
+
181
+ assert_html "<p>This is line one.\n This is line two.</p>", source
182
+ end
183
+
184
+ def test_paragraph_with_padded_nested_text
185
+ source = %q{
186
+ p This is line one.
187
+ This is line two.
188
+ }
189
+
190
+ assert_html "<p> This is line one.\n This is line two.</p>", source
191
+ end
192
+
193
+ def test_paragraph_with_attributes_and_nested_text
194
+ source = %q{
195
+ p#test class="paragraph" This is line one.
196
+ This is line two.
197
+ }
198
+
199
+ assert_html "<p class=\"paragraph\" id=\"test\">This is line one.\nThis is line two.</p>", source
200
+ end
201
+
202
+ def test_output_code_with_leading_spaces
203
+ source = %q{
204
+ p= @hello_world()
205
+ p = @hello_world()
206
+ p = @hello_world()
207
+ }
208
+
209
+ assert_html '<p>Hello World from @env</p><p>Hello World from @env</p><p>Hello World from @env</p>', source
210
+ end
211
+
212
+ def test_single_quoted_attributes
213
+ source = %q{
214
+ p class='underscored_class_name' = @output_number()
215
+ }
216
+
217
+ assert_html '<p class="underscored_class_name">1337</p>', source
218
+ end
219
+
220
+ def test_nonstandard_attributes
221
+ source = %q{
222
+ p id="dashed-id" class="underscored_class_name" = @output_number()
223
+ }
224
+
225
+ assert_html '<p class="underscored_class_name" id="dashed-id">1337</p>', source
226
+ end
227
+
228
+ def test_nonstandard_shortcut_attributes
229
+ source = %q{
230
+ p#dashed-id.underscored_class_name = @output_number()
231
+ }
232
+
233
+ assert_html '<p class="underscored_class_name" id="dashed-id">1337</p>', source
234
+ end
235
+
236
+ def test_dashed_attributes
237
+ source = %q{
238
+ p data-info="Illudium Q-36" = @output_number()
239
+ }
240
+
241
+ assert_html '<p data-info="Illudium Q-36">1337</p>', source
242
+ end
243
+
244
+ def test_dashed_attributes_with_shortcuts
245
+ source = %q{
246
+ p#marvin.martian data-info="Illudium Q-36" = @output_number()
247
+ }
248
+
249
+ assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
250
+ end
251
+
252
+ def test_parens_around_attributes
253
+ source = %q{
254
+ p(id="marvin" class="martian" data-info="Illudium Q-36") = @output_number()
255
+ }
256
+
257
+ assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
258
+ end
259
+
260
+ def test_square_brackets_around_attributes
261
+ source = %q{
262
+ p[id="marvin" class="martian" data-info="Illudium Q-36"] = @output_number()
263
+ }
264
+
265
+ assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
266
+ end
267
+
268
+ def test_parens_around_attributes_with_equal_sign_snug_to_right_paren
269
+ source = %q{
270
+ p(id="marvin" class="martian" data-info="Illudium Q-36")= @output_number()
271
+ }
272
+
273
+ assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
274
+ end
275
+
276
+ def test_static_empty_attribute
277
+ source = %q{
278
+ p(id="marvin" class="" data-info="Illudium Q-36")= @output_number()
279
+ }
280
+
281
+ assert_html '<p class="" data-info="Illudium Q-36" id="marvin">1337</p>', source
282
+ end
283
+
284
+ def test_dynamic_empty_attribute
285
+ skip "pending"
286
+
287
+ source = %q{
288
+ p(id="marvin" class=null other_empty=("") data-info="Illudium Q-36")= @output_number()
289
+ }
290
+
291
+ assert_html '<p data-info="Illudium Q-36" id="marvin">1337</p>', source
292
+ end
293
+
294
+ def test_closed_tag
295
+ source = %q{
296
+ closed/
297
+ }
298
+
299
+ assert_html '<closed />', source, :format => :xhtml
300
+ end
301
+
302
+ def test_attributs_with_parens_and_spaces
303
+ source = %q{label{ for='filter' }= @hello_world()}
304
+ assert_html '<label for="filter">Hello World from @env</label>', source
305
+ end
306
+
307
+ def test_attributs_with_parens_and_spaces2
308
+ source = %q{label{ for='filter' } = @hello_world()}
309
+ assert_html '<label for="filter">Hello World from @env</label>', source
310
+ end
311
+
312
+ def test_attributs_with_multiple_spaces
313
+ source = %q{label for='filter' class="test" = @hello_world()}
314
+ assert_html '<label class="test" for="filter">Hello World from @env</label>', source
315
+ end
316
+
317
+ def test_closed_tag_with_attributes
318
+ source = %q{
319
+ closed id="test" /
320
+ }
321
+
322
+ assert_html '<closed id="test" />', source, :format => :xhtml
323
+ end
324
+
325
+ def test_closed_tag_with_attributes_and_parens
326
+ source = %q{
327
+ closed(id="test")/
328
+ }
329
+
330
+ assert_html '<closed id="test" />', source, :format => :xhtml
331
+ end
332
+
333
+ def test_render_with_html_comments
334
+ source = %q{
335
+ p Hello
336
+ /! This is a comment
337
+
338
+ Another comment
339
+ p World
340
+ }
341
+
342
+ assert_html "<p>Hello</p><!--This is a comment\n\nAnother comment--><p>World</p>", source
343
+ end
344
+
345
+ def test_render_with_html_conditional_and_tag
346
+ source = %q{
347
+ /[ if IE ]
348
+ p Get a better browser.
349
+ }
350
+
351
+ assert_html "<!--[if IE]><p>Get a better browser.</p><![endif]-->", source
352
+ end
353
+
354
+ def test_render_with_html_conditional_and_method_output
355
+ source = %q{
356
+ /[ if IE ]
357
+ = @message 'hello'
358
+ }
359
+
360
+ assert_html "<!--[if IE]>hello<![endif]-->", source
361
+ end
362
+
363
+ def test_multiline_attributes_with_method
364
+ source = %q{
365
+ p<id="marvin"
366
+ class="martian"
367
+ data-info="Illudium Q-36"> = @output_number()
368
+ }
369
+ Slim::Parser::DELIMITERS.each do |k,v|
370
+ str = source.sub('<',k).sub('>',v)
371
+ assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', str
372
+ end
373
+ end
374
+
375
+ def test_multiline_attributes_with_text_on_same_line
376
+ source = %q{
377
+ p<id="marvin"
378
+ class="martian"
379
+ data-info="Illudium Q-36"> THE space modulator
380
+ }
381
+ Slim::Parser::DELIMITERS.each do |k,v|
382
+ str = source.sub('<',k).sub('>',v)
383
+ assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">THE space modulator</p>', str
384
+ end
385
+ end
386
+
387
+ def test_multiline_attributes_with_nested_text
388
+ source = %q{
389
+ p<id="marvin"
390
+ class="martian"
391
+ data-info="Illudium Q-36">
392
+ | THE space modulator
393
+ }
394
+ Slim::Parser::DELIMITERS.each do |k,v|
395
+ str = source.sub('<',k).sub('>',v)
396
+ assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">THE space modulator</p>', str
397
+ end
398
+ end
399
+
400
+ def test_multiline_attributes_with_dynamic_attr
401
+ source = %q{
402
+ p<id=@id_helper()
403
+ class="martian"
404
+ data-info="Illudium Q-36">
405
+ | THE space modulator
406
+ }
407
+ Slim::Parser::DELIMITERS.each do |k,v|
408
+ str = source.sub('<',k).sub('>',v)
409
+ assert_html '<p class="martian" data-info="Illudium Q-36" id="notice">THE space modulator</p>', str
410
+ end
411
+ end
412
+
413
+ def test_multiline_attributes_with_nested_tag
414
+ source = %q{
415
+ p<id=@id_helper()
416
+ class="martian"
417
+ data-info="Illudium Q-36">
418
+ span.emphasis THE
419
+ | space modulator
420
+ }
421
+ Slim::Parser::DELIMITERS.each do |k,v|
422
+ str = source.sub('<',k).sub('>',v)
423
+ assert_html '<p class="martian" data-info="Illudium Q-36" id="notice"><span class="emphasis">THE</span> space modulator</p>', str
424
+ end
425
+ end
426
+
427
+ def test_multiline_attributes_with_nested_text_and_extra_indentation
428
+ source = %q{
429
+ li< id="myid"
430
+ class="myclass"
431
+ data-info="myinfo">
432
+ a href="link" My Link
433
+ }
434
+ Slim::Parser::DELIMITERS.each do |k,v|
435
+ str = source.sub('<',k).sub('>',v)
436
+ assert_html '<li class="myclass" data-info="myinfo" id="myid"><a href="link">My Link</a></li>', str
437
+ end
438
+ end
439
+
440
+ def test_block_expansion_support
441
+ source = %q{
442
+ ul
443
+ li.first: a href='a' foo
444
+ li: a href='b' bar
445
+ li.last: a href='c' baz
446
+ }
447
+ assert_html %{<ul><li class=\"first\"><a href=\"a\">foo</a></li><li><a href=\"b\">bar</a></li><li class=\"last\"><a href=\"c\">baz</a></li></ul>}, source
448
+ end
449
+
450
+ def test_block_expansion_class_attributes
451
+ source = %q{
452
+ .a: .b: #c d
453
+ }
454
+ assert_html %{<div class="a"><div class="b"><div id="c">d</div></div></div>}, source
455
+ end
456
+
457
+ def test_block_expansion_nesting
458
+ source = %q{
459
+ html: body: .content
460
+ | Text
461
+ }
462
+ assert_html %{<html><body><div class=\"content\">Text</div></body></html>}, source
463
+ end
464
+
465
+ def test_eval_attributes_once
466
+ source = %q{
467
+ input[value=@succ_x()]
468
+ input[value=@succ_x()]
469
+ }
470
+ assert_html %{<input value="1" /><input value="2" />}, source
471
+ end
472
+
473
+ end