haml 1.8.2 → 2.0.0

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 (77) hide show
  1. data/FAQ +138 -0
  2. data/MIT-LICENSE +1 -1
  3. data/{README → README.rdoc} +66 -3
  4. data/Rakefile +111 -147
  5. data/VERSION +1 -1
  6. data/bin/css2sass +0 -0
  7. data/bin/haml +0 -0
  8. data/bin/html2haml +0 -0
  9. data/bin/sass +0 -0
  10. data/init.rb +6 -1
  11. data/lib/haml.rb +464 -201
  12. data/lib/haml/buffer.rb +117 -63
  13. data/lib/haml/engine.rb +63 -44
  14. data/lib/haml/error.rb +16 -6
  15. data/lib/haml/exec.rb +37 -7
  16. data/lib/haml/filters.rb +213 -68
  17. data/lib/haml/helpers.rb +95 -60
  18. data/lib/haml/helpers/action_view_extensions.rb +1 -1
  19. data/lib/haml/helpers/action_view_mods.rb +54 -6
  20. data/lib/haml/html.rb +6 -6
  21. data/lib/haml/precompiler.rb +254 -133
  22. data/lib/haml/template.rb +3 -6
  23. data/lib/haml/template/patch.rb +9 -2
  24. data/lib/haml/template/plugin.rb +52 -23
  25. data/lib/sass.rb +157 -12
  26. data/lib/sass/constant.rb +22 -22
  27. data/lib/sass/constant/color.rb +13 -13
  28. data/lib/sass/constant/literal.rb +7 -7
  29. data/lib/sass/constant/number.rb +9 -9
  30. data/lib/sass/constant/operation.rb +4 -4
  31. data/lib/sass/constant/string.rb +3 -3
  32. data/lib/sass/css.rb +104 -31
  33. data/lib/sass/engine.rb +120 -39
  34. data/lib/sass/error.rb +1 -1
  35. data/lib/sass/plugin.rb +14 -3
  36. data/lib/sass/plugin/merb.rb +6 -2
  37. data/lib/sass/tree/attr_node.rb +5 -5
  38. data/lib/sass/tree/directive_node.rb +2 -7
  39. data/lib/sass/tree/node.rb +1 -12
  40. data/lib/sass/tree/rule_node.rb +39 -31
  41. data/lib/sass/tree/value_node.rb +1 -1
  42. data/test/benchmark.rb +67 -80
  43. data/test/haml/engine_test.rb +284 -84
  44. data/test/haml/helper_test.rb +51 -15
  45. data/test/haml/results/content_for_layout.xhtml +1 -2
  46. data/test/haml/results/eval_suppressed.xhtml +2 -4
  47. data/test/haml/results/filters.xhtml +44 -15
  48. data/test/haml/results/helpers.xhtml +2 -3
  49. data/test/haml/results/just_stuff.xhtml +2 -6
  50. data/test/haml/results/nuke_inner_whitespace.xhtml +34 -0
  51. data/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
  52. data/test/haml/results/original_engine.xhtml +3 -7
  53. data/test/haml/results/partials.xhtml +1 -0
  54. data/test/haml/results/tag_parsing.xhtml +1 -6
  55. data/test/haml/results/very_basic.xhtml +2 -4
  56. data/test/haml/results/whitespace_handling.xhtml +13 -21
  57. data/test/haml/template_test.rb +8 -15
  58. data/test/haml/templates/_partial.haml +1 -0
  59. data/test/haml/templates/filters.haml +48 -7
  60. data/test/haml/templates/just_stuff.haml +1 -2
  61. data/test/haml/templates/nuke_inner_whitespace.haml +26 -0
  62. data/test/haml/templates/nuke_outer_whitespace.haml +144 -0
  63. data/test/haml/templates/tag_parsing.haml +0 -3
  64. data/test/haml/test_helper.rb +15 -0
  65. data/test/sass/engine_test.rb +80 -34
  66. data/test/sass/plugin_test.rb +1 -1
  67. data/test/sass/results/import.css +2 -2
  68. data/test/sass/results/mixins.css +95 -0
  69. data/test/sass/results/multiline.css +24 -0
  70. data/test/sass/templates/import.sass +4 -1
  71. data/test/sass/templates/importee.sass +4 -0
  72. data/test/sass/templates/mixins.sass +76 -0
  73. data/test/sass/templates/multiline.sass +20 -0
  74. metadata +65 -51
  75. data/lib/haml/util.rb +0 -18
  76. data/test/haml/runner.rb +0 -16
  77. data/test/profile.rb +0 -65
