haml 2.2.24 → 3.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of haml might be problematic. Click here for more details.

Files changed (168) hide show
  1. data/.yardopts +0 -1
  2. data/README.md +91 -151
  3. data/REMEMBER +11 -1
  4. data/Rakefile +73 -55
  5. data/VERSION +1 -1
  6. data/VERSION_NAME +1 -1
  7. data/bin/css2sass +7 -1
  8. data/bin/sass-convert +7 -0
  9. data/extra/haml-mode.el +2 -1
  10. data/lib/haml/buffer.rb +22 -4
  11. data/lib/haml/engine.rb +5 -1
  12. data/lib/haml/exec.rb +231 -46
  13. data/lib/haml/filters.rb +19 -8
  14. data/lib/haml/helpers.rb +47 -20
  15. data/lib/haml/helpers/action_view_extensions.rb +2 -4
  16. data/lib/haml/helpers/action_view_mods.rb +11 -8
  17. data/lib/haml/helpers/xss_mods.rb +13 -2
  18. data/lib/haml/html.rb +179 -48
  19. data/lib/haml/html/erb.rb +141 -0
  20. data/lib/haml/precompiler.rb +40 -15
  21. data/lib/haml/railtie.rb +1 -5
  22. data/lib/haml/root.rb +3 -0
  23. data/lib/haml/template.rb +4 -14
  24. data/lib/haml/util.rb +120 -30
  25. data/lib/haml/version.rb +25 -2
  26. data/lib/sass.rb +5 -1
  27. data/lib/sass/callbacks.rb +50 -0
  28. data/lib/sass/css.rb +40 -191
  29. data/lib/sass/engine.rb +170 -74
  30. data/lib/sass/environment.rb +8 -2
  31. data/lib/sass/error.rb +163 -25
  32. data/lib/sass/files.rb +31 -28
  33. data/lib/sass/plugin.rb +268 -87
  34. data/lib/sass/plugin/rails.rb +9 -4
  35. data/lib/sass/repl.rb +1 -1
  36. data/lib/sass/script.rb +31 -29
  37. data/lib/sass/script/bool.rb +1 -0
  38. data/lib/sass/script/color.rb +290 -23
  39. data/lib/sass/script/css_lexer.rb +22 -0
  40. data/lib/sass/script/css_parser.rb +28 -0
  41. data/lib/sass/script/funcall.rb +22 -3
  42. data/lib/sass/script/functions.rb +523 -33
  43. data/lib/sass/script/interpolation.rb +42 -0
  44. data/lib/sass/script/lexer.rb +169 -52
  45. data/lib/sass/script/literal.rb +58 -9
  46. data/lib/sass/script/node.rb +79 -1
  47. data/lib/sass/script/number.rb +20 -5
  48. data/lib/sass/script/operation.rb +49 -3
  49. data/lib/sass/script/parser.rb +162 -28
  50. data/lib/sass/script/string.rb +50 -2
  51. data/lib/sass/script/unary_operation.rb +25 -2
  52. data/lib/sass/script/variable.rb +21 -4
  53. data/lib/sass/scss.rb +14 -0
  54. data/lib/sass/scss/css_parser.rb +39 -0
  55. data/lib/sass/scss/parser.rb +683 -0
  56. data/lib/sass/scss/rx.rb +112 -0
  57. data/lib/sass/scss/script_lexer.rb +13 -0
  58. data/lib/sass/scss/script_parser.rb +25 -0
  59. data/lib/sass/tree/comment_node.rb +69 -27
  60. data/lib/sass/tree/debug_node.rb +7 -2
  61. data/lib/sass/tree/directive_node.rb +41 -35
  62. data/lib/sass/tree/for_node.rb +6 -0
  63. data/lib/sass/tree/if_node.rb +13 -1
  64. data/lib/sass/tree/import_node.rb +52 -27
  65. data/lib/sass/tree/mixin_def_node.rb +18 -0
  66. data/lib/sass/tree/mixin_node.rb +41 -6
  67. data/lib/sass/tree/node.rb +197 -70
  68. data/lib/sass/tree/prop_node.rb +152 -57
  69. data/lib/sass/tree/root_node.rb +118 -0
  70. data/lib/sass/tree/rule_node.rb +193 -96
  71. data/lib/sass/tree/variable_node.rb +9 -5
  72. data/lib/sass/tree/while_node.rb +4 -0
  73. data/test/benchmark.rb +5 -5
  74. data/test/haml/engine_test.rb +147 -10
  75. data/test/haml/{rhtml/_av_partial_1.rhtml → erb/_av_partial_1.erb} +1 -1
  76. data/test/haml/{rhtml/_av_partial_2.rhtml → erb/_av_partial_2.erb} +1 -1
  77. data/test/haml/{rhtml/action_view.rhtml → erb/action_view.erb} +1 -1
  78. data/test/haml/{rhtml/standard.rhtml → erb/standard.erb} +0 -0
  79. data/test/haml/helper_test.rb +91 -24
  80. data/test/haml/html2haml/erb_tests.rb +410 -0
  81. data/test/haml/html2haml_test.rb +210 -66
  82. data/test/haml/results/filters.xhtml +1 -1
  83. data/test/haml/results/just_stuff.xhtml +2 -0
  84. data/test/haml/spec_test.rb +44 -0
  85. data/test/haml/template_test.rb +22 -2
  86. data/test/haml/templates/helpers.haml +0 -13
  87. data/test/haml/templates/just_stuff.haml +2 -0
  88. data/test/haml/util_test.rb +48 -0
  89. data/test/sass/callbacks_test.rb +61 -0
  90. data/test/sass/conversion_test.rb +884 -0
  91. data/test/sass/css2sass_test.rb +99 -18
  92. data/test/sass/data/hsl-rgb.txt +319 -0
  93. data/test/sass/engine_test.rb +1049 -131
  94. data/test/sass/functions_test.rb +398 -47
  95. data/test/sass/more_results/more_import.css +1 -1
  96. data/test/sass/more_templates/more_import.sass +3 -3
  97. data/test/sass/plugin_test.rb +184 -10
  98. data/test/sass/results/compact.css +1 -1
  99. data/test/sass/results/complex.css +5 -5
  100. data/test/sass/results/compressed.css +1 -1
  101. data/test/sass/results/expanded.css +1 -1
  102. data/test/sass/results/import.css +3 -1
  103. data/test/sass/results/mixins.css +12 -12
  104. data/test/sass/results/nested.css +1 -1
  105. data/test/sass/results/options.css +1 -0
  106. data/test/sass/results/parent_ref.css +4 -4
  107. data/test/sass/results/script.css +3 -3
  108. data/test/sass/results/scss_import.css +15 -0
  109. data/test/sass/results/scss_importee.css +2 -0
  110. data/test/sass/script_conversion_test.rb +153 -0
  111. data/test/sass/script_test.rb +137 -70
  112. data/test/sass/scss/css_test.rb +811 -0
  113. data/test/sass/scss/rx_test.rb +156 -0
  114. data/test/sass/scss/scss_test.rb +871 -0
  115. data/test/sass/scss/test_helper.rb +37 -0
  116. data/test/sass/templates/alt.sass +2 -2
  117. data/test/sass/templates/bork1.sass +2 -0
  118. data/test/sass/templates/bork3.sass +2 -0
  119. data/test/sass/templates/bork4.sass +2 -0
  120. data/test/sass/templates/import.sass +4 -4
  121. data/test/sass/templates/importee.sass +3 -3
  122. data/test/sass/templates/line_numbers.sass +1 -1
  123. data/test/sass/templates/mixin_bork.sass +5 -0
  124. data/test/sass/templates/mixins.sass +2 -2
  125. data/test/sass/templates/nested_bork1.sass +2 -0
  126. data/test/sass/templates/nested_bork2.sass +2 -0
  127. data/test/sass/templates/nested_bork3.sass +2 -0
  128. data/test/sass/templates/nested_bork4.sass +2 -0
  129. data/test/sass/templates/nested_mixin_bork.sass +6 -0
  130. data/test/sass/templates/options.sass +2 -0
  131. data/test/sass/templates/parent_ref.sass +2 -2
  132. data/test/sass/templates/script.sass +69 -69
  133. data/test/sass/templates/scss_import.scss +10 -0
  134. data/test/sass/templates/scss_importee.scss +1 -0
  135. data/test/sass/templates/units.sass +10 -10
  136. data/test/test_helper.rb +20 -8
  137. data/vendor/fssm/LICENSE +20 -0
  138. data/vendor/fssm/README.markdown +55 -0
  139. data/vendor/fssm/Rakefile +59 -0
  140. data/vendor/fssm/VERSION.yml +5 -0
  141. data/vendor/fssm/example.rb +9 -0
  142. data/vendor/fssm/fssm.gemspec +77 -0
  143. data/vendor/fssm/lib/fssm.rb +33 -0
  144. data/vendor/fssm/lib/fssm/backends/fsevents.rb +36 -0
  145. data/vendor/fssm/lib/fssm/backends/inotify.rb +26 -0
  146. data/vendor/fssm/lib/fssm/backends/polling.rb +25 -0
  147. data/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +131 -0
  148. data/vendor/fssm/lib/fssm/monitor.rb +26 -0
  149. data/vendor/fssm/lib/fssm/path.rb +91 -0
  150. data/vendor/fssm/lib/fssm/pathname.rb +502 -0
  151. data/vendor/fssm/lib/fssm/state/directory.rb +57 -0
  152. data/vendor/fssm/lib/fssm/state/file.rb +24 -0
  153. data/vendor/fssm/lib/fssm/support.rb +63 -0
  154. data/vendor/fssm/lib/fssm/tree.rb +176 -0
  155. data/vendor/fssm/profile/prof-cache.rb +40 -0
  156. data/vendor/fssm/profile/prof-fssm-pathname.html +1231 -0
  157. data/vendor/fssm/profile/prof-pathname.rb +68 -0
  158. data/vendor/fssm/profile/prof-plain-pathname.html +988 -0
  159. data/vendor/fssm/profile/prof.html +2379 -0
  160. data/vendor/fssm/spec/path_spec.rb +75 -0
  161. data/vendor/fssm/spec/root/duck/quack.txt +0 -0
  162. data/vendor/fssm/spec/root/file.css +0 -0
  163. data/vendor/fssm/spec/root/file.rb +0 -0
  164. data/vendor/fssm/spec/root/file.yml +0 -0
  165. data/vendor/fssm/spec/root/moo/cow.txt +0 -0
  166. data/vendor/fssm/spec/spec_helper.rb +14 -0
  167. metadata +94 -14
  168. data/test/sass/templates/bork.sass +0 -2
