haml 4.1.0.beta.1 → 5.0.0.beta.2

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 (75) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +36 -6
  4. data/FAQ.md +4 -14
  5. data/MIT-LICENSE +1 -1
  6. data/README.md +81 -48
  7. data/REFERENCE.md +86 -50
  8. data/Rakefile +28 -41
  9. data/lib/haml/attribute_builder.rb +163 -0
  10. data/lib/haml/attribute_compiler.rb +214 -0
  11. data/lib/haml/attribute_parser.rb +112 -0
  12. data/lib/haml/buffer.rb +24 -126
  13. data/lib/haml/compiler.rb +62 -281
  14. data/lib/haml/engine.rb +16 -23
  15. data/lib/haml/error.rb +2 -0
  16. data/lib/haml/escapable.rb +48 -0
  17. data/lib/haml/exec.rb +23 -12
  18. data/lib/haml/filters.rb +3 -4
  19. data/lib/haml/generator.rb +36 -0
  20. data/lib/haml/helpers.rb +61 -48
  21. data/lib/haml/helpers/action_view_extensions.rb +1 -1
  22. data/lib/haml/helpers/action_view_mods.rb +32 -50
  23. data/lib/haml/helpers/safe_erubi_template.rb +26 -0
  24. data/lib/haml/helpers/safe_erubis_template.rb +2 -0
  25. data/lib/haml/helpers/xss_mods.rb +17 -12
  26. data/lib/haml/options.rb +32 -36
  27. data/lib/haml/parser.rb +61 -38
  28. data/lib/haml/{template/plugin.rb → plugin.rb} +5 -2
  29. data/lib/haml/railtie.rb +14 -6
  30. data/lib/haml/template.rb +11 -6
  31. data/lib/haml/temple_engine.rb +119 -0
  32. data/lib/haml/temple_line_counter.rb +28 -0
  33. data/lib/haml/util.rb +17 -112
  34. data/lib/haml/version.rb +1 -1
  35. data/test/attribute_parser_test.rb +105 -0
  36. data/test/engine_test.rb +202 -106
  37. data/test/filters_test.rb +32 -19
  38. data/test/gemfiles/Gemfile.rails-4.0.x +7 -1
  39. data/test/gemfiles/Gemfile.rails-4.0.x.lock +57 -71
  40. data/test/gemfiles/Gemfile.rails-4.1.x +5 -0
  41. data/test/gemfiles/Gemfile.rails-4.2.x +5 -0
  42. data/test/gemfiles/Gemfile.rails-5.0.x +4 -0
  43. data/test/helper_test.rb +156 -109
  44. data/test/options_test.rb +21 -0
  45. data/test/parser_test.rb +49 -4
  46. data/test/results/eval_suppressed.xhtml +4 -4
  47. data/test/results/helpers.xhtml +43 -41
  48. data/test/results/helpful.xhtml +6 -3
  49. data/test/results/just_stuff.xhtml +21 -20
  50. data/test/results/list.xhtml +9 -9
  51. data/test/results/nuke_inner_whitespace.xhtml +22 -22
  52. data/test/results/nuke_outer_whitespace.xhtml +84 -92
  53. data/test/results/original_engine.xhtml +17 -17
  54. data/test/results/partial_layout.xhtml +4 -3
  55. data/test/results/partial_layout_erb.xhtml +4 -3
  56. data/test/results/partials.xhtml +11 -10
  57. data/test/results/silent_script.xhtml +63 -63
  58. data/test/results/standard.xhtml +156 -159
  59. data/test/results/tag_parsing.xhtml +19 -19
  60. data/test/results/very_basic.xhtml +2 -2
  61. data/test/results/whitespace_handling.xhtml +77 -76
  62. data/test/template_test.rb +21 -48
  63. data/test/template_test_helper.rb +38 -0
  64. data/test/templates/just_stuff.haml +1 -0
  65. data/test/templates/standard_ugly.haml +1 -0
  66. data/test/temple_line_counter_test.rb +40 -0
  67. data/test/test_helper.rb +10 -10
  68. data/test/util_test.rb +1 -48
  69. metadata +49 -35
  70. data/lib/haml/temple.rb +0 -85
  71. data/test/gemfiles/Gemfile.rails-3.2.x +0 -4
  72. data/test/templates/_av_partial_1_ugly.haml +0 -9
  73. data/test/templates/_av_partial_2_ugly.haml +0 -5
  74. data/test/templates/action_view_ugly.haml +0 -47
  75. data/test/templates/standard_ugly.haml +0 -43
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ module Haml
4
+ class OptionsTest < Haml::TestCase
5
+ def test_buffer_defaults_have_only_buffer_option_keys
6
+ assert_equal(
7
+ Haml::Options.buffer_option_keys.sort,
8
+ Haml::Options.buffer_defaults.keys.sort,
9
+ )
10
+ end
11
+
12
+ def test_buffer_defaults_values_are_default_options
13
+ Haml::Options.buffer_option_keys.each do |key|
14
+ assert_equal(
15
+ Haml::Options.defaults[key],
16
+ Haml::Options.buffer_defaults[key],
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Haml
4
- class ParserTest < MiniTest::Unit::TestCase
4
+ class ParserTest < Haml::TestCase
5
5
 
6
6
  test "should raise error for 'else' at wrong indent level" do
7
7
  begin
@@ -116,12 +116,57 @@ module Haml
116
116
  refute node.value[:revealed]
117
117
  end
118
118
 
119
+ test "only script lines are checked for continuation keywords" do
120
+ haml = "- if true\n setup\n- else\n else\n"
121
+ node = parse(haml).children[0]
122
+ assert_equal(3, node.children.size)
123
+ end
124
+
125
+ # see #830. Strictly speaking the pipe here is not necessary, but there
126
+ # shouldn't be an error if it is there.
127
+ test "multiline Ruby with extra trailing pipe doesn't raise error" do
128
+ haml = "%p= foo bar, |\n baz"
129
+ begin
130
+ parse haml
131
+ rescue Haml::SyntaxError
132
+ flunk "Should not have raised SyntaxError"
133
+ end
134
+ end
135
+
136
+ test "empty filter doesn't hide following lines" do
137
+ root = parse "%p\n :plain\n %p\n"
138
+ p_element = root.children[0]
139
+ assert_equal 2, p_element.children.size
140
+ assert_equal :filter, p_element.children[0].type
141
+ assert_equal :tag, p_element.children[1].type
142
+ end
143
+
144
+ # Previously blocks under a haml_comment would be rejected if any line was
145
+ # indented by a value that wasn't a multiple of the document indentation.
146
+ test "haml_comment accepts any indentation in content" do
147
+ begin
148
+ parse "-\#\n Indented two spaces\n Indented three spaces"
149
+ rescue Haml::SyntaxError
150
+ flunk "haml_comment should accept any combination of indentation"
151
+ end
152
+ end
153
+
154
+ test "block haml_comment includes text" do
155
+ root = parse "-#\n Hello\n Hello\n"
156
+ assert_equal "Hello\n Hello\n", root.children[0].value[:text]
157
+ end
158
+
159
+ test "block haml_comment includes first line if present" do
160
+ root = parse "-# First line\n Hello\n Hello\n"
161
+ assert_equal " First line\nHello\n Hello\n", root.children[0].value[:text]
162
+ end
163
+
119
164
  private
120
165
 
121
166
  def parse(haml, options = nil)
122
167
  options ||= Options.new
123
- parser = Parser.new(haml, options)
124
- parser.parse
168
+ parser = Parser.new(options)
169
+ parser.call(haml)
125
170
  end
126
171
  end
127
- end
172
+ end
@@ -2,8 +2,8 @@
2
2
  <p></p>
3
3
  <h1>Me!</h1>
4
4
  <div id='foo'>
5
- <p id='bar'>All</p>
6
- <br />
7
- <p class='baz'>This</p>
8
- Should render
5
+ <p id='bar'>All</p>
6
+ <br />
7
+ <p class='baz'>This</p>
8
+ Should render
9
9
  </div>
@@ -1,59 +1,61 @@
1
1
  &amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;
2
2
  <div>
3
- <p class='title'>Title</p>
4
- <p class='text'>
5
- Woah this is really crazy
6
- I mean wow,
7
- man.
8
- </p>
3
+ <p class='title'>Title</p>
4
+ <p class='text'>
5
+ Woah this is really crazy
6
+ I mean wow,
7
+ man.
8
+ </p>
9
9
  </div>
10
+
10
11
  <div>
11
- <p class='title'>Title</p>
12
- <p class='text'>
13
- Woah this is really crazy
14
- I mean wow,
15
- man.
16
- </p>
12
+ <p class='title'>Title</p>
13
+ <p class='text'>
14
+ Woah this is really crazy
15
+ I mean wow,
16
+ man.
17
+ </p>
17
18
  </div>
19
+
18
20
  <div>
19
- <p class='title'>Title</p>
20
- <p class='text'>
21
- Woah this is really crazy
22
- I mean wow,
23
- man.
24
- </p>
21
+ <p class='title'>Title</p>
22
+ <p class='text'>
23
+ Woah this is really crazy
24
+ I mean wow,
25
+ man.
26
+ </p>
25
27
  </div>
28
+
26
29
  <p>foo</p>
27
- <p>reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeally loooooooooooooooooong</p>
30
+ <p>reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeally loooooooooooooooooong</p>
28
31
  <div class='woah'>
29
- <div id='funky'>
30
- <div>
31
- <h1>Big!</h1>
32
- <p>Small</p>
33
- <!-- Invisible -->
34
- </div>
35
- <div class='dilly'>
36
- <p>foo</p>
37
- <h1>bar</h1>
38
- </div>
39
- </div>
40
- (<strong>parentheses!</strong>)
32
+ <div id='funky'>
33
+ <div>
34
+ <h1>Big!</h1>
35
+ <p>Small</p>
36
+ <!-- Invisible -->
37
+ </div>
38
+ <div class='dilly'>
39
+ <p>foo</p>
40
+ <h1>bar</h1>
41
+ </div>
42
+ </div>
43
+ (<strong>parentheses!</strong>)
41
44
  </div>
42
45
  *<span class='small'>Not really</span>
43
46
  click
44
47
  <a href='thing'>here</a>.
45
48
  <p>baz</p>
46
- <p>boom</p>
49
+ <p>boom</p>
50
+ foo
51
+ <li><a href='http://www.google.com'>google</a></li><p>
47
52
  foo
48
- <li><a href='http://www.google.com'>google</a></li>
49
- <p>
50
- foo
51
- <div>
52
- bar
53
- </div>
54
- boom
55
- baz
56
- boom, again
53
+ <div>
54
+ bar
55
+ </div>
56
+ boom
57
+ baz
58
+ boom, again
57
59
  </p>
58
60
  <table>
59
61
  <tr>
@@ -1,10 +1,13 @@
1
1
  <div class='article' id='article_1'>
2
- <h1>Hello</h1>
3
- <div>World</div>
2
+ <h1>Hello</h1>
3
+ <div>World</div>
4
4
  </div>
5
5
  <div class='article' id='id_article_1'>id</div>
6
6
  <div class='article class' id='article_1'>class</div>
7
7
  <div class='article class' id='id_article_1'>id class</div>
8
8
  <div class='article full' id='article_1'>boo</div>
9
9
  <div class='article full' id='article_1'>moo</div>
10
- <div class='article articleFull' id='article_1'>foo</div>
10
+ <div class='article articleFull' id='article_1'>foo</div>
11
+ <span>
12
+ Boo
13
+ </span>
@@ -6,7 +6,7 @@
6
6
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
7
7
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
8
8
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
9
- <strong apos="Foo's bar!">Boo!</strong>
9
+ <strong apos='Foo&#39;s bar!'>Boo!</strong>
10
10
  Embedded? false!
11
11
  Embedded? true!
12
12
  Embedded? true!
@@ -20,29 +20,30 @@ Embedded? one af"t"er another!
20
20
  stuff followed by whitespace
21
21
  <strong>block with whitespace</strong>
22
22
  <p>
23
- Escape
24
- - character
25
- %p foo
26
- yee\ha
23
+ Escape
24
+ - character
25
+ %p foo
26
+ yee\ha
27
+ don't lstrip me
27
28
  </p>
28
29
  <!-- Short comment -->
29
30
  <!--
30
- This is a block comment
31
- cool, huh?
32
- <strong>there can even be sub-tags!</strong>
33
- Or script!
31
+ This is a block comment
32
+ cool, huh?
33
+ <strong>there can even be sub-tags!</strong>
34
+ Or script!
34
35
  -->
35
36
  <p class=''>class attribute should appear!</p>
36
37
  <p>this attribute shouldn't appear</p>
37
38
  <!--[if lte IE6]> conditional comment! <![endif]-->
38
39
  <!--[if gte IE7]>
39
- <p>Block conditional comment</p>
40
- <div>
41
- <h1>Cool, eh?</h1>
42
- </div>
40
+ <p>Block conditional comment</p>
41
+ <div>
42
+ <h1>Cool, eh?</h1>
43
+ </div>
43
44
  <![endif]-->
44
45
  <!--[if gte IE5.2]>
45
- Woah a period.
46
+ Woah a period.
46
47
  <![endif]-->
47
48
  testtest
48
49
  <br />
@@ -52,7 +53,7 @@ testtest
52
53
  <link />
53
54
  <script>Inline content</script>
54
55
  <br>
55
- Nested content
56
+ Nested content
56
57
  </br>
57
58
  <p class='article bar foo' id='article_1'>Blah</p>
58
59
  <p class='article foo' id='article_1'>Blah</p>
@@ -60,11 +61,11 @@ testtest
60
61
  <p class='article quux qux' id='article_1'>Blump</p>
61
62
  <p class='article' id='foo_bar_baz_article_1'>Whee</p>
62
63
  Woah inner quotes
63
- <p class='dynamic_quote' dyn='3' quotes="single '"></p>
64
+ <p class='dynamic_quote' dyn='3' quotes='single &#39;'></p>
64
65
  <p class='dynamic_self_closing' dyn='3' />
65
66
  <body>
66
- hello
67
- <div>
68
- <img />
69
- </div>
67
+ hello
68
+ <div>
69
+ <img />
70
+ </div>
70
71
  </body>
@@ -1,12 +1,12 @@
1
1
  !Not a Doctype!
2
2
  <ul>
3
- <li>a</li>
4
- <li>b</li>
5
- <li>c</li>
6
- <li>d</li>
7
- <li>e</li>
8
- <li>f</li>
9
- <li>g</li>
10
- <li>h</li>
11
- <li>i</li>
3
+ <li>a</li>
4
+ <li>b</li>
5
+ <li>c</li>
6
+ <li>d</li>
7
+ <li>e</li>
8
+ <li>f</li>
9
+ <li>g</li>
10
+ <li>h</li>
11
+ <li>i</li>
12
12
  </ul>
@@ -1,40 +1,40 @@
1
1
  <p>
2
- <q>Foo</q>
2
+ <q>Foo</q>
3
3
  </p>
4
4
  <p>
5
- <q a='2'>Foo</q>
5
+ <q a='2'>Foo</q>
6
6
  </p>
7
7
  <p>
8
- <q>Foo
9
- Bar</q>
8
+ <q>Foo
9
+ Bar</q>
10
10
  </p>
11
11
  <p>
12
- <q a='2'>Foo
13
- Bar</q>
12
+ <q a='2'>Foo
13
+ Bar</q>
14
14
  </p>
15
15
  <p>
16
- <q>Foo
17
- Bar</q>
16
+ <q>Foo
17
+ Bar</q>
18
18
  </p>
19
19
  <p>
20
- <q a='2'>Foo
21
- Bar</q>
20
+ <q a='2'>Foo
21
+ Bar</q>
22
22
  </p>
23
23
  <p>
24
- <q><div>
25
- Foo
26
- Bar
27
- </div></q>
24
+ <q><div>
25
+ Foo
26
+ Bar
27
+ </div></q>
28
28
  </p>
29
29
  <p>
30
- <q a='2'><div>
31
- Foo
32
- Bar
33
- </div></q>
30
+ <q a='2'><div>
31
+ Foo
32
+ Bar
33
+ </div></q>
34
34
  </p>
35
35
  <p>
36
- <q>foo</q>
37
- <q a='2'>
38
- bar
39
- </q>
36
+ <q>foo</q>
37
+ <q a='2'>
38
+ bar
39
+ </q>
40
40
  </p>
@@ -1,148 +1,140 @@
1
1
  <p>
2
- <p><q>
3
- Foo
4
- </q></p>
2
+ <p><q>
3
+ Foo
4
+ </q></p>
5
5
  </p>
6
6
  <p>
7
- <p><q a='2'>
8
- Foo
9
- </q></p>
7
+ <p><q a='2'>
8
+ Foo
9
+ </q></p>
10
10
  </p>
11
11
  <p>
12
- <p><q>Foo</q></p>
12
+ <p><q>Foo</q></p>
13
13
  </p>
14
14
  <p>
15
- <p><q a='2'>Foo</q></p>
15
+ <p><q a='2'>Foo</q></p>
16
16
  </p>
17
17
  <p>
18
- <p><q>
19
- Foo
20
- </q></p>
18
+ <p><q>
19
+ Foo
20
+ </q></p>
21
21
  </p>
22
22
  <p>
23
- <p><q a='2'>
24
- Foo
25
- </q></p>
23
+ <p><q a='2'>
24
+ Foo
25
+ </q></p>
26
26
  </p>
27
27
  <p>
28
- <p><q>Foo</q></p>
28
+ <p><q>Foo</q></p>
29
29
  </p>
30
30
  <p>
31
- <p><q a='2'>Foo</q></p>
31
+ <p><q a='2'>Foo</q></p>
32
32
  </p>
33
33
  <p>
34
- <p><q>
35
- Foo
36
- Bar
37
- </q></p>
34
+ <p><q>
35
+ Foo
36
+ Bar
37
+ </q></p>
38
38
  </p>
39
39
  <p>
40
- <p><q a='2'>
41
- Foo
42
- Bar
43
- </q></p>
40
+ <p><q a='2'>
41
+ Foo
42
+ Bar
43
+ </q></p>
44
44
  </p>
45
45
  <p>
46
- <p><q>
47
- Foo
48
- Bar
49
- </q></p>
46
+ <p><q>Foo
47
+ Bar</q></p>
50
48
  </p>
51
49
  <p>
52
- <p><q a='2'>
53
- Foo
54
- Bar
55
- </q></p>
50
+ <p><q a='2'>Foo
51
+ Bar</q></p>
56
52
  </p>
57
53
  <p>
58
- <p>
59
- foo<q>
60
- Foo
61
- </q>bar
62
- </p>
54
+ <p>
55
+ foo<q>
56
+ Foo
57
+ </q>bar
58
+ </p>
63
59
  </p>
64
60
  <p>
65
- <p>
66
- foo<q a='2'>
67
- Foo
68
- </q>bar
69
- </p>
61
+ <p>
62
+ foo<q a='2'>
63
+ Foo
64
+ </q>bar
70
65
  </p>
66
+ </p>
67
+ <p>
71
68
  <p>
72
- <p>
73
- foo<q>Foo</q>bar
74
- </p>
69
+ foo<q>Foo</q>bar
70
+ </p>
75
71
  </p>
76
72
  <p>
77
- <p>
78
- foo<q a='2'>Foo</q>bar
79
- </p>
73
+ <p>
74
+ foo<q a='2'>Foo</q>bar
75
+ </p>
80
76
  </p>
81
77
  <p>
82
- <p>
83
- foo<q>
84
- Foo
85
- </q>bar
86
- </p>
78
+ <p>
79
+ foo<q>
80
+ Foo
81
+ </q>bar
87
82
  </p>
83
+ </p>
84
+ <p>
88
85
  <p>
89
- <p>
90
- foo<q a='2'>
91
- Foo
92
- </q>bar
93
- </p>
86
+ foo<q a='2'>
87
+ Foo
88
+ </q>bar
89
+ </p>
94
90
  </p>
95
91
  <p>
96
- <p>
97
- foo<q>Foo</q>bar
98
- </p>
92
+ <p>
93
+ foo<q>Foo</q>bar
94
+ </p>
99
95
  </p>
100
96
  <p>
101
- <p>
102
- foo<q a='2'>Foo</q>bar
103
- </p>
97
+ <p>
98
+ foo<q a='2'>Foo</q>bar
104
99
  </p>
100
+ </p>
101
+ <p>
105
102
  <p>
106
- <p>
107
- foo<q>
108
- Foo
109
- Bar
110
- </q>bar
111
- </p>
103
+ foo<q>
104
+ Foo
105
+ Bar
106
+ </q>bar
107
+ </p>
112
108
  </p>
113
109
  <p>
114
- <p>
115
- foo<q a='2'>
116
- Foo
117
- Bar
118
- </q>bar
119
- </p>
110
+ <p>
111
+ foo<q a='2'>
112
+ Foo
113
+ Bar
114
+ </q>bar
115
+ </p>
120
116
  </p>
121
117
  <p>
122
- <p>
123
- foo<q>
124
- Foo
125
- Bar
126
- </q>bar
127
- </p>
118
+ <p>
119
+ foo<q>Foo
120
+ Bar</q>bar
128
121
  </p>
122
+ </p>
123
+ <p>
129
124
  <p>
130
- <p>
131
- foo<q a='2'>
132
- Foo
133
- Bar
134
- </q>bar
135
- </p>
125
+ foo<q a='2'>Foo
126
+ Bar</q>bar
127
+ </p>
136
128
  </p>
137
129
  <p>
138
- <p><q></q></p>
130
+ <p><q></q></p>
139
131
  </p>
140
132
  <p>
141
- <p><q /></p>
133
+ <p><q /></p>
142
134
  </p>
143
135
  <p>
144
- <p><q a='2'></q></p>
136
+ <p><q a='2'></q></p>
145
137
  </p>
146
138
  <p>
147
- <p><q a='2' /></p>
139
+ <p><q a='2' /></p>
148
140
  </p>