@@ -1,20 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'active_support'
5
- require 'action_controller'
6
- require 'action_view'
7
-
8
- require 'test/unit'
9
- require File.dirname(__FILE__) + '/../../lib/haml'
2
+ require File.dirname(__FILE__) + '/test_helper'
10
3
  require 'haml/template'
11
4
 
12
5
  class HelperTest < Test::Unit::TestCase
13
6
  include Haml::Helpers
7
+ Post = Struct.new('Post', :body)
14
8
 
15
9
  def setup
16
10
  @base = ActionView::Base.new
17
11
  @base.controller = ActionController::Base.new
12
+ @base.instance_variable_set('@post', Post.new("Foo bar\nbaz"))
18
13
  end
19
14
 
20
15
  def render(text, options = {})
@@ -27,14 +22,14 @@ class HelperTest < Test::Unit::TestCase
27
22
  end
28
23
 
29
24
  def test_flatten
30
- assert_equal(flatten("FooBar"), "FooBar")
25
+ assert_equal("FooBar", flatten("FooBar"))
31
26
 
32
- assert_equal(flatten("Foo\rBar"), "FooBar")
27
+ assert_equal("FooBar", flatten("Foo\rBar"))
33
28
 
34
- assert_equal(flatten("Foo\nBar"), "Foo&#x000A;Bar")
29
+ assert_equal("Foo&#x000A;Bar", flatten("Foo\nBar"))
35
30
 
36
- assert_equal(flatten("Hello\nWorld!\nYOU ARE \rFLAT?\n\rOMGZ!"),
37
- "Hello&#x000A;World!&#x000A;YOU ARE FLAT?&#x000A;OMGZ!")
31
+ assert_equal("Hello&#x000A;World!&#x000A;YOU ARE FLAT?&#x000A;OMGZ!",
32
+ flatten("Hello\nWorld!\nYOU ARE \rFLAT?\n\rOMGZ!"))
38
33
  end
39
34
 
40
35
  def test_list_of_should_render_correctly
@@ -85,10 +80,33 @@ class HelperTest < Test::Unit::TestCase
85
80
  should_be = "<form action=\"foo\" method=\"post\">\n <p>bar</p>\n <strong>baz</strong>\n</form>\n"
86
81
  assert_equal(should_be, result)
87
82
  end