@@ -0,0 +1,410 @@
1
+ module ErbTests
2
+ def test_erb
3
+ assert_equal '- foo = bar', render_erb('<% foo = bar %>')
4
+ assert_equal '- foo = bar', render_erb('<% foo = bar -%>')
5
+ assert_equal '= h @item.title', render_erb('<%=h @item.title %>')
6
+ assert_equal '= h @item.title', render_erb('<%=h @item.title -%>')
7
+ end
8
+
9
+ def test_inline_erb
10
+ assert_equal("%p= foo", render_erb("<p><%= foo %></p>"))
11
+ end
12
+
13
+ def test_non_inline_erb
14
+ assert_equal(<<HAML.rstrip, render_erb(<<HTML))
15
+ %p
16
+ = foo
17
+ HAML
18
+ <p>
19
+ <%= foo %>
20
+ </p>
21
+ HTML
22
+ assert_equal(<<HAML.rstrip, render_erb(<<HTML))
23
+ %p
24
+ = foo
25
+ HAML
26
+ <p>
27
+ <%= foo %></p>
28
+ HTML
29
+ assert_equal(<<HAML.rstrip, render_erb(<<HTML))
30
+ %p
31
+ = foo
32
+ HAML
33
+ <p><%= foo %>
34
+ </p>
35
+ HTML
36
+ end
37
+
38
+ def test_erb_in_cdata
39
+ assert_equal(<<HAML.rstrip, render_erb(<<HTML))
40
+ :cdata
41
+ Foo \#{bar} baz
42
+ HAML
43
+ <![CDATA[Foo <%= bar %> baz]]>
44
+ HTML
45
+ end
46
+
47
+ def test_erb_in_script
48
+ assert_equal(<<HAML.rstrip, render_erb(<<HTML))
49
+ :javascript
50
+ function foo() {
51
+ return \#{foo.to_json};
52
+ }
53
+ HAML
54
+ <script type="text/javascript">
55
+ function foo() {
56
+ return <%= foo.to_json %>;
57
+ }
58
+ </script>
59
+ HTML
60
+ end
61
+
62
+ def test_erb_in_style
63
+ assert_equal(<<HAML.rstrip, render_erb(<<HTML))
64
+ :css
65
+ foo {
66
+ bar: \#{"baz"};
67
+ }
68
+ HAML
69
+ <style type="text/css">
70
+ foo {
71
+ bar: <%= "baz" %>;
72
+ }
73
+ </style>
74
+ HTML
75
+ end
76
+
77
+ def test_erb_in_line
78
+ assert_equal 'foo bar #{baz}', render_erb('foo bar <%= baz %>')
79
+ assert_equal 'foo bar #{baz}! Bang.', render_erb('foo bar <%= baz %>! Bang.')
80
+ end
81
+
82
+ def test_erb_multi_in_line
83
+ assert_equal('foo bar #{baz}! Bang #{bop}.',
84
+ render_erb('foo bar <%= baz %>! Bang <%= bop %>.'))
85
+ assert_equal('foo bar #{baz}#{bop}!',
86
+ render_erb('foo bar <%= baz %><%= bop %>!'))
87
+ end
88
+
89
+ def test_erb_with_html_special_chars
90
+ assert_equal '= 3 < 5 ? "OK" : "Your computer is b0rken"',
91
+ render_erb('<%= 3 < 5 ? "OK" : "Your computer is b0rken" %>')
92
+ end
93
+
94
+ def test_erb_in_class_attribute
95
+ assert_equal "%div{:class => dyna_class} I have a dynamic attribute",
96
+ render_erb('<div class="<%= dyna_class %>">I have a dynamic attribute</div>')
97
+ end
98
+
99
+ def test_erb_in_id_attribute
100
+ assert_equal "%div{:id => dyna_id} I have a dynamic attribute",
101
+ render_erb('<div id="<%= dyna_id %>">I have a dynamic attribute</div>')
102
+ end
103
+
104
+ def test_erb_in_attribute_results_in_string_interpolation
105
+ assert_equal('%div{:id => "item_#{i}"} Ruby string interpolation FTW',
106
+ render_erb('<div id="item_<%= i %>">Ruby string interpolation FTW</div>'))
107
+ end
108
+
109
+ def test_erb_in_attribute_with_trailing_content
110
+ assert_equal('%div{:class => "#{12}!"} Bang!',
111
+ render_erb('<div class="<%= 12 %>!">Bang!</div>'))
112
+ end
113
+
114
+ def test_erb_in_html_escaped_attribute
115
+ assert_equal '%div{:class => "foo"} Bang!',
116
+ render_erb('<div class="<%= "foo" %>">Bang!</div>')
117
+ end
118
+
119
+ def test_erb_in_attribute_to_multiple_interpolations
120
+ assert_equal('%div{:class => "#{12} + #{13}"} Math is super',
121
+ render_erb('<div class="<%= 12 %> + <%= 13 %>">Math is super</div>'))
122
+ end
123
+
124
+ def test_whitespace_eating_erb_tags
125
+ assert_equal '- form_for', render_erb('<%- form_for -%>')
126
+ end
127
+
128
+ def test_interpolation_in_erb
129
+ assert_equal('= "Foo #{bar} baz"', render_erb('<%= "Foo #{bar} baz" %>'))
130
+ end
131
+
132
+ def test_interpolation_in_erb_attrs
133
+ assert_equal('%p{:foo => "#{bar} baz"}',
134
+ render_erb('<p foo="<%= "#{bar} baz" %>"></p>'))
135
+ end
136
+
137
+ def test_multiline_erb_silent_script
138
+ assert_equal(<<HAML.rstrip, render_erb(<<ERB))
139
+ .blah
140
+ - foo
141
+ - bar
142
+ - baz
143
+ %p foo
144
+ HAML
145
+ <div class="blah">
146
+ <%
147
+ foo
148
+ bar
149
+ baz
150
+ %>
151
+ <p>foo</p>
152
+ </div>
153
+ ERB
154
+ end
155
+
156
+ def test_multiline_erb_loud_script
157
+ assert_equal(<<HAML.rstrip, render_erb(<<ERB))
158
+ .blah
159
+ = foo + |
160
+ bar.baz.bang + |
161
+ baz |
162
+ %p foo
163
+ HAML
164
+ <div class="blah">
165
+ <%=
166
+ foo +
167
+ bar.baz.bang +
168
+ baz
169
+ %>
170
+ <p>foo</p>
171
+ </div>
172
+ ERB
173
+ end
174
+
175
+ def test_weirdly_indented_multiline_erb_loud_script
176
+ assert_equal(<<HAML.rstrip, render_erb(<<ERB))
177
+ .blah
178
+ = foo + |
179
+ bar.baz.bang + |
180
+ baz |
181
+ %p foo
182
+ HAML
183
+ <div class="blah">
184
+ <%=
185
+ foo +
186
+ bar.baz.bang +
187
+ baz
188
+ %>
189
+ <p>foo</p>
190
+ </div>
191
+ ERB
192
+ end
193
+
194
+ def test_two_multiline_erb_loud_scripts
195
+ assert_equal(<<HAML.rstrip, render_erb(<<ERB))
196
+ .blah
197
+ = foo + |
198
+ bar.baz.bang + |
199
+ baz |
200
+ -#
201
+ = foo.bar do |
202
+ bang |
203
+ end |
204
+ %p foo
205
+ HAML
206
+ <div class="blah">
207
+ <%=
208
+ foo +
209
+ bar.baz.bang +
210
+ baz
211
+ %>
212
+ <%= foo.bar do
213
+ bang
214
+ end %>
215
+ <p>foo</p>
216
+ </div>
217
+ ERB
218
+ end
219
+
220
+ def test_multiline_then_single_line_erb_loud_scripts
221
+ assert_equal(<<HAML.rstrip, render_erb(<<ERB))
222
+ .blah
223
+ = foo + |
224
+ bar.baz.bang + |
225
+ baz |
226
+ = foo.bar
227
+ %p foo
228
+ HAML
229
+ <div class="blah">
230
+ <%=
231
+ foo +
232
+ bar.baz.bang +
233
+ baz
234
+ %>
235
+ <%= foo.bar %>
236
+ <p>foo</p>
237
+ </div>
238
+ ERB
239
+ end
240
+
241
+ def test_multiline_erb_but_really_single_line
242
+ assert_equal(<<HAML.rstrip, render_erb(<<ERB))
243
+ .blah
244
+ = foo
245
+ %p foo
246
+ HAML
247
+ <div class="blah">
248
+ <%=
249
+ foo
250
+ %>
251
+ <p>foo</p>
252
+ </div>
253
+ ERB
254
+ end
255
+
256
+ ### Block Parsing
257
+
258
+ def test_block_parsing
259
+ assert_equal(<<HAML.rstrip, render_erb(<<ERB))
260
+ - foo do
261
+ %p bar
262
+ HAML
263
+ <% foo do %>
264
+ <p>bar</p>
265
+ <% end %>
266
+ ERB
267
+ end
268
+
269
+ def test_block_parsing_with_args
270
+ assert_equal(<<HAML.rstrip, render_erb(<<ERB))
271
+ - foo do |a, b, c|
272
+ %p bar
273
+ HAML
274
+ <% foo do |a, b, c| %>
275
+ <p>bar</p>
276
+ <% end %>
277
+ ERB
278
+ end
279
+
280
+ def test_block_parsing_with_equals
281
+ assert_equal(<<HAML.rstrip, render_erb(<<ERB))
282
+ = foo do
283
+ %p bar
284
+ HAML
285
+ <%= foo do %>
286
+ <p>bar</p>
287
+ <% end %>
288
+ ERB
289
+ end
290
+
291
+ def test_block_parsing_with_modified_end
292
+ assert_equal(<<HAML.rstrip, render_erb(<<ERB))
293
+ - foo do
294
+ blah
295
+ - end.bip
296
+ HAML
297
+ <% foo do %>
298
+ blah
299
+ <% end.bip %>
300
+ ERB
301
+ end
302
+
303
+ def test_block_parsing_with_modified_end_with_block
304
+ assert_equal(<<HAML.rstrip, render_erb(<<ERB))
305
+ - foo do
306
+ blah
307
+ - end.bip do
308
+ brang
309
+ HAML
310
+ <% foo do %>
311
+ blah
312
+ <% end.bip do %>
313
+ brang
314
+ <% end %>
315
+ ERB
316
+ end
317
+
318
+ def test_multiline_block_opener
319
+ assert_equal(<<HAML.rstrip, render_erb(<<ERB))
320
+ - foo bar
321
+ - baz bang
322
+ - biddle do
323
+ foo
324
+ HAML
325
+ <% foo bar
326
+ baz bang
327
+ biddle do %>
328
+ foo
329
+ <% end %>
330
+ ERB
331
+ end
332
+
333
+ def test_if_elsif_else_parsing
334
+ assert_equal(<<HAML.rstrip, render_erb(<<ERB))
335
+ - if foo
336
+ %p bar
337
+ - elsif bar.foo("zip")
338
+ #bang baz
339
+ - else
340
+ %strong bibble
341
+ HAML
342
+ <% if foo %>
343
+ <p>bar</p>
344
+ <% elsif bar.foo("zip") %>
345
+ <div id="bang">baz</div>
346
+ <% else %>
347
+ <strong>bibble</strong>
348
+ <% end %>
349
+ ERB
350
+ end
351
+
352
+ def test_case_when_parsing
353
+ assert_equal(<<HAML.rstrip, render_erb(<<ERB))
354
+ - case foo.bar
355
+ - when "bip"
356
+ %p bip
357
+ - when "bop"
358
+ %p BOP
359
+ - when bizzle.bang.boop.blip
360
+ %em BIZZLE BANG BOOP BLIP
361
+ HAML
362
+ <% case foo.bar %>
363
+ <% when "bip" %>
364
+ <p>bip</p>
365
+ <% when "bop" %>
366
+ <p>BOP</p>
367
+ <% when bizzle.bang.boop.blip %>
368
+ <em>BIZZLE BANG BOOP BLIP</em>
369
+ <% end %>
370
+ ERB
371
+
372
+ assert_equal(<<HAML.rstrip, render_erb(<<ERB))
373
+ - case foo.bar
374
+ - when "bip"
375
+ %p bip
376
+ - when "bop"
377
+ %p BOP
378
+ - when bizzle.bang.boop.blip
379
+ %em BIZZLE BANG BOOP BLIP
380
+ HAML
381
+ <% case foo.bar
382
+ when "bip" %>
383
+ <p>bip</p>
384
+ <% when "bop" %>
385
+ <p>BOP</p>
386
+ <% when bizzle.bang.boop.blip %>
387
+ <em>BIZZLE BANG BOOP BLIP</em>
388
+ <% end %>
389
+ ERB
390
+ end
391
+
392
+ def test_begin_rescue_ensure
393
+ assert_equal(<<HAML.rstrip, render_erb(<<ERB))
394
+ - begin
395
+ %p a
396
+ - rescue FooException => e
397
+ %p b
398
+ - ensure
399
+ %p c
400
+ HAML
401
+ <% begin %>
402
+ <p>a</p>
403
+ <% rescue FooException => e %>
404
+ <p>b</p>
405
+ <% ensure %>
406
+ <p>c</p>
407
+ <% end %>
408
+ ERB
409
+ end
410
+ end
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  require File.dirname(__FILE__) + '/../test_helper'
3
+ require File.dirname(__FILE__) + '/html2haml/erb_tests'
3
4
  require 'haml/html'
