haml 4.0.6 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +19 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +72 -0
  5. data/.yardopts +2 -3
  6. data/CHANGELOG.md +138 -4
  7. data/FAQ.md +4 -14
  8. data/Gemfile +16 -0
  9. data/MIT-LICENSE +2 -2
  10. data/README.md +79 -42
  11. data/REFERENCE.md +142 -67
  12. data/Rakefile +44 -63
  13. data/TODO +24 -0
  14. data/benchmark.rb +70 -0
  15. data/haml.gemspec +45 -0
  16. data/lib/haml.rb +2 -0
  17. data/lib/haml/.gitattributes +1 -0
  18. data/lib/haml/attribute_builder.rb +164 -0
  19. data/lib/haml/attribute_compiler.rb +235 -0
  20. data/lib/haml/attribute_parser.rb +150 -0
  21. data/lib/haml/buffer.rb +29 -136
  22. data/lib/haml/compiler.rb +110 -320
  23. data/lib/haml/engine.rb +34 -41
  24. data/lib/haml/error.rb +28 -24
  25. data/lib/haml/escapable.rb +77 -0
  26. data/lib/haml/exec.rb +38 -20
  27. data/lib/haml/filters.rb +22 -27
  28. data/lib/haml/generator.rb +42 -0
  29. data/lib/haml/helpers.rb +134 -89
  30. data/lib/haml/helpers/action_view_extensions.rb +4 -2
  31. data/lib/haml/helpers/action_view_mods.rb +45 -60
  32. data/lib/haml/helpers/action_view_xss_mods.rb +2 -0
  33. data/lib/haml/helpers/safe_erubi_template.rb +20 -0
  34. data/lib/haml/helpers/safe_erubis_template.rb +5 -1
  35. data/lib/haml/helpers/xss_mods.rb +23 -13
  36. data/lib/haml/options.rb +63 -69
  37. data/lib/haml/parser.rb +292 -228
  38. data/lib/haml/plugin.rb +37 -0
  39. data/lib/haml/railtie.rb +38 -12
  40. data/lib/haml/sass_rails_filter.rb +18 -4
  41. data/lib/haml/template.rb +13 -6
  42. data/lib/haml/template/options.rb +13 -2
  43. data/lib/haml/temple_engine.rb +123 -0
  44. data/lib/haml/temple_line_counter.rb +30 -0
  45. data/lib/haml/util.rb +83 -202
  46. data/lib/haml/version.rb +3 -1
  47. data/yard/default/.gitignore +1 -0
  48. data/yard/default/fulldoc/html/css/common.sass +15 -0
  49. data/yard/default/layout/html/footer.erb +12 -0
  50. metadata +73 -108
  51. data/lib/haml/template/plugin.rb +0 -41
  52. data/test/engine_test.rb +0 -2013
  53. data/test/erb/_av_partial_1.erb +0 -12
  54. data/test/erb/_av_partial_2.erb +0 -8
  55. data/test/erb/action_view.erb +0 -62
  56. data/test/erb/standard.erb +0 -55
  57. data/test/filters_test.rb +0 -254
  58. data/test/gemfiles/Gemfile.rails-3.0.x +0 -5
  59. data/test/gemfiles/Gemfile.rails-3.1.x +0 -6
  60. data/test/gemfiles/Gemfile.rails-3.2.x +0 -5
  61. data/test/gemfiles/Gemfile.rails-4.0.x +0 -5
  62. data/test/helper_test.rb +0 -583
  63. data/test/markaby/standard.mab +0 -52
  64. data/test/mocks/article.rb +0 -6
  65. data/test/parser_test.rb +0 -105
  66. data/test/results/content_for_layout.xhtml +0 -12
  67. data/test/results/eval_suppressed.xhtml +0 -9
  68. data/test/results/helpers.xhtml +0 -70
  69. data/test/results/helpful.xhtml +0 -10
  70. data/test/results/just_stuff.xhtml +0 -70
  71. data/test/results/list.xhtml +0 -12
  72. data/test/results/nuke_inner_whitespace.xhtml +0 -40
  73. data/test/results/nuke_outer_whitespace.xhtml +0 -148
  74. data/test/results/original_engine.xhtml +0 -20
  75. data/test/results/partial_layout.xhtml +0 -5
  76. data/test/results/partial_layout_erb.xhtml +0 -5
  77. data/test/results/partials.xhtml +0 -21
  78. data/test/results/render_layout.xhtml +0 -3
  79. data/test/results/silent_script.xhtml +0 -74
  80. data/test/results/standard.xhtml +0 -162
  81. data/test/results/tag_parsing.xhtml +0 -23
  82. data/test/results/very_basic.xhtml +0 -5
  83. data/test/results/whitespace_handling.xhtml +0 -90
  84. data/test/template_test.rb +0 -354
  85. data/test/templates/_av_partial_1.haml +0 -9
  86. data/test/templates/_av_partial_1_ugly.haml +0 -9
  87. data/test/templates/_av_partial_2.haml +0 -5
  88. data/test/templates/_av_partial_2_ugly.haml +0 -5
  89. data/test/templates/_layout.erb +0 -3
  90. data/test/templates/_layout_for_partial.haml +0 -3
  91. data/test/templates/_partial.haml +0 -8
  92. data/test/templates/_text_area.haml +0 -3
  93. data/test/templates/_text_area_helper.html.haml +0 -4
  94. data/test/templates/action_view.haml +0 -47
  95. data/test/templates/action_view_ugly.haml +0 -47
  96. data/test/templates/breakage.haml +0 -8
  97. data/test/templates/content_for_layout.haml +0 -8
  98. data/test/templates/eval_suppressed.haml +0 -11
  99. data/test/templates/helpers.haml +0 -55
  100. data/test/templates/helpful.haml +0 -11
  101. data/test/templates/just_stuff.haml +0 -85
  102. data/test/templates/list.haml +0 -12
  103. data/test/templates/nuke_inner_whitespace.haml +0 -32
  104. data/test/templates/nuke_outer_whitespace.haml +0 -144
  105. data/test/templates/original_engine.haml +0 -17
  106. data/test/templates/partial_layout.haml +0 -3
  107. data/test/templates/partial_layout_erb.erb +0 -4
  108. data/test/templates/partialize.haml +0 -1
  109. data/test/templates/partials.haml +0 -12
  110. data/test/templates/render_layout.haml +0 -2
  111. data/test/templates/silent_script.haml +0 -45
  112. data/test/templates/standard.haml +0 -43
  113. data/test/templates/standard_ugly.haml +0 -43
  114. data/test/templates/tag_parsing.haml +0 -21
  115. data/test/templates/very_basic.haml +0 -4
  116. data/test/templates/whitespace_handling.haml +0 -87
  117. data/test/test_helper.rb +0 -81
  118. data/test/util_test.rb +0 -63