83
+
84
+ def test_text_area
85
+ assert_equal(%(<textarea id="body" name="body">Foo&#x000A;Bar&#x000A; Baz&#x000A; Boom</textarea>\n),
86
+ render('= text_area_tag "body", "Foo\nBar\n Baz\n Boom"', :action_view))
87
+
88
+ assert_equal(%(<textarea cols="40" id="post_body" name="post[body]" rows="20">Foo bar&#x000A;baz</textarea>\n),
89
+ render('= text_area :post, :body', :action_view))
90
+
91
+ assert_equal(%(<pre>Foo bar&#x000A; baz</pre>\n),
92
+ render('= content_tag "pre", "Foo bar\n baz"', :action_view))
93
+ end
88
94
 
89
95
  def test_capture_haml
90
96
  assert_equal("\"<p>13</p>\\n\"\n", render("- foo = capture_haml(13) do |a|\n %p= a\n= foo.dump"))
91
97
  end
98
+
99
+ def test_haml_tag_attribute_html_escaping
100
+ assert_equal("<p id='foo&amp;bar'>baz</p>\n", render("%p{:id => 'foo&bar'} baz", :escape_html => true))
101
+ end
102
+
103
+ def test_haml_tag_autoclosed_tags_are_closed
104
+ assert_equal("<br class='foo' />\n", render("- haml_tag :br, :class => 'foo'"))
105
+ end
106
+
107
+ def test_haml_tag_non_autoclosed_tags_arent_closed
108
+ assert_equal("<p>\n</p>\n", render("- haml_tag :p"))
109
+ end
92
110
 
93
111
  def test_is_haml
94
112
  assert(!ActionView::Base.new.is_haml?)
@@ -123,12 +141,12 @@ class HelperTest < Test::Unit::TestCase
123
141
  end
124
142
 
125
143
  def test_find_and_preserve_with_block
126
- assert_equal("<pre>&#x000A; Foo&#x000A; Bar&#x000A;</pre>\nFoo\nBar\n",
144
+ assert_equal("<pre>Foo&#x000A;Bar</pre>\nFoo\nBar\n",
127
145
  render("= find_and_preserve do\n %pre\n Foo\n Bar\n Foo\n Bar"))
128
146
  end
129
147
 
130
148
  def test_preserve_with_block
131
- assert_equal("<pre>&#x000A; Foo&#x000A; Bar&#x000A;</pre>&#x000A;Foo&#x000A;Bar&#x000A;\n",
149
+ assert_equal("<pre>Foo&#x000A;Bar</pre>&#x000A;Foo&#x000A;Bar\n",
132
150
  render("= preserve do\n %pre\n Foo\n Bar\n Foo\n Bar"))
133
151
  end
134
152
 
@@ -147,5 +165,23 @@ class HelperTest < Test::Unit::TestCase
147
165
 
148
166
  assert_equal("<p attr='val'>\n Blah\n</p>\n", result)
149
167
  end
168
+
169
+ def test_non_haml
170
+ assert_equal("false\n", render("= non_haml { is_haml? }"))
171
+ end
172
+
173
+ class ActsLikeTag
174
+ # We want to be able to have people include monkeypatched ActionView helpers
175
+ # without redefining is_haml?.
176
+ # This is accomplished via Object#is_haml?, and this is a test for it.
177
+ include ActionView::Helpers::TagHelper
178
+ def to_s
179
+ content_tag :p, 'some tag content'
180
+ end
181
+ end
182
+
183
+ def test_random_class_includes_tag_helper
184
+ assert_equal "<p>some tag content</p>", ActsLikeTag.new.to_s
185
+ end
150
186
  end
151
187
 
@@ -1,7 +1,6 @@
1
1
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
2
  <html>
3
- <head>
4
- </head>
3
+ <head></head>
5
4
  <body>
6
5
  <div id='content'>
7
6
  Lorem ipsum dolor sit amet
@@ -1,7 +1,5 @@
1
- <p>
2
- </p>
3
- <p>
4
- </p>
1
+ <p></p>
2
+ <p></p>
5
3
  <h1>Me!</h1>
6
4
  <div id='foo'>
7
5
  <p id='bar'>All</p>
@@ -1,7 +1,7 @@
1
1
  <style>
2
2
  p {
3
3
  border-style: dotted;
4
- border-width: 10px;
4
+ border-width: 22px;
5
5
  border-color: #ff00ff; }
6
6
 
7
7
  h1 {
@@ -11,9 +11,7 @@ TESTING HAHAHAHA!
11
11
  <h1>Foo</h1>
12
12
 
13
13
 
14
- <pre><code>This is preformatted!
15
- Look at that!
16
- Wowie-zowie!</code></pre>
14
+ <pre><code>This is preformatted!&#x000A;Look at that!&#x000A;Wowie-zowie!</code></pre>
17
15
 
18
16
 
19
17
  <p><strong>boldilicious!</strong></p>
@@ -21,31 +19,60 @@ Wowie-zowie!</code></pre>
21
19
 
22
20
 
23
21
  <p><em>pretty much the same as above</em></p>
22
+ <p>
23
+ <script type='text/javascript'>
24
+ //<![CDATA[
25
+ function newline(str) {
26
+ return "\n" + str;
27
+ }
28
+ //]]>
29
+ </script>
30
+ </p>
24
31
  This
25
32
  Is
26
33
  Plain
27
34
  Text
28
35
  %strong right?
36
+ #{not interpolated}
37
+ \3
38
+ \#{also not}
39
+ \\
40
+ <p>
41
+ <pre>This pre is pretty deeply&#x000A; nested.&#x000A; Does interpolation work?
42
+ This one is, too.&#x000A;Nested, that is.&#x000A;</pre>
43
+ </p>
44
+ <ul>
45
+
46
+ <li>a</li>
47
+
48
+ <li>b</li>
49
+
50
+ <li>c</li>
29
51
 
30
- a
52
+ <li>d</li>
31
53
 
32
- b
54
+ <li>e</li>
33
55
 
34
- c
56
+ <li>f</li>
35
57
 
36
- d
58
+ <li>g</li>
37
59
 
38
- e
60
+ <li>h</li>
39
61
 
40
- f
62
+ <li>i</li>
41
63
 
42
- g
64
+ <li>j</li>
43
65
 
44
- h
45
66
 
46
- i
47
67
 
48
- j
68
+ </ul>
69
+ <div class='res'>178</div>
70
+ <p>
71
+ <p>I like preserved text:</p>
72
+
73
+
74
+ <pre><code>Foo&#x000A; Bar!&#x000A;Baz</code></pre>
75
+ </p>
49
76
  <ul>
50
77
  <li>Foo</li>
51
78
  <li>Bar</li>
@@ -54,4 +81,6 @@ This
54
81
  Text!
55
82
  Hello, World!
56
83
  How are you doing today?
57
-
84
+ &lt;div class=&quot;foo&quot;&gt;
85
+ &lt;p&gt;I think &amp;mdash; or do I?&lt;/p&gt;
86
+ &lt;/div&gt;
@@ -24,9 +24,7 @@
24
24
  </p>
25
25
  </div>
26
26
  <p>foo</p>
27
- <p>
28
- reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeally loooooooooooooooooong
29
- </p>
27
+ <p>reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeally loooooooooooooooooong</p>
30
28
  <div class='woah'>
31
29
  <div id='funky'>
32
30
  <div>
@@ -56,6 +54,7 @@ foo
56
54
  @foo =
57
55
  value one
58
56
  </p>
57
+ Toplevel? false
59
58
  <p>
60
59
  @foo =
61
60
  value three
@@ -27,9 +27,6 @@ stuff followed by whitespace
27
27
  yee\ha
28
28
  </p>
29
29
  <!-- Short comment -->
30
- <!--
31
- This is a really long comment look how long it is it should be on a line of its own don't you think?
32
- -->
33
30
  <!--
34
31
  This is a block comment
35
32
  cool, huh?
@@ -62,6 +59,5 @@ testtest
62
59
  <p class='article foo' id='article_1'>Blah</p>
63
60
  <p class='article quux qux' id='article_1'>Blump</p>
64
61
  Woah inner quotes
65
- <p class='dynamic_quote' dyn='3' quotes="single '">
66
- </p>
67
- <p class='dynamic_atomic' dyn='3' />
62
+ <p class='dynamic_quote' dyn='3' quotes="single '"></p>
63
+ <p class='dynamic_self_closing' dyn='3' />
@@ -0,0 +1,34 @@
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>
@@ -0,0 +1,148 @@
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>