4
5
 
5
6
  class Html2HamlTest < Test::Unit::TestCase
6
-
7
7
  def test_empty_render_should_remain_empty
8
8
  assert_equal '', render('')
9
9
  end
@@ -35,14 +35,21 @@ class Html2HamlTest < Test::Unit::TestCase
35
35
  end
36
36
 
37
37
  def test_should_have_pretty_attributes
38
- assert_equal_attributes('%input{ :type => "text", :name => "login" }',
38
+ assert_equal('%input{:name => "login", :type => "text"}/',
39
39
  render('<input type="text" name="login" />'))
40
- assert_equal_attributes('%meta{ "http-equiv" => "Content-Type", :content => "text/html" }',
40
+ assert_equal('%meta{:content => "text/html", "http-equiv" => "Content-Type"}/',
41
41
  render('<meta http-equiv="Content-Type" content="text/html" />'))
42
42
  end
43
43
 
44
- def test_sqml_comment
45
- assert_equal "/\n IE sucks", render('<!-- IE sucks -->')
44
+ def test_class_with_dot_and_hash
45
+ assert_equal('%div{:class => "foo.bar"}', render("<div class='foo.bar'></div>"))
46
+ assert_equal('%div{:class => "foo#bar"}', render("<div class='foo#bar'></div>"))
47
+ assert_equal('.foo.bar{:class => "foo#bar foo.bar"}', render("<div class='foo foo#bar bar foo.bar'></div>"))
48
+ end
49
+
50
+ def test_id_with_dot_and_hash
51
+ assert_equal('%div{:id => "foo.bar"}', render("<div id='foo.bar'></div>"))
52
+ assert_equal('%div{:id => "foo#bar"}', render("<div id='foo#bar'></div>"))
46
53
  end
47
54
 
48
55
  def test_interpolation
@@ -50,54 +57,7 @@ class Html2HamlTest < Test::Unit::TestCase
50
57
  end
51
58
 
52
59
  def test_interpolation_in_attrs
53
- assert_equal('%p{ :foo => "\#{bar} baz" }', render('<p foo="#{bar} baz"></p>'))
54
- end
55
-
56
- def test_rhtml
57
- assert_equal '- foo = bar', render_rhtml('<% foo = bar %>')
58
- assert_equal '- foo = bar', render_rhtml('<% foo = bar -%>')
59
- assert_equal '= h @item.title', render_rhtml('<%=h @item.title %>')
60
- assert_equal '= h @item.title', render_rhtml('<%=h @item.title -%>')
61
- end
62
-
63
- def test_rhtml_with_html_special_chars
64
- assert_equal '= 3 < 5 ? "OK" : "Your computer is b0rken"',
65
- render_rhtml(%Q{<%= 3 < 5 ? "OK" : "Your computer is b0rken" %>})
66
- end
67
-
68
- def test_rhtml_in_class_attribute
69
- assert_equal "%div{ :class => dyna_class }\n I have a dynamic attribute",
70
- render_rhtml(%Q{<div class="<%= dyna_class %>">I have a dynamic attribute</div>})
71
- end
72
-
73
- def test_rhtml_in_id_attribute
74
- assert_equal "%div{ :id => dyna_id }\n I have a dynamic attribute",
75
- render_rhtml(%Q{<div id="<%= dyna_id %>">I have a dynamic attribute</div>})
76
- end
77
-
78
- def test_rhtml_in_attribute_results_in_string_interpolation
79
- assert_equal %(%div{ :id => "item_\#{i}" }\n Ruby string interpolation FTW),
80
- render_rhtml(%Q{<div id="item_<%= i %>">Ruby string interpolation FTW</div>})
81
- end
82
-
83
- def test_rhtml_in_attribute_with_trailing_content
84
- assert_equal %(%div{ :class => "\#{12}!" }\n Bang!),
85
- render_rhtml(%Q{<div class="<%= 12 %>!">Bang!</div>})
86
- end
87
-
88
- def test_rhtml_in_html_escaped_attribute
89
- assert_equal %(%div{ :class => "foo" }\n Bang!),
90
- render_rhtml(%Q{<div class="<%= "foo" %>">Bang!</div>})
91
- end
92
-
93
- def test_rhtml_in_attribute_to_multiple_interpolations
94
- assert_equal %(%div{ :class => "\#{12} + \#{13}" }\n Math is super),
95
- render_rhtml(%Q{<div class="<%= 12 %> + <%= 13 %>">Math is super</div>})
96
- end
97
-
98
- def test_whitespace_eating_erb_tags
99
- assert_equal %(- form_for),
100
- render_rhtml(%Q{<%- form_for -%>})
60
+ assert_equal('%p{:foo => "\#{bar} baz"}', render('<p foo="#{bar} baz"></p>'))
101
61
  end
102
62
 
103
63
  def test_cdata
@@ -116,13 +76,203 @@ HAML
116
76
  HTML
117
77
  end
118
78
 
119
- def test_interpolation_in_rhtml
120
- assert_equal('= "Foo #{bar} baz"', render_rhtml('<%= "Foo #{bar} baz" %>'))
79
+ def test_self_closing_tag
80
+ assert_equal("%foo/", render("<foo />"))
81
+ end
82
+
83
+ def test_inline_text
84
+ assert_equal("%p foo", render("<p>foo</p>"))
85
+ end
86
+
87
+ def test_inline_comment
88
+ assert_equal("/ foo", render("<!-- foo -->"))
89
+ end
90
+
91
+ def test_non_inline_comment
92
+ assert_equal(<<HAML.rstrip, render(<<HTML))
93
+ /
94
+ Foo
95
+ Bar
96
+ HAML
97
+ <!-- Foo
98
+ Bar -->
99
+ HTML
100
+ end
101
+
102
+ def test_non_inline_text
103
+ assert_equal(<<HAML.rstrip, render(<<HTML))
104
+ %p
105
+ foo
106
+ HAML
107
+ <p>
108
+ foo
109
+ </p>
110
+ HTML
111
+ assert_equal(<<HAML.rstrip, render(<<HTML))
112
+ %p
113
+ foo
114
+ HAML
115
+ <p>
116
+ foo</p>
117
+ HTML
118
+ assert_equal(<<HAML.rstrip, render(<<HTML))
119
+ %p
120
+ foo
121
+ HAML
122
+ <p>foo
123
+ </p>
124
+ HTML
125
+ end
126
+
127
+ def test_script_tag
128
+ assert_equal(<<HAML.rstrip, render(<<HTML))
129
+ :javascript
130
+ function foo() {
131
+ return "12" & "13";
132
+ }
133
+ HAML
134
+ <script type="text/javascript">
135
+ function foo() {
136
+ return "12" &amp; "13";
137
+ }
138
+ </script>
139
+ HTML
140
+ end
141
+
142
+ def test_script_tag_with_cdata
143
+ assert_equal(<<HAML.rstrip, render(<<HTML))
144
+ :javascript
145
+ function foo() {
146
+ return "&amp;";
147
+ }
148
+ HAML
149
+ <script type="text/javascript">
150
+ <![CDATA[
151
+ function foo() {
152
+ return "&amp;";
153
+ }
154
+ ]]>
155
+ </script>
156
+ HTML
157
+ end
158
+
159
+ def test_pre
160
+ assert_equal(<<HAML.rstrip, render(<<HTML))
161
+ %pre
162
+ :preserve
163
+ foo
164
+ bar
165
+ baz
166
+ HAML
167
+ <pre>foo
168
+ bar
169
+ baz</pre>
170
+ HTML
171
+ end
172
+
173
+ def test_pre_code
174
+ assert_equal(<<HAML.rstrip, render(<<HTML))
175
+ %pre
176
+ %code
177
+ :preserve
178
+ foo
179
+ bar
180
+ baz
181
+ HAML
182
+ <pre><code>foo
183
+ bar
184
+ baz</code></pre>
185
+ HTML
186
+ end
187
+
188
+ def test_code_without_pre
189
+ assert_equal(<<HAML.rstrip, render(<<HTML))
190
+ %code
191
+ foo
192
+ bar
193
+ baz
194
+ HAML
195
+ <code>foo
196
+ bar
197
+ baz</code>
198
+ HTML
199
+ end
200
+
201
+ def test_conditional_comment
202
+ assert_equal(<<HAML.rstrip, render(<<HTML))
203
+ /[if foo]
204
+ bar
205
+ baz
206
+ HAML
207
+ <!--[if foo]>
208
+ bar
209
+ baz
210
+ <![endif]-->
211
+ HTML
212
+ end
213
+
214
+ def test_style_to_css_filter
215
+ assert_equal(<<HAML.rstrip, render_erb(<<HTML))
216
+ :css
217
+ foo {
218
+ bar: baz;
219
+ }
220
+ HAML
221
+ <style type="text/css">
222
+ foo {
223
+ bar: baz;
224
+ }
225
+ </style>
226
+ HTML
227
+ end
228
+
229
+ def test_inline_conditional_comment
230
+ assert_equal(<<HAML.rstrip, render(<<HTML))
231
+ /[if foo] bar baz
232
+ HAML
233
+ <!--[if foo]> bar baz <![endif]-->
234
+ HTML
121
235
  end
122
236
 
123
- def test_interpolation_in_rhtml_attrs
124
- assert_equal('%p{ :foo => "#{bar} baz" }',
125
- render_rhtml('<p foo="<%= "#{bar} baz" %>"></p>'))
237
+ def test_minus_in_tag
238
+ assert_equal("%p - foo bar -", render("<p>- foo bar -</p>"))
239
+ end
240
+
241
+ def test_equals_in_tag
242
+ assert_equal("%p = foo bar =", render("<p>= foo bar =</p>"))
243
+ end
244
+
245
+ def test_hash_in_tag
246
+ assert_equal("%p # foo bar #", render("<p># foo bar #</p>"))
247
+ end
248
+
249
+ begin
250
+ require 'haml/html/erb'
251
+ include ErbTests
252
+ rescue LoadError => e
253
+ puts "\n** Couldn't require #{e.message[/-- (.*)$/, 1]}, skipping some tests"
254
+ end
255
+
256
+ # Encodings
257
+
258
+ unless Haml::Util.ruby1_8?
259
+ def test_encoding_error
260
+ render("foo\nbar\nb\xFEaz".force_encoding("utf-8"))
261
+ assert(false, "Expected exception")
262
+ rescue Haml::Error => e
263
+ assert_equal(3, e.line)
264
+ assert_equal('Invalid UTF-8 character "\xFE"', e.message)
265
+ end
266
+
267
+ def test_ascii_incompatible_encoding_error
268
+ template = "foo\nbar\nb_z".encode("utf-16le")
269
+ template[9] = "\xFE".force_encoding("utf-16le")
270
+ render(template)
271
+ assert(false, "Expected exception")
272
+ rescue Haml::Error => e
273
+ assert_equal(3, e.line)
274
+ assert_equal('Invalid UTF-16LE character "\xFE"', e.message)
275
+ end
126
276
  end
127
277
 
128
278
  # Regression Tests
@@ -140,13 +290,7 @@ HTML
140
290
  Haml::HTML.new(text, options).render.rstrip
141
291
  end
142
292
 
143
- def render_rhtml(text)
144
- render(text, :rhtml => true)
145
- end
146
-
147
- def assert_equal_attributes(expected, result)
148
- expected_attr, result_attr = [expected, result].map { |s| s.gsub!(/\{ (.+) \}/, ''); $1.split(', ').sort }
149
- assert_equal expected_attr, result_attr
150
- assert_equal expected, result
293
+ def render_erb(text)
294
+ render(text, :erb => true)
151
295
  end
152
296
  end