@@ -1,52 +0,0 @@
1
- self << '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
2
- html(:xmlns=>'http://www.w3.org/1999/xhtml', 'xml:lang'=>'en-US') do
3
- head do
4
- title "Hampton Catlin Is Totally Awesome"
5
- meta("http-equiv" => "Content-Type", :content => "text/html; charset=utf-8")
6
- end
7
- body do
8
- # You're In my house now!
9
- div :class => "header" do
10
- self << %|Yes, ladies and gentileman. He is just that egotistical.
11
- Fantastic! This should be multi-line output
12
- The question is if this would translate! Ahah!|
13
- self << 1 + 9 + 8 + 2 #numbers should work and this should be ignored
14
- end
15
- div(:id => "body") { self << "Quotes should be loved! Just like people!"}
16
- 120.times do |number|
17
- number
18
- end
19
- self << "Wow.|"
20
- p do
21
- self << "Holy cow " +
22
- "multiline " +
23
- "tags! " +
24
- "A pipe (|) even!"
25
- self << [1, 2, 3].collect { |n| "PipesIgnored|" }
26
- self << [1, 2, 3].collect { |n|
27
- n.to_s
28
- }.join("|")
29
- end
30
- div(:class => "silent") do
31
- foo = String.new
32
- foo << "this"
33
- foo << " shouldn't"
34
- foo << " evaluate"
35
- self << foo + " but now it should!"
36
- # Woah crap a comment!
37
- end
38
- # That was a line that shouldn't close everything.
39
- ul(:class => "really cool") do
40
- ('a'..'f').each do |a|
41
- li a
42
- end
43
- end
44
- div((@should_eval = "with this text"), :id => "combo", :class => "of_divs_with_underscore")
45
- [ 104, 101, 108, 108, 111 ].map do |byte|
46
- byte.chr
47
- end
48
- div(:class => "footer") do
49
- strong("This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid. \nSo, I'm just making it *really* long. God, I hope this works", :class => "shout")
50
- end
51
- end
52
- end
@@ -1,6 +0,0 @@
1
- class Article
2
- attr_accessor :id, :title, :body
3
- def initialize
4
- @id, @title, @body = 1, 'Hello', 'World'
5
- end
6
- end
@@ -1,105 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Haml
4
- class ParserTest < MiniTest::Unit::TestCase
5
-
6
- test "should raise error for 'else' at wrong indent level" do
7
- begin
8
- parse("- if true\n #first\n text\n - else\n #second")
9
- flunk("Should have raised a Haml::SyntaxError")
10
- rescue SyntaxError => e
11
- assert_equal Error.message(:bad_script_indent, 'else', 0, 1), e.message
12
- end
13
- end
14
-
15
- test "should raise error for 'elsif' at wrong indent level" do
16
- begin
17
- parse("- if true\n #first\n text\n - elsif false\n #second")
18
- flunk("Should have raised a Haml::SyntaxError")
19
- rescue SyntaxError => e
20
- assert_equal Error.message(:bad_script_indent, 'elsif', 0, 1), e.message
21
- end
22
- end
23
-
24
- test "should raise error for 'else' at wrong indent level after unless" do
25
- begin
26
- parse("- unless true\n #first\n text\n - else\n #second")
27
- flunk("Should have raised a Haml::SyntaxError")
28
- rescue SyntaxError => e
29
- assert_equal Error.message(:bad_script_indent, 'else', 0, 1), e.message
30
- end
31
- end
32
-
33
- test "should raise syntax error for else with no if" do
34
- begin
35
- parse("- else\n 'foo'")
36
- flunk("Should have raised a Haml::SyntaxError")
37
- rescue SyntaxError => e
38
- assert_equal Error.message(:missing_if, 'else'), e.message
39
- end
40
- end
41
-
42
- test "should raise syntax error for nested else with no" do
43
- begin
44
- parse("#foo\n - else\n 'foo'")
45
- flunk("Should have raised a Haml::SyntaxError")
46
- rescue SyntaxError => e
47
- assert_equal Error.message(:missing_if, 'else'), e.message
48
- end
49
- end
50
-
51
- test "else after if containing case is accepted" do
52
- # see issue 572
53
- begin
54
- parse "- if true\n - case @foo\n - when 1\n bar\n- else\n bar"
55
- assert true
56
- rescue SyntaxError
57
- flunk 'else clause after if containing case should be accepted'
58
- end
59
- end
60
-
61
- test "else after if containing unless is accepted" do
62
- begin
63
- parse "- if true\n - unless @foo\n bar\n- else\n bar"
64
- assert true
65
- rescue SyntaxError
66
- flunk 'else clause after if containing unless should be accepted'
67
- end
68
- end
69
-
70
- test "loud script with else is accepted" do
71
- begin
72
- parse "= if true\n - 'A'\n-else\n - 'B'"
73
- assert true
74
- rescue SyntaxError
75
- flunk 'loud script (=) should allow else'
76
- end
77
- end
78
-
79
- test "else after nested loud script is accepted" do
80
- begin
81
- parse "-if true\n =if true\n - 'A'\n-else\n B"
82
- assert true
83
- rescue SyntaxError
84
- flunk 'else after nested loud script should be accepted'
85
- end
86
- end
87
-
88
- test "case with indented whens should allow else" do
89
- begin
90
- parse "- foo = 1\n-case foo\n -when 1\n A\n -else\n B"
91
- assert true
92
- rescue SyntaxError
93
- flunk 'case with indented whens should allow else'
94
- end
95
- end
96
-
97
- private
98
-
99
- def parse(haml, options = nil)
100
- options ||= Options.new
101
- parser = Parser.new(haml, options)
102
- parser.parse
103
- end
104
- end
105
- end
@@ -1,12 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
- <html>
3
- <head></head>
4
- <body>
5
- <div id='yieldy'>
6
- Lorem ipsum dolor sit amet
7
- </div>
8
- <div id='nosym'>
9
- Lorem ipsum dolor sit amet
10
- </div>
11
- </body>
12
- </html>
@@ -1,9 +0,0 @@
1
- <p></p>
2
- <p></p>
3
- <h1>Me!</h1>
4
- <div id='foo'>
5
- <p id='bar'>All</p>
6
- <br />
7
- <p class='baz'>This</p>
8
- Should render
9
- </div>
@@ -1,70 +0,0 @@
1
- &amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;
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>
9
- </div>
10
- <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>
17
- </div>
18
- <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>
25
- </div>
26
- <p>foo</p>
27
- <p>reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeally loooooooooooooooooong</p>
28
- <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>)
41
- </div>
42
- *<span class='small'>Not really</span>
43
- click
44
- <a href='thing'>here</a>.
45
- <p>baz</p>
46
- <p>boom</p>
47
- 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
57
- </p>
58
- <table>
59
- <tr>
60
- <td class='cell'>
61
- <strong>strong!</strong>
62
- data
63
- </td>
64
- <td>
65
- more_data
66
- </td>
67
- </tr>
68
- </table>
69
- <hr />
70
- <div></div>
@@ -1,10 +0,0 @@
1
- <div class='article' id='article_1'>
2
- <h1>Hello</h1>
3
- <div>World</div>
4
- </div>
5
- <div class='article' id='id_article_1'>id</div>
6
- <div class='article class' id='article_1'>class</div>
7
- <div class='article class' id='id_article_1'>id class</div>
8
- <div class='article full' id='article_1'>boo</div>
9
- <div class='article full' id='article_1'>moo</div>
10
- <div class='article articleFull' id='article_1'>foo</div>
@@ -1,70 +0,0 @@
1
- <?xml version='1.0' encoding='utf-8' ?>
2
- <?xml version='1.0' encoding='iso-8859-1' ?>
3
- <?xml version='1.0' encoding='utf-8' ?>
4
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
6
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
7
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
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>
10
- Embedded? false!
11
- Embedded? true!
12
- Embedded? true!
13
- Embedded? twice! true!
14
- Embedded? one af"t"er another!
15
- <p>Embedded? false!</p>
16
- <p>Embedded? true!</p>
17
- <p>Embedded? true!</p>
18
- <p>Embedded? twice! true!</p>
19
- <p>Embedded? one af"t"er another!</p>
20
- stuff followed by whitespace
21
- <strong>block with whitespace</strong>
22
- <p>
23
- Escape
24
- - character
25
- %p foo
26
- yee\ha
27
- </p>
28
- <!-- Short comment -->
29
- <!--
30
- This is a block comment
31
- cool, huh?
32
- <strong>there can even be sub-tags!</strong>
33
- Or script!
34
- -->
35
- <p class=''>class attribute should appear!</p>
36
- <p>this attribute shouldn't appear</p>
37
- <!--[if lte IE6]> conditional comment! <![endif]-->
38
- <!--[if gte IE7]>
39
- <p>Block conditional comment</p>
40
- <div>
41
- <h1>Cool, eh?</h1>
42
- </div>
43
- <![endif]-->
44
- <!--[if gte IE5.2]>
45
- Woah a period.
46
- <![endif]-->
47
- testtest
48
- <br />
49
- <meta foo='bar' />
50
- <img />
51
- <hr />
52
- <link />
53
- <script>Inline content</script>
54
- <br>
55
- Nested content
56
- </br>
57
- <p class='article bar foo' id='article_1'>Blah</p>
58
- <p class='article foo' id='article_1'>Blah</p>
59
- <p class='article bar baz foo' id='article_1'>Blah</p>
60
- <p class='article quux qux' id='article_1'>Blump</p>
61
- <p class='article' id='foo_bar_baz_article_1'>Whee</p>
62
- Woah inner quotes
63
- <p class='dynamic_quote' dyn='3' quotes="single '"></p>
64
- <p class='dynamic_self_closing' dyn='3' />
65
- <body>
66
- hello
67
- <div>
68
- <img />
69
- </div>
70
- </body>
@@ -1,12 +0,0 @@
1
- !Not a Doctype!
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>
12
- </ul>
@@ -1,40 +0,0 @@
1
- <p>
2
- <q>Foo</q>
3
- </p>
4
- <p>
5
- <q a='2'>Foo</q>
6
- </p>
7
- <p>
8
- <q>Foo
9
- Bar</q>
10
- </p>
11
- <p>
12
- <q a='2'>Foo
13
- Bar</q>
14
- </p>
15
- <p>
16
- <q>Foo
17
- Bar</q>
18
- </p>
19
- <p>
20
- <q a='2'>Foo
21
- Bar</q>
22
- </p>
23
- <p>
24
- <q><div>
25
- Foo
26
- Bar
27
- </div></q>
28
- </p>
29
- <p>
30
- <q a='2'><div>
31
- Foo
32
- Bar
33
- </div></q>
34
- </p>
35
- <p>
36
- <q>foo</q>
37
- <q a='2'>
38
- bar
39
- </q>
40
- </p>
@@ -1,148 +0,0 @@
1
- <p>
2
- <p><q>
3
- Foo
4
- </q></p>
5
- </p>
6
- <p>
7
- <p><q a='2'>
8
- Foo
9
- </q></p>
10
- </p>
11
- <p>
12
- <p><q>Foo</q></p>
13
- </p>
14
- <p>
15
- <p><q a='2'>Foo</q></p>
16
- </p>
17
- <p>
18
- <p><q>
19
- Foo
20
- </q></p>
21
- </p>
22
- <p>
23
- <p><q a='2'>
24
- Foo
25
- </q></p>
26
- </p>
27
- <p>
28
- <p><q>Foo</q></p>
29
- </p>
30
- <p>
31
- <p><q a='2'>Foo</q></p>
32
- </p>
33
- <p>
34
- <p><q>
35
- Foo
36
- Bar
37
- </q></p>
38
- </p>
39
- <p>
40
- <p><q a='2'>
41
- Foo
42
- Bar
43
- </q></p>
44
- </p>
45
- <p>
46
- <p><q>
47
- Foo
48
- Bar
49
- </q></p>
50
- </p>
51
- <p>
52
- <p><q a='2'>
53
- Foo
54
- Bar
55
- </q></p>
56
- </p>
57
- <p>
58
- <p>
59
- foo<q>
60
- Foo
61
- </q>bar
62
- </p>
63
- </p>
64
- <p>
65
- <p>
66
- foo<q a='2'>
67
- Foo
68
- </q>bar
69
- </p>
70
- </p>
71
- <p>
72
- <p>
73
- foo<q>Foo</q>bar
74
- </p>
75
- </p>
76
- <p>
77
- <p>
78
- foo<q a='2'>Foo</q>bar
79
- </p>
80
- </p>
81
- <p>
82
- <p>
83
- foo<q>
84
- Foo
85
- </q>bar
86
- </p>
87
- </p>
88
- <p>
89
- <p>
90
- foo<q a='2'>
91
- Foo
92
- </q>bar
93
- </p>
94
- </p>
95
- <p>
96
- <p>
97
- foo<q>Foo</q>bar
98
- </p>
99
- </p>
100
- <p>
101
- <p>
102
- foo<q a='2'>Foo</q>bar
103
- </p>
104
- </p>
105
- <p>
106
- <p>
107
- foo<q>
108
- Foo
109
- Bar
110
- </q>bar
111
- </p>
112
- </p>
113
- <p>
114
- <p>
115
- foo<q a='2'>
116
- Foo
117
- Bar
118
- </q>bar
119
- </p>
120
- </p>
121
- <p>
122
- <p>
123
- foo<q>
124
- Foo
125
- Bar
126
- </q>bar
127
- </p>
128
- </p>
129
- <p>
130
- <p>
131
- foo<q a='2'>
132
- Foo
133
- Bar
134
- </q>bar
135
- </p>
136
- </p>
137
- <p>
138
- <p><q></q></p>
139
- </p>
140
- <p>
141
- <p><q /></p>
142
- </p>
143
- <p>
144
- <p><q a='2'></q></p>
145
- </p>
146
- <p>
147
- <p><q a='2' /></p>
148
- </p>