haml 3.2.0.alpha.14 → 3.2.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.
- data/CHANGELOG.md +7 -0
- data/REFERENCE.md +11 -9
- data/lib/haml/compiler.rb +2 -2
- data/lib/haml/error.rb +40 -1
- data/lib/haml/exec.rb +15 -3
- data/lib/haml/filters.rb +20 -17
- data/lib/haml/helpers.rb +3 -3
- data/lib/haml/options.rb +28 -10
- data/lib/haml/parser.rb +66 -39
- data/lib/haml/template.rb +1 -2
- data/lib/haml/util.rb +3 -9
- data/lib/haml/version.rb +1 -1
- data/test/engine_test.rb +110 -106
- data/test/filters_test.rb +97 -5
- data/test/gemfiles/Gemfile.rails-3.0.x +0 -1
- data/test/gemfiles/Gemfile.rails-3.1.x +0 -1
- data/test/gemfiles/Gemfile.rails-3.2.x +0 -1
- data/test/haml-spec/tests.json +62 -14
- data/test/helper_test.rb +1 -1
- data/test/parser_test.rb +59 -0
- data/test/template_test.rb +3 -2
- data/test/test_helper.rb +7 -2
- metadata +93 -136
- data/test/gemfiles/Gemfile.rails-3.0.x.lock +0 -101
- data/test/gemfiles/Gemfile.rails-3.1.x.lock +0 -111
- data/test/gemfiles/Gemfile.rails-3.2.x.lock +0 -109
data/lib/haml/template.rb
CHANGED
data/lib/haml/util.rb
CHANGED
@@ -304,23 +304,17 @@ METHOD
|
|
304
304
|
# @param was [Boolean] Whether or not to add `"was"` or `"were"`
|
305
305
|
# (depending on how many characters were in `indentation`)
|
306
306
|
# @return [String] The name of the indentation (e.g. `"12 spaces"`, `"1 tab"`)
|
307
|
-
def human_indentation(indentation
|
307
|
+
def human_indentation(indentation)
|
308
308
|
if !indentation.include?(?\t)
|
309
309
|
noun = 'space'
|
310
310
|
elsif !indentation.include?(?\s)
|
311
311
|
noun = 'tab'
|
312
312
|
else
|
313
|
-
return indentation.inspect
|
313
|
+
return indentation.inspect
|
314
314
|
end
|
315
315
|
|
316
316
|
singular = indentation.length == 1
|
317
|
-
|
318
|
-
was = singular ? ' was' : ' were'
|
319
|
-
else
|
320
|
-
was = ''
|
321
|
-
end
|
322
|
-
|
323
|
-
"#{indentation.length} #{noun}#{'s' unless singular}#{was}"
|
317
|
+
"#{indentation.length} #{noun}#{'s' unless singular}"
|
324
318
|
end
|
325
319
|
|
326
320
|
def contains_interpolation?(str)
|
data/lib/haml/version.rb
CHANGED
data/test/engine_test.rb
CHANGED
@@ -7,85 +7,77 @@ class EngineTest < MiniTest::Unit::TestCase
|
|
7
7
|
# if so, the second element should be the line number that should be reported for the error.
|
8
8
|
# If this isn't provided, the tests will assume the line number should be the last line of the document.
|
9
9
|
EXCEPTION_MAP = {
|
10
|
-
"!!!\n a"
|
11
|
-
"a\n b"
|
12
|
-
"/ a\n b"
|
13
|
-
"% a"
|
14
|
-
"%p a\n b"
|
15
|
-
"%p="
|
16
|
-
"%p~"
|
17
|
-
"~"
|
18
|
-
"="
|
19
|
-
"%p/\n a"
|
20
|
-
":a\n b"
|
21
|
-
":a= b"
|
22
|
-
"."
|
23
|
-
".#"
|
24
|
-
".{} a"
|
25
|
-
".() a"
|
26
|
-
".= a"
|
27
|
-
"%p..a"
|
28
|
-
"%a/ b"
|
29
|
-
"%p
|
30
|
-
"%p
|
31
|
-
"
|
32
|
-
"%p{:a => 'b',\n:c => 'd'
|
10
|
+
"!!!\n a" => error(:illegal_nesting_header),
|
11
|
+
"a\n b" => error(:illegal_nesting_plain),
|
12
|
+
"/ a\n b" => error(:illegal_nesting_content),
|
13
|
+
"% a" => error(:invalid_tag, '% a'),
|
14
|
+
"%p a\n b" => error(:illegal_nesting_line, 'p'),
|
15
|
+
"%p=" => error(:no_ruby_code, '='),
|
16
|
+
"%p~" => error(:no_ruby_code, '~'),
|
17
|
+
"~" => error(:no_ruby_code, '~'),
|
18
|
+
"=" => error(:no_ruby_code, '='),
|
19
|
+
"%p/\n a" => error(:illegal_nesting_self_closing),
|
20
|
+
":a\n b" => [error(:filter_not_defined, 'a'), 1],
|
21
|
+
":a= b" => error(:invalid_filter_name, 'a= b'),
|
22
|
+
"." => error(:illegal_element),
|
23
|
+
".#" => error(:illegal_element),
|
24
|
+
".{} a" => error(:illegal_element),
|
25
|
+
".() a" => error(:illegal_element),
|
26
|
+
".= a" => error(:illegal_element),
|
27
|
+
"%p..a" => error(:illegal_element),
|
28
|
+
"%a/ b" => error(:self_closing_content),
|
29
|
+
" %p foo" => error(:indenting_at_start),
|
30
|
+
" %p foo" => error(:indenting_at_start),
|
31
|
+
"- end" => error(:no_end),
|
32
|
+
"%p{:a => 'b',\n:c => 'd'}/ e" => [error(:self_closing_content), 2],
|
33
|
+
"%p{:a => 'b',\n:c => 'd'}=" => [error(:no_ruby_code, '='), 2],
|
34
|
+
"%p.{:a => 'b',\n:c => 'd'} e" => [error(:illegal_element), 1],
|
35
|
+
"%p{:a => 'b',\n:c => 'd',\n:e => 'f'}\n%p/ a" => [error(:self_closing_content), 4],
|
33
36
|
"%p{:a => 'b',\n:c => 'd',\n:e => 'f'}\n- raise 'foo'" => ["foo", 4],
|
34
|
-
"%p{:a => 'b',\n:c => raise('foo'),\n:e => 'f'}"
|
35
|
-
"%p{:a => 'b',\n:c => 'd',\n:e => raise('foo')}"
|
36
|
-
" %p foo"
|
37
|
-
"
|
38
|
-
"
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
%p
|
45
|
-
|
46
|
-
"
|
47
|
-
"
|
48
|
-
"%p
|
49
|
-
"%p
|
50
|
-
"%p
|
51
|
-
"%p
|
52
|
-
"%p
|
53
|
-
"%p
|
54
|
-
"%p
|
55
|
-
"%p
|
56
|
-
"%p
|
57
|
-
"%p
|
58
|
-
"%p
|
59
|
-
"%p(foo=)" => "Invalid attribute list: \"(foo=)\".",
|
60
|
-
"%p(foo 'bar')" => "Invalid attribute list: \"(foo 'bar')\".",
|
61
|
-
"%p(foo 'bar'\nbaz='bang')" => ["Invalid attribute list: \"(foo 'bar'\".", 1],
|
62
|
-
"%p(foo='bar'\nbaz 'bang'\nbip='bop')" => ["Invalid attribute list: \"(foo='bar' baz 'bang'\".", 2],
|
63
|
-
"%p{'foo' => 'bar' 'bar' => 'baz'}" => :compile,
|
64
|
-
"%p{:foo => }" => :compile,
|
65
|
-
"%p{=> 'bar'}" => :compile,
|
66
|
-
"%p{'foo => 'bar'}" => :compile,
|
67
|
-
"%p{:foo => 'bar}" => :compile,
|
68
|
-
"%p{:foo => 'bar\"}" => :compile,
|
69
|
-
|
37
|
+
"%p{:a => 'b',\n:c => raise('foo'),\n:e => 'f'}" => ["foo", 2],
|
38
|
+
"%p{:a => 'b',\n:c => 'd',\n:e => raise('foo')}" => ["foo", 3],
|
39
|
+
" \n\t\n %p foo" => [error(:indenting_at_start), 3],
|
40
|
+
"\n\n %p foo" => [error(:indenting_at_start), 3],
|
41
|
+
"%p\n foo\n foo" => [error(:inconsistent_indentation, "1 space", "2 spaces"), 3],
|
42
|
+
"%p\n foo\n%p\n foo" => [error(:inconsistent_indentation, "1 space", "2 spaces"), 4],
|
43
|
+
"%p\n\t\tfoo\n\tfoo" => [error(:inconsistent_indentation, "1 tab", "2 tabs"), 3],
|
44
|
+
"%p\n foo\n foo" => [error(:inconsistent_indentation, "3 spaces", "2 spaces"), 3],
|
45
|
+
"%p\n foo\n %p\n bar" => [error(:inconsistent_indentation, "3 spaces", "2 spaces"), 4],
|
46
|
+
"%p\n :plain\n bar\n \t baz" => [error(:inconsistent_indentation, '" \t "', "2 spaces"), 4],
|
47
|
+
"%p\n foo\n%p\n bar" => [error(:deeper_indenting, 2), 4],
|
48
|
+
"%p\n foo\n %p\n bar" => [error(:deeper_indenting, 3), 4],
|
49
|
+
"%p\n \tfoo" => [error(:cant_use_tabs_and_spaces), 2],
|
50
|
+
"%p(" => error(:invalid_attribute_list, '"("'),
|
51
|
+
"%p(foo=)" => error(:invalid_attribute_list, '"(foo=)"'),
|
52
|
+
"%p(foo 'bar')" => error(:invalid_attribute_list, '"(foo \'bar\')"'),
|
53
|
+
"%p(foo=\nbar)" => [error(:invalid_attribute_list, '"(foo="'), 1],
|
54
|
+
"%p(foo 'bar'\nbaz='bang')" => [error(:invalid_attribute_list, '"(foo \'bar\'"'), 1],
|
55
|
+
"%p(foo='bar'\nbaz 'bang'\nbip='bop')" => [error(:invalid_attribute_list, '"(foo=\'bar\' baz \'bang\'"'), 2],
|
56
|
+
"%p{'foo' => 'bar' 'bar' => 'baz'}" => :compile,
|
57
|
+
"%p{:foo => }" => :compile,
|
58
|
+
"%p{=> 'bar'}" => :compile,
|
59
|
+
"%p{'foo => 'bar'}" => :compile,
|
60
|
+
"%p{:foo => 'bar}" => :compile,
|
61
|
+
"%p{:foo => 'bar\"}" => :compile,
|
70
62
|
# Regression tests
|
71
|
-
"
|
72
|
-
"
|
73
|
-
"\n\n
|
74
|
-
"
|
75
|
-
"
|
76
|
-
"
|
77
|
-
"
|
78
|
-
"
|
79
|
-
"
|
80
|
-
"foo\n:ruby\n 1\n 2\n 3\n- raise 'foo'"
|
81
|
-
"foo\n:erb\n 1\n 2\n 3\n- raise 'foo'"
|
82
|
-
"foo\n:plain\n 1\n 2\n 3\n- raise 'foo'"
|
83
|
-
"foo\n:plain\n 1\n 2\n 3\n4\n- raise 'foo'"
|
84
|
-
"foo\n:plain\n 1\n 2\n 3\#{''}\n- raise 'foo'"
|
85
|
-
"foo\n:plain\n 1\n 2\n 3\#{''}\n4\n- raise 'foo'"
|
86
|
-
"foo\n:plain\n 1\n 2\n \#{raise 'foo'}"
|
87
|
-
"= raise 'foo'\nfoo\nbar\nbaz\nbang"
|
88
|
-
"- case 1\n\n- when 1\n - raise 'foo'"
|
63
|
+
"foo\n\n\n bar" => [error(:illegal_nesting_plain), 4],
|
64
|
+
"%p/\n\n bar" => [error(:illegal_nesting_self_closing), 3],
|
65
|
+
"%p foo\n\n bar" => [error(:illegal_nesting_line, 'p'), 3],
|
66
|
+
"/ foo\n\n bar" => [error(:illegal_nesting_content), 3],
|
67
|
+
"!!!\n\n bar" => [error(:illegal_nesting_header), 3],
|
68
|
+
"- raise 'foo'\n\n\n\nbar" => ["foo", 1],
|
69
|
+
"= 'foo'\n-raise 'foo'" => ["foo", 2],
|
70
|
+
"\n\n\n- raise 'foo'" => ["foo", 4],
|
71
|
+
"%p foo |\n bar |\n baz |\nbop\n- raise 'foo'" => ["foo", 5],
|
72
|
+
"foo\n:ruby\n 1\n 2\n 3\n- raise 'foo'" => ["foo", 6],
|
73
|
+
"foo\n:erb\n 1\n 2\n 3\n- raise 'foo'" => ["foo", 6],
|
74
|
+
"foo\n:plain\n 1\n 2\n 3\n- raise 'foo'" => ["foo", 6],
|
75
|
+
"foo\n:plain\n 1\n 2\n 3\n4\n- raise 'foo'" => ["foo", 7],
|
76
|
+
"foo\n:plain\n 1\n 2\n 3\#{''}\n- raise 'foo'" => ["foo", 6],
|
77
|
+
"foo\n:plain\n 1\n 2\n 3\#{''}\n4\n- raise 'foo'" => ["foo", 7],
|
78
|
+
"foo\n:plain\n 1\n 2\n \#{raise 'foo'}" => ["foo", 5],
|
79
|
+
"= raise 'foo'\nfoo\nbar\nbaz\nbang" => ["foo", 1],
|
80
|
+
"- case 1\n\n- when 1\n - raise 'foo'" => ["foo", 4],
|
89
81
|
}
|
90
82
|
|
91
83
|
User = Struct.new('User', :id)
|
@@ -181,11 +173,11 @@ MESSAGE
|
|
181
173
|
end
|
182
174
|
|
183
175
|
def test_colon_in_class_attr
|
184
|
-
assert_equal("<p class='foo:bar'
|
176
|
+
assert_equal("<p class='foo:bar'>\n", render("%p.foo:bar/"))
|
185
177
|
end
|
186
178
|
|
187
179
|
def test_colon_in_id_attr
|
188
|
-
assert_equal("<p id='foo:bar'
|
180
|
+
assert_equal("<p id='foo:bar'>\n", render("%p#foo:bar/"))
|
189
181
|
end
|
190
182
|
|
191
183
|
def test_dynamic_attributes_with_no_content
|
@@ -266,17 +258,17 @@ HAML
|
|
266
258
|
end
|
267
259
|
|
268
260
|
def test_static_attributes_with_empty_attr
|
269
|
-
assert_equal("<img alt='' src='/foo.png'
|
261
|
+
assert_equal("<img alt='' src='/foo.png'>\n", render("%img{:src => '/foo.png', :alt => ''}"))
|
270
262
|
end
|
271
263
|
|
272
264
|
def test_dynamic_attributes_with_empty_attr
|
273
|
-
assert_equal("<img alt='' src='/foo.png'
|
265
|
+
assert_equal("<img alt='' src='/foo.png'>\n", render("%img{:width => nil, :src => '/foo.png', :alt => String.new}"))
|
274
266
|
end
|
275
267
|
|
276
268
|
def test_attribute_hash_with_newlines
|
277
269
|
assert_equal("<p a='b' c='d'>foop</p>\n", render("%p{:a => 'b',\n :c => 'd'} foop"))
|
278
270
|
assert_equal("<p a='b' c='d'>\n foop\n</p>\n", render("%p{:a => 'b',\n :c => 'd'}\n foop"))
|
279
|
-
assert_equal("<p a='b' c='d'
|
271
|
+
assert_equal("<p a='b' c='d'>\n", render("%p{:a => 'b',\n :c => 'd'}/"))
|
280
272
|
assert_equal("<p a='b' c='d' e='f'></p>\n", render("%p{:a => 'b',\n :c => 'd',\n :e => 'f'}"))
|
281
273
|
end
|
282
274
|
|
@@ -298,7 +290,7 @@ HAML
|
|
298
290
|
assert_equal(<<HTML, render(<<HAML, :ugly => true))
|
299
291
|
<p a='2'></p>
|
300
292
|
<p a='2'>foo</p>
|
301
|
-
<p a='2'
|
293
|
+
<p a='2'>
|
302
294
|
<p a='2'>foo</p>
|
303
295
|
<p a='2'>foo
|
304
296
|
bar</p>
|
@@ -416,7 +408,7 @@ HAML
|
|
416
408
|
assert_equal(<<HTML, render(<<HAML))
|
417
409
|
<html>
|
418
410
|
<body>
|
419
|
-
<img src='test'
|
411
|
+
<img src='test'>
|
420
412
|
foo
|
421
413
|
bar
|
422
414
|
</body>
|
@@ -917,7 +909,7 @@ HAML
|
|
917
909
|
end
|
918
910
|
|
919
911
|
def test_static_attributes_should_be_escaped
|
920
|
-
assert_equal("<img class='atlantis' style='ugly&stupid'
|
912
|
+
assert_equal("<img class='atlantis' style='ugly&stupid'>\n",
|
921
913
|
render("%img.atlantis{:style => 'ugly&stupid'}"))
|
922
914
|
assert_equal("<div class='atlantis' style='ugly&stupid'>foo</div>\n",
|
923
915
|
render(".atlantis{:style => 'ugly&stupid'} foo"))
|
@@ -928,13 +920,13 @@ HAML
|
|
928
920
|
end
|
929
921
|
|
930
922
|
def test_dynamic_attributes_should_be_escaped
|
931
|
-
assert_equal("<img alt='' src='&foo.png'
|
923
|
+
assert_equal("<img alt='' src='&foo.png'>\n",
|
932
924
|
render("%img{:width => nil, :src => '&foo.png', :alt => String.new}"))
|
933
925
|
assert_equal("<p alt='' src='&foo.png'>foo</p>\n",
|
934
926
|
render("%p{:width => nil, :src => '&foo.png', :alt => String.new} foo"))
|
935
927
|
assert_equal("<div alt='' src='&foo.png'>foo</div>\n",
|
936
928
|
render("%div{:width => nil, :src => '&foo.png', :alt => String.new}= 'foo'"))
|
937
|
-
assert_equal("<img alt='' src='foo
.png'
|
929
|
+
assert_equal("<img alt='' src='foo
.png'>\n",
|
938
930
|
render("%img{:width => nil, :src => \"foo\\n.png\", :alt => String.new}"))
|
939
931
|
end
|
940
932
|
|
@@ -1035,9 +1027,9 @@ HAML
|
|
1035
1027
|
def test_stop_eval
|
1036
1028
|
assert_equal("", render("= 'Hello'", :suppress_eval => true))
|
1037
1029
|
assert_equal("", render("- haml_concat 'foo'", :suppress_eval => true))
|
1038
|
-
assert_equal("<div id='foo' yes='no'
|
1039
|
-
assert_equal("<div id='foo'
|
1040
|
-
assert_equal("<div
|
1030
|
+
assert_equal("<div id='foo' yes='no'>\n", render("#foo{:yes => 'no'}/", :suppress_eval => true))
|
1031
|
+
assert_equal("<div id='foo'>\n", render("#foo{:yes => 'no', :call => a_function() }/", :suppress_eval => true))
|
1032
|
+
assert_equal("<div>\n", render("%div[1]/", :suppress_eval => true))
|
1041
1033
|
assert_equal("", render(":ruby\n Kernel.puts 'hello'", :suppress_eval => true))
|
1042
1034
|
end
|
1043
1035
|
|
@@ -1046,17 +1038,17 @@ HAML
|
|
1046
1038
|
render('!!!', :format => :html5).strip)
|
1047
1039
|
assert_equal('<!DOCTYPE html>', render('!!! 5').strip)
|
1048
1040
|
assert_equal('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
|
1049
|
-
render('!!! strict').strip)
|
1041
|
+
render('!!! strict', :format => :xhtml).strip)
|
1050
1042
|
assert_equal('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
|
1051
|
-
render('!!! frameset').strip)
|
1043
|
+
render('!!! frameset', :format => :xhtml).strip)
|
1052
1044
|
assert_equal('<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">',
|
1053
|
-
render('!!! mobile').strip)
|
1045
|
+
render('!!! mobile', :format => :xhtml).strip)
|
1054
1046
|
assert_equal('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
|
1055
|
-
render('!!! basic').strip)
|
1047
|
+
render('!!! basic', :format => :xhtml).strip)
|
1056
1048
|
assert_equal('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
|
1057
|
-
render('!!! transitional').strip)
|
1049
|
+
render('!!! transitional', :format => :xhtml).strip)
|
1058
1050
|
assert_equal('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
|
1059
|
-
render('!!!').strip)
|
1051
|
+
render('!!!', :format => :xhtml).strip)
|
1060
1052
|
assert_equal('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
|
1061
1053
|
render('!!! strict', :format => :html4).strip)
|
1062
1054
|
assert_equal('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
|
@@ -1072,14 +1064,14 @@ HAML
|
|
1072
1064
|
assert_equal("<p escaped='quo\"te'></p>\n", render("%p{ :escaped => 'quo\"te'}", :attr_wrapper => '"'))
|
1073
1065
|
assert_equal("<p escaped=\"quo'te\"></p>\n", render("%p{ :escaped => 'quo\\'te'}", :attr_wrapper => '"'))
|
1074
1066
|
assert_equal("<p escaped=\"q'uo"te\"></p>\n", render("%p{ :escaped => 'q\\'uo\"te'}", :attr_wrapper => '"'))
|
1075
|
-
assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n", render("!!! XML", :attr_wrapper => '"'))
|
1067
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n", render("!!! XML", :attr_wrapper => '"', :format => :xhtml))
|
1076
1068
|
end
|
1077
1069
|
|
1078
1070
|
def test_autoclose_option
|
1079
|
-
assert_equal("<flaz foo='bar'
|
1071
|
+
assert_equal("<flaz foo='bar'>\n", render("%flaz{:foo => 'bar'}", :autoclose => ["flaz"]))
|
1080
1072
|
assert_equal(<<HTML, render(<<HAML, :autoclose => [/^flaz/]))
|
1081
|
-
<flaz
|
1082
|
-
<flaznicate
|
1073
|
+
<flaz>
|
1074
|
+
<flaznicate>
|
1083
1075
|
<flan></flan>
|
1084
1076
|
HTML
|
1085
1077
|
%flaz
|
@@ -1148,7 +1140,7 @@ HAML
|
|
1148
1140
|
end
|
1149
1141
|
|
1150
1142
|
def test_dynamic_attrs_with_self_closed_tag
|
1151
|
-
assert_equal("<a b='2'
|
1143
|
+
assert_equal("<a b='2'>\nc\n", render("%a{'b' => 1 + 1}/\n= 'c'\n"))
|
1152
1144
|
end
|
1153
1145
|
|
1154
1146
|
EXCEPTION_MAP.each do |key, value|
|
@@ -1206,7 +1198,7 @@ HAML
|
|
1206
1198
|
def test_unbalanced_brackets
|
1207
1199
|
render('foo #{1 + 5} foo #{6 + 7 bar #{8 + 9}')
|
1208
1200
|
rescue Haml::SyntaxError => e
|
1209
|
-
assert_equal(
|
1201
|
+
assert_equal(Haml::Error.message(:unbalanced_brackets), e.message)
|
1210
1202
|
end
|
1211
1203
|
|
1212
1204
|
def test_balanced_conditional_comments
|
@@ -1244,8 +1236,8 @@ HAML
|
|
1244
1236
|
end
|
1245
1237
|
|
1246
1238
|
def test_non_literal_attributes
|
1247
|
-
assert_equal("<p a1='foo' a2='bar' a3='baz'
|
1248
|
-
render("%p{a2, a1, :a3 => 'baz'}
|
1239
|
+
assert_equal("<p a1='foo' a2='bar' a3='baz'></p>\n",
|
1240
|
+
render("%p{a2, a1, :a3 => 'baz'}",
|
1249
1241
|
:locals => {:a1 => {:a1 => 'foo'}, :a2 => {:a2 => 'bar'}}))
|
1250
1242
|
end
|
1251
1243
|
|
@@ -1561,9 +1553,9 @@ HAML
|
|
1561
1553
|
end
|
1562
1554
|
|
1563
1555
|
def test_truthy_new_attributes
|
1564
|
-
assert_equal("<a href='href'>bar</a>\n", render("%a(href) bar"))
|
1556
|
+
assert_equal("<a href='href'>bar</a>\n", render("%a(href) bar", :format => :xhtml))
|
1565
1557
|
assert_equal("<a bar='baz' href>bar</a>\n", render("%a(href bar='baz') bar", :format => :html5))
|
1566
|
-
assert_equal("<a href
|
1558
|
+
assert_equal("<a href>bar</a>\n", render("%a(href=true) bar"))
|
1567
1559
|
assert_equal("<a>bar</a>\n", render("%a(href=false) bar"))
|
1568
1560
|
end
|
1569
1561
|
|
@@ -1931,6 +1923,18 @@ HAML
|
|
1931
1923
|
end
|
1932
1924
|
end
|
1933
1925
|
|
1926
|
+
def test_block_spacing
|
1927
|
+
begin
|
1928
|
+
assert render(<<-HAML)
|
1929
|
+
- foo = ["bar", "baz", "kni"]
|
1930
|
+
- foo.each do | item |
|
1931
|
+
= item
|
1932
|
+
HAML
|
1933
|
+
rescue ::SyntaxError => e
|
1934
|
+
flunk("Should not have raised syntax error")
|
1935
|
+
end
|
1936
|
+
end
|
1937
|
+
|
1934
1938
|
private
|
1935
1939
|
|
1936
1940
|
def assert_valid_encoding_comment(comment)
|
data/test/filters_test.rb
CHANGED
@@ -24,6 +24,48 @@ class FiltersTest < MiniTest::Unit::TestCase
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
test "should raise error when a Tilt filters dependencies are unavailable for extension" do
|
28
|
+
begin
|
29
|
+
assert_raises Haml::Error do
|
30
|
+
Haml::Filters.register_tilt_filter "Textile"
|
31
|
+
Haml::Filters.defined["textile"].template_class
|
32
|
+
end
|
33
|
+
ensure
|
34
|
+
Haml::Filters.defined.delete "textile"
|
35
|
+
Haml::Filters.send :remove_const, :Textile
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
test "should raise error when a Tilt filters dependencies are unavailable for filter without extension" do
|
40
|
+
begin
|
41
|
+
assert_raises Haml::Error do
|
42
|
+
Haml::Filters.register_tilt_filter "Maruku"
|
43
|
+
Haml::Filters.defined["maruku"].template_class
|
44
|
+
end
|
45
|
+
ensure
|
46
|
+
Haml::Filters.defined.delete "maruku"
|
47
|
+
Haml::Filters.send :remove_const, :Maruku
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
test "should raise informative error about Maruku being moved to haml-contrib" do
|
52
|
+
begin
|
53
|
+
render(":maruku\n # foo")
|
54
|
+
flunk("Should have raised error with message about the haml-contrib gem.")
|
55
|
+
rescue Haml::Error => e
|
56
|
+
assert_equal e.message, Haml::Error.message(:install_haml_contrib, "maruku")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
test "should raise informative error about Textile being moved to haml-contrib" do
|
61
|
+
begin
|
62
|
+
render(":textile\n h1. foo")
|
63
|
+
flunk("Should have raised error with message about the haml-contrib gem.")
|
64
|
+
rescue Haml::Error => e
|
65
|
+
assert_equal e.message, Haml::Error.message(:install_haml_contrib, "textile")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
27
69
|
test "should respect escaped newlines and interpolation" do
|
28
70
|
html = "\\n\n"
|
29
71
|
haml = ":plain\n \\n\#{""}"
|
@@ -98,30 +140,80 @@ class JavascriptFilterTest < MiniTest::Unit::TestCase
|
|
98
140
|
end
|
99
141
|
|
100
142
|
test "should never HTML-escape ampersands" do
|
101
|
-
html = "<script
|
143
|
+
html = "<script>\n & < > &\n</script>\n"
|
102
144
|
haml = %Q{:javascript\n & < > \#{"&"}}
|
103
145
|
assert_equal(html, render(haml, :escape_html => true))
|
104
146
|
end
|
105
147
|
|
106
148
|
test "should not include type in HTML 5 output" do
|
107
|
-
html = "<script>\n
|
149
|
+
html = "<script>\n foo bar\n</script>\n"
|
108
150
|
haml = ":javascript\n foo bar"
|
109
151
|
assert_equal(html, render(haml, :format => :html5))
|
110
152
|
end
|
153
|
+
|
154
|
+
test "should always include CDATA when format is xhtml" do
|
155
|
+
html = "<script type='text/javascript'>\n //<![CDATA[\n foo bar\n //]]>\n</script>\n"
|
156
|
+
haml = ":javascript\n foo bar"
|
157
|
+
assert_equal(html, render(haml, :format => :xhtml, :cdata => false))
|
158
|
+
end
|
159
|
+
|
160
|
+
test "should omit CDATA when cdata option is false" do
|
161
|
+
html = "<script>\n foo bar\n</script>\n"
|
162
|
+
haml = ":javascript\n foo bar"
|
163
|
+
assert_equal(html, render(haml, :format => :html5, :cdata => false))
|
164
|
+
end
|
165
|
+
|
166
|
+
test "should include CDATA when cdata option is true" do
|
167
|
+
html = "<script>\n //<![CDATA[\n foo bar\n //]]>\n</script>\n"
|
168
|
+
haml = ":javascript\n foo bar"
|
169
|
+
assert_equal(html, render(haml, :format => :html5, :cdata => true))
|
170
|
+
end
|
171
|
+
|
172
|
+
test "should default to no CDATA when format is html5" do
|
173
|
+
haml = ":javascript\n foo bar"
|
174
|
+
out = render(haml, :format => :html5)
|
175
|
+
refute_match('//<![CDATA[', out)
|
176
|
+
refute_match('//]]>', out)
|
177
|
+
end
|
111
178
|
end
|
112
179
|
|
113
180
|
class CSSFilterTest < MiniTest::Unit::TestCase
|
114
|
-
test "should wrap output in CDATA and a CSS tag" do
|
181
|
+
test "should wrap output in CDATA and a CSS tag when output is XHTML" do
|
115
182
|
html = "<style type='text/css'>\n /*<![CDATA[*/\n foo\n /*]]>*/\n</style>\n"
|
116
183
|
haml = ":css\n foo"
|
117
|
-
assert_equal(html, render(haml))
|
184
|
+
assert_equal(html, render(haml, :format => :xhtml))
|
118
185
|
end
|
119
186
|
|
120
187
|
test "should not include type in HTML 5 output" do
|
121
|
-
html = "<style>\n
|
188
|
+
html = "<style>\n foo bar\n</style>\n"
|
122
189
|
haml = ":css\n foo bar"
|
123
190
|
assert_equal(html, render(haml, :format => :html5))
|
124
191
|
end
|
192
|
+
|
193
|
+
test "should always include CDATA when format is xhtml" do
|
194
|
+
html = "<style type='text/css'>\n /*<![CDATA[*/\n foo bar\n /*]]>*/\n</style>\n"
|
195
|
+
haml = ":css\n foo bar"
|
196
|
+
assert_equal(html, render(haml, :format => :xhtml, :cdata => false))
|
197
|
+
end
|
198
|
+
|
199
|
+
test "should omit CDATA when cdata option is false" do
|
200
|
+
html = "<style>\n foo bar\n</style>\n"
|
201
|
+
haml = ":css\n foo bar"
|
202
|
+
assert_equal(html, render(haml, :format => :html5, :cdata => false))
|
203
|
+
end
|
204
|
+
|
205
|
+
test "should include CDATA when cdata option is true" do
|
206
|
+
html = "<style>\n /*<![CDATA[*/\n foo bar\n /*]]>*/\n</style>\n"
|
207
|
+
haml = ":css\n foo bar"
|
208
|
+
assert_equal(html, render(haml, :format => :html5, :cdata => true))
|
209
|
+
end
|
210
|
+
|
211
|
+
test "should default to no CDATA when format is html5" do
|
212
|
+
haml = ":css\n foo bar"
|
213
|
+
out = render(haml, :format => :html5)
|
214
|
+
refute_match('<![CDATA[', out)
|
215
|
+
refute_match(']]>', out)
|
216
|
+
end
|
125
217
|
end
|
126
218
|
|
127
219
|
class CDATAFilterTest < MiniTest::Unit::TestCase
|