haml-edge 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. data/EDGE_GEM_VERSION +1 -0
  2. data/FAQ +138 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +332 -0
  5. data/REVISION +1 -0
  6. data/Rakefile +226 -0
  7. data/VERSION +1 -0
  8. data/bin/css2sass +7 -0
  9. data/bin/haml +9 -0
  10. data/bin/html2haml +7 -0
  11. data/bin/sass +8 -0
  12. data/extra/edge_gem_watch.rb +13 -0
  13. data/extra/haml-mode.el +596 -0
  14. data/extra/sass-mode.el +200 -0
  15. data/init.rb +8 -0
  16. data/lib/haml/buffer.rb +255 -0
  17. data/lib/haml/engine.rb +268 -0
  18. data/lib/haml/error.rb +22 -0
  19. data/lib/haml/exec.rb +395 -0
  20. data/lib/haml/filters.rb +275 -0
  21. data/lib/haml/helpers/action_view_extensions.rb +45 -0
  22. data/lib/haml/helpers/action_view_mods.rb +181 -0
  23. data/lib/haml/helpers.rb +488 -0
  24. data/lib/haml/html.rb +222 -0
  25. data/lib/haml/precompiler.rb +904 -0
  26. data/lib/haml/shared.rb +45 -0
  27. data/lib/haml/template/patch.rb +58 -0
  28. data/lib/haml/template/plugin.rb +72 -0
  29. data/lib/haml/template.rb +42 -0
  30. data/lib/haml/util.rb +88 -0
  31. data/lib/haml/version.rb +47 -0
  32. data/lib/haml.rb +1044 -0
  33. data/lib/sass/css.rb +388 -0
  34. data/lib/sass/engine.rb +495 -0
  35. data/lib/sass/environment.rb +46 -0
  36. data/lib/sass/error.rb +35 -0
  37. data/lib/sass/plugin/merb.rb +56 -0
  38. data/lib/sass/plugin/rails.rb +24 -0
  39. data/lib/sass/plugin.rb +204 -0
  40. data/lib/sass/repl.rb +51 -0
  41. data/lib/sass/script/bool.rb +13 -0
  42. data/lib/sass/script/color.rb +97 -0
  43. data/lib/sass/script/funcall.rb +29 -0
  44. data/lib/sass/script/functions.rb +134 -0
  45. data/lib/sass/script/lexer.rb +148 -0
  46. data/lib/sass/script/literal.rb +82 -0
  47. data/lib/sass/script/number.rb +231 -0
  48. data/lib/sass/script/operation.rb +30 -0
  49. data/lib/sass/script/parser.rb +142 -0
  50. data/lib/sass/script/string.rb +9 -0
  51. data/lib/sass/script/unary_operation.rb +21 -0
  52. data/lib/sass/script/variable.rb +20 -0
  53. data/lib/sass/script.rb +38 -0
  54. data/lib/sass/tree/attr_node.rb +64 -0
  55. data/lib/sass/tree/comment_node.rb +30 -0
  56. data/lib/sass/tree/debug_node.rb +22 -0
  57. data/lib/sass/tree/directive_node.rb +50 -0
  58. data/lib/sass/tree/file_node.rb +27 -0
  59. data/lib/sass/tree/for_node.rb +29 -0
  60. data/lib/sass/tree/if_node.rb +27 -0
  61. data/lib/sass/tree/mixin_def_node.rb +18 -0
  62. data/lib/sass/tree/mixin_node.rb +35 -0
  63. data/lib/sass/tree/node.rb +99 -0
  64. data/lib/sass/tree/rule_node.rb +161 -0
  65. data/lib/sass/tree/variable_node.rb +24 -0
  66. data/lib/sass/tree/while_node.rb +21 -0
  67. data/lib/sass.rb +1062 -0
  68. data/rails/init.rb +1 -0
  69. data/test/benchmark.rb +99 -0
  70. data/test/haml/engine_test.rb +795 -0
  71. data/test/haml/helper_test.rb +228 -0
  72. data/test/haml/html2haml_test.rb +108 -0
  73. data/test/haml/markaby/standard.mab +52 -0
  74. data/test/haml/mocks/article.rb +6 -0
  75. data/test/haml/results/content_for_layout.xhtml +15 -0
  76. data/test/haml/results/eval_suppressed.xhtml +9 -0
  77. data/test/haml/results/filters.xhtml +62 -0
  78. data/test/haml/results/helpers.xhtml +93 -0
  79. data/test/haml/results/helpful.xhtml +10 -0
  80. data/test/haml/results/just_stuff.xhtml +68 -0
  81. data/test/haml/results/list.xhtml +12 -0
  82. data/test/haml/results/nuke_inner_whitespace.xhtml +40 -0
  83. data/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
  84. data/test/haml/results/original_engine.xhtml +20 -0
  85. data/test/haml/results/partial_layout.xhtml +5 -0
  86. data/test/haml/results/partials.xhtml +21 -0
  87. data/test/haml/results/render_layout.xhtml +3 -0
  88. data/test/haml/results/silent_script.xhtml +74 -0
  89. data/test/haml/results/standard.xhtml +162 -0
  90. data/test/haml/results/tag_parsing.xhtml +23 -0
  91. data/test/haml/results/very_basic.xhtml +5 -0
  92. data/test/haml/results/whitespace_handling.xhtml +89 -0
  93. data/test/haml/rhtml/_av_partial_1.rhtml +12 -0
  94. data/test/haml/rhtml/_av_partial_2.rhtml +8 -0
  95. data/test/haml/rhtml/action_view.rhtml +62 -0
  96. data/test/haml/rhtml/standard.rhtml +54 -0
  97. data/test/haml/template_test.rb +204 -0
  98. data/test/haml/templates/_av_partial_1.haml +9 -0
  99. data/test/haml/templates/_av_partial_1_ugly.haml +9 -0
  100. data/test/haml/templates/_av_partial_2.haml +5 -0
  101. data/test/haml/templates/_av_partial_2_ugly.haml +5 -0
  102. data/test/haml/templates/_layout.erb +3 -0
  103. data/test/haml/templates/_layout_for_partial.haml +3 -0
  104. data/test/haml/templates/_partial.haml +8 -0
  105. data/test/haml/templates/_text_area.haml +3 -0
  106. data/test/haml/templates/action_view.haml +47 -0
  107. data/test/haml/templates/action_view_ugly.haml +47 -0
  108. data/test/haml/templates/breakage.haml +8 -0
  109. data/test/haml/templates/content_for_layout.haml +10 -0
  110. data/test/haml/templates/eval_suppressed.haml +11 -0
  111. data/test/haml/templates/filters.haml +66 -0
  112. data/test/haml/templates/helpers.haml +95 -0
  113. data/test/haml/templates/helpful.haml +11 -0
  114. data/test/haml/templates/just_stuff.haml +83 -0
  115. data/test/haml/templates/list.haml +12 -0
  116. data/test/haml/templates/nuke_inner_whitespace.haml +32 -0
  117. data/test/haml/templates/nuke_outer_whitespace.haml +144 -0
  118. data/test/haml/templates/original_engine.haml +17 -0
  119. data/test/haml/templates/partial_layout.haml +3 -0
  120. data/test/haml/templates/partialize.haml +1 -0
  121. data/test/haml/templates/partials.haml +12 -0
  122. data/test/haml/templates/render_layout.haml +2 -0
  123. data/test/haml/templates/silent_script.haml +40 -0
  124. data/test/haml/templates/standard.haml +42 -0
  125. data/test/haml/templates/standard_ugly.haml +42 -0
  126. data/test/haml/templates/tag_parsing.haml +21 -0
  127. data/test/haml/templates/very_basic.haml +4 -0
  128. data/test/haml/templates/whitespace_handling.haml +87 -0
  129. data/test/haml/util_test.rb +87 -0
  130. data/test/linked_rails.rb +12 -0
  131. data/test/sass/css2sass_test.rb +193 -0
  132. data/test/sass/engine_test.rb +709 -0
  133. data/test/sass/functions_test.rb +109 -0
  134. data/test/sass/more_results/more1.css +9 -0
  135. data/test/sass/more_results/more1_with_line_comments.css +26 -0
  136. data/test/sass/more_results/more_import.css +29 -0
  137. data/test/sass/more_templates/_more_partial.sass +2 -0
  138. data/test/sass/more_templates/more1.sass +23 -0
  139. data/test/sass/more_templates/more_import.sass +11 -0
  140. data/test/sass/plugin_test.rb +213 -0
  141. data/test/sass/results/alt.css +4 -0
  142. data/test/sass/results/basic.css +9 -0
  143. data/test/sass/results/compact.css +5 -0
  144. data/test/sass/results/complex.css +87 -0
  145. data/test/sass/results/compressed.css +1 -0
  146. data/test/sass/results/expanded.css +19 -0
  147. data/test/sass/results/import.css +29 -0
  148. data/test/sass/results/line_numbers.css +49 -0
  149. data/test/sass/results/mixins.css +95 -0
  150. data/test/sass/results/multiline.css +24 -0
  151. data/test/sass/results/nested.css +22 -0
  152. data/test/sass/results/parent_ref.css +13 -0
  153. data/test/sass/results/script.css +16 -0
  154. data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
  155. data/test/sass/results/subdir/subdir.css +3 -0
  156. data/test/sass/results/units.css +11 -0
  157. data/test/sass/script_test.rb +250 -0
  158. data/test/sass/templates/_partial.sass +2 -0
  159. data/test/sass/templates/alt.sass +16 -0
  160. data/test/sass/templates/basic.sass +23 -0
  161. data/test/sass/templates/bork.sass +2 -0
  162. data/test/sass/templates/bork2.sass +2 -0
  163. data/test/sass/templates/compact.sass +17 -0
  164. data/test/sass/templates/complex.sass +309 -0
  165. data/test/sass/templates/compressed.sass +15 -0
  166. data/test/sass/templates/expanded.sass +17 -0
  167. data/test/sass/templates/import.sass +11 -0
  168. data/test/sass/templates/importee.sass +19 -0
  169. data/test/sass/templates/line_numbers.sass +13 -0
  170. data/test/sass/templates/mixins.sass +76 -0
  171. data/test/sass/templates/multiline.sass +20 -0
  172. data/test/sass/templates/nested.sass +25 -0
  173. data/test/sass/templates/parent_ref.sass +25 -0
  174. data/test/sass/templates/script.sass +101 -0
  175. data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
  176. data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
  177. data/test/sass/templates/subdir/subdir.sass +6 -0
  178. data/test/sass/templates/units.sass +11 -0
  179. data/test/test_helper.rb +21 -0
  180. metadata +278 -0
@@ -0,0 +1,228 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../test_helper'
3
+ require 'haml/template'
4
+
5
+ class ActionView::Base
6
+ def nested_tag
7
+ content_tag(:span) {content_tag(:div) {"something"}}
8
+ end
9
+ end
10
+
11
+ class HelperTest < Test::Unit::TestCase
12
+ Post = Struct.new('Post', :body)
13
+
14
+ def setup
15
+ @base = ActionView::Base.new
16
+ @base.controller = ActionController::Base.new
17
+ @base.instance_variable_set('@post', Post.new("Foo bar\nbaz"))
18
+ end
19
+
20
+ def render(text, options = {})
21
+ if options == :action_view
22
+ @base.render :inline => text, :type => :haml
23
+ else
24
+ scope = options.delete :scope_object
25
+ Haml::Engine.new(text, options).to_html(scope ? scope : Object.new)
26
+ end
27
+ end
28
+
29
+ def test_flatten
30
+ assert_equal("FooBar", Haml::Helpers.flatten("FooBar"))
31
+
32
+ assert_equal("FooBar", Haml::Helpers.flatten("Foo\rBar"))
33
+
34
+ assert_equal("Foo&#x000A;Bar", Haml::Helpers.flatten("Foo\nBar"))
35
+
36
+ assert_equal("Hello&#x000A;World!&#x000A;YOU ARE FLAT?&#x000A;OMGZ!",
37
+ Haml::Helpers.flatten("Hello\nWorld!\nYOU ARE \rFLAT?\n\rOMGZ!"))
38
+ end
39
+
40
+ def test_list_of_should_render_correctly
41
+ assert_equal("<li>1</li>\n<li>2</li>\n", render("= list_of([1, 2]) do |i|\n = i"))
42
+ assert_equal("<li>[1]</li>\n", render("= list_of([[1]]) do |i|\n = i.inspect"))
43
+ assert_equal("<li>\n <h1>Fee</h1>\n <p>A word!</p>\n</li>\n<li>\n <h1>Fi</h1>\n <p>A word!</p>\n</li>\n<li>\n <h1>Fo</h1>\n <p>A word!</p>\n</li>\n<li>\n <h1>Fum</h1>\n <p>A word!</p>\n</li>\n",
44
+ render("= list_of(['Fee', 'Fi', 'Fo', 'Fum']) do |title|\n %h1= title\n %p A word!"))
45
+ end
46
+
47
+ def test_buffer_access
48
+ assert(render("= buffer") =~ /#<Haml::Buffer:0x[a-z0-9]+>/)
49
+ assert_equal(render("= (buffer == _hamlout)"), "true\n")
50
+ end
51
+
52
+ def test_tabs
53
+ assert_equal("foo\n bar\nbaz\n", render("foo\n- tab_up\nbar\n- tab_down\nbaz"))
54
+ assert_equal(" <p>tabbed</p>\n", render("- buffer.tabulation=5\n%p tabbed"))
55
+ end
56
+
57
+ def test_helpers_dont_leak
58
+ # Haml helpers shouldn't be accessible from ERB
59
+ render("foo")
60
+ proper_behavior = false
61
+
62
+ begin
63
+ ActionView::Base.new.render(:inline => "<%= flatten('Foo\\nBar') %>")
64
+ rescue NoMethodError
65
+ proper_behavior = true
66
+ end
67
+ assert(proper_behavior)
68
+
69
+ begin
70
+ ActionView::Base.new.render(:inline => "<%= concat('foo') %>")
71
+ rescue ArgumentError, NameError
72
+ proper_behavior = true
73
+ end
74
+ assert(proper_behavior)
75
+ end
76
+
77
+ def test_action_view_included
78
+ assert(Haml::Helpers.action_view?)
79
+ end
80
+
81
+ def test_form_tag
82
+ # This is usually provided by ActionController::Base.
83
+ def @base.protect_against_forgery?; false; end
84
+ result = render("- form_tag 'foo' do\n %p bar\n %strong baz", :action_view)
85
+ should_be = "<form action=\"foo\" method=\"post\">\n <p>bar</p>\n <strong>baz</strong>\n</form>\n"
86
+ assert_equal(should_be, result)
87
+ end
88
+
89
+ def test_text_area
90
+ assert_equal(%(<textarea id="body" name="body">Foo&#x000A;Bar&#x000A; Baz&#x000A; Boom</textarea>\n),
91
+ render('= text_area_tag "body", "Foo\nBar\n Baz\n Boom"', :action_view))
92
+
93
+ assert_equal(%(<textarea cols="40" id="post_body" name="post[body]" rows="20">Foo bar&#x000A;baz</textarea>\n),
94
+ render('= text_area :post, :body', :action_view))
95
+
96
+ assert_equal(%(<pre>Foo bar&#x000A; baz</pre>\n),
97
+ render('= content_tag "pre", "Foo bar\n baz"', :action_view))
98
+ end
99
+
100
+ def test_capture_haml
101
+ assert_equal("\"<p>13</p>\\n\"\n", render("- foo = capture_haml(13) do |a|\n %p= a\n= foo.dump"))
102
+ end
103
+
104
+ def test_content_tag_block
105
+ assert_equal(<<HTML.strip, render(<<HAML, :action_view))
106
+ <div><p>bar</p>
107
+ <strong>bar</strong>
108
+ </div>
109
+ HTML
110
+ - content_tag :div do
111
+ %p bar
112
+ %strong bar
113
+ HAML
114
+ end
115
+
116
+ def test_haml_tag_attribute_html_escaping
117
+ assert_equal("<p id='foo&amp;bar'>baz</p>\n", render("%p{:id => 'foo&bar'} baz", :escape_html => true))
118
+ end
119
+
120
+ def test_haml_tag_autoclosed_tags_are_closed
121
+ assert_equal("<br class='foo' />\n", render("- haml_tag :br, :class => 'foo'"))
122
+ end
123
+
124
+ def test_haml_tag_non_autoclosed_tags_arent_closed
125
+ assert_equal("<p></p>\n", render("- haml_tag :p"))
126
+ end
127
+
128
+ def test_haml_tag_renders_text_on_a_single_line
129
+ assert_equal("<p>#{'a' * 100}</p>\n", render("- haml_tag :p, 'a' * 100"))
130
+ end
131
+
132
+ def test_haml_tag_raises_error_for_multiple_content
133
+ assert_raise(Haml::Error) { render("- haml_tag :p, 'foo' do\n bar") }
134
+ end
135
+
136
+ def test_haml_tag_flags
137
+ assert_equal("<p />\n", render("- haml_tag :p, :/"))
138
+ assert_equal("<p>kumquat</p>\n", render("- haml_tag :p, :< do\n kumquat"))
139
+
140
+ assert_raise(Haml::Error) { render("- haml_tag :p, 'foo', :/") }
141
+ assert_raise(Haml::Error) { render("- haml_tag :p, :/ do\n foo") }
142
+ end
143
+
144
+ def test_haml_tag_error_return
145
+ assert_raise(Haml::Error) { render("= haml_tag :p") }
146
+ end
147
+
148
+ def test_is_haml
149
+ assert(!ActionView::Base.new.is_haml?)
150
+ assert_equal("true\n", render("= is_haml?"))
151
+ assert_equal("true\n", render("= is_haml?", :action_view))
152
+ assert_equal("false", @base.render(:inline => '<%= is_haml? %>'))
153
+ assert_equal("false\n", render("= render :inline => '<%= is_haml? %>'", :action_view))
154
+ end
155
+
156
+ def test_page_class
157
+ controller = Struct.new(:controller_name, :action_name).new('troller', 'tion')
158
+ scope = Struct.new(:controller).new(controller)
159
+ result = render("%div{:class => page_class} MyDiv", :scope_object => scope)
160
+ expected = "<div class='troller tion'>MyDiv</div>\n"
161
+ assert_equal expected, result
162
+ end
163
+
164
+ def test_indented_capture
165
+ assert_equal(" \n Foo\n ", @base.render(:inline => " <% res = capture do %>\n Foo\n <% end %><%= res %>"))
166
+ end
167
+
168
+ def test_capture_deals_properly_with_collections
169
+ Haml::Helpers.module_eval do
170
+ def trc(collection, &block)
171
+ collection.each do |record|
172
+ haml_concat capture_haml(record, &block)
173
+ end
174
+ end
175
+ end
176
+
177
+ assert_equal("1\n\n2\n\n3\n\n", render("- trc([1, 2, 3]) do |i|\n = i.inspect"))
178
+ end
179
+
180
+ def test_find_and_preserve_with_block
181
+ assert_equal("<pre>Foo&#x000A;Bar</pre>\nFoo\nBar\n",
182
+ render("= find_and_preserve do\n %pre\n Foo\n Bar\n Foo\n Bar"))
183
+ end
184
+
185
+ def test_preserve_with_block
186
+ assert_equal("<pre>Foo&#x000A;Bar</pre>&#x000A;Foo&#x000A;Bar\n",
187
+ render("= preserve do\n %pre\n Foo\n Bar\n Foo\n Bar"))
188
+ end
189
+
190
+ def test_init_haml_helpers
191
+ context = Object.new
192
+ class << context
193
+ include Haml::Helpers
194
+ end
195
+ context.init_haml_helpers
196
+
197
+ result = context.capture_haml do
198
+ context.haml_tag :p, :attr => "val" do
199
+ context.haml_concat "Blah"
200
+ end
201
+ end
202
+
203
+ assert_equal("<p attr='val'>\n Blah\n</p>\n", result)
204
+ end
205
+
206
+ def test_non_haml
207
+ assert_equal("false\n", render("= non_haml { is_haml? }"))
208
+ end
209
+
210
+ def test_content_tag_nested
211
+ assert_equal "<span><div>something</div></span>", render("= nested_tag", :action_view).strip
212
+ end
213
+
214
+ class ActsLikeTag
215
+ # We want to be able to have people include monkeypatched ActionView helpers
216
+ # without redefining is_haml?.
217
+ # This is accomplished via Object#is_haml?, and this is a test for it.
218
+ include ActionView::Helpers::TagHelper
219
+ def to_s
220
+ content_tag :p, 'some tag content'
221
+ end
222
+ end
223
+
224
+ def test_random_class_includes_tag_helper
225
+ assert_equal "<p>some tag content</p>", ActsLikeTag.new.to_s
226
+ end
227
+ end
228
+
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../test_helper'
3
+ require 'haml/html'
4
+
5
+ class Html2HamlTest < Test::Unit::TestCase
6
+
7
+ def test_empty_render_should_remain_empty
8
+ assert_equal '', render('')
9
+ end
10
+
11
+ def test_id_and_class_should_be_removed_from_hash
12
+ assert_equal '%span#foo.bar', render('<span id="foo" class="bar"> </span>')
13
+ end
14
+
15
+ def test_no_tag_name_for_div_if_class_or_id_is_present
16
+ assert_equal '#foo', render('<div id="foo"> </div>')
17
+ assert_equal '.foo', render('<div class="foo"> </div>')
18
+ end
19
+
20
+ def test_multiple_class_names
21
+ assert_equal '.foo.bar.baz', render('<div class=" foo bar baz "> </div>')
22
+ end
23
+
24
+ def test_should_have_pretty_attributes
25
+ assert_equal_attributes('%input{ :type => "text", :name => "login" }',
26
+ render('<input type="text" name="login" />'))
27
+ assert_equal_attributes('%meta{ "http-equiv" => "Content-Type", :content => "text/html" }',
28
+ render('<meta http-equiv="Content-Type" content="text/html" />'))
29
+ end
30
+
31
+ def test_sqml_comment
32
+ assert_equal "/\n IE sucks", render('<!-- IE sucks -->')
33
+ end
34
+
35
+ def test_rhtml
36
+ assert_equal '- foo = bar', render_rhtml('<% foo = bar %>')
37
+ assert_equal '- foo = bar', render_rhtml('<% foo = bar -%>')
38
+ assert_equal '= h @item.title', render_rhtml('<%=h @item.title %>')
39
+ assert_equal '= h @item.title', render_rhtml('<%=h @item.title -%>')
40
+ end
41
+
42
+ def test_rhtml_with_html_special_chars
43
+ assert_equal '= 3 < 5 ? "OK" : "Your computer is b0rken"',
44
+ render_rhtml(%Q{<%= 3 < 5 ? "OK" : "Your computer is b0rken" %>})
45
+ end
46
+
47
+ def test_rhtml_in_class_attribute
48
+ assert_equal "%div{ :class => dyna_class }\n I have a dynamic attribute",
49
+ render_rhtml(%Q{<div class="<%= dyna_class %>">I have a dynamic attribute</div>})
50
+ end
51
+
52
+ def test_rhtml_in_id_attribute
53
+ assert_equal "%div{ :id => dyna_id }\n I have a dynamic attribute",
54
+ render_rhtml(%Q{<div id="<%= dyna_id %>">I have a dynamic attribute</div>})
55
+ end
56
+
57
+ def test_rhtml_in_attribute_results_in_string_interpolation
58
+ assert_equal %(%div{ :id => "item_\#{i}" }\n Ruby string interpolation FTW),
59
+ render_rhtml(%Q{<div id="item_<%= i %>">Ruby string interpolation FTW</div>})
60
+ end
61
+
62
+ def test_rhtml_in_attribute_with_trailing_content
63
+ assert_equal %(%div{ :class => "\#{12}!" }\n Bang!),
64
+ render_rhtml(%Q{<div class="<%= 12 %>!">Bang!</div>})
65
+ end
66
+
67
+ def test_rhtml_in_attribute_to_multiple_interpolations
68
+ assert_equal %(%div{ :class => "\#{12} + \#{13}" }\n Math is super),
69
+ render_rhtml(%Q{<div class="<%= 12 %> + <%= 13 %>">Math is super</div>})
70
+ end
71
+
72
+ def test_whitespace_eating_erb_tags
73
+ assert_equal %(- form_for),
74
+ render_rhtml(%Q{<%- form_for -%>})
75
+ end
76
+
77
+ def test_cdata
78
+ assert_equal(<<HAML.strip, render(<<HTML))
79
+ %p
80
+ :cdata
81
+ <a foo="bar" baz="bang">
82
+ <div id="foo">flop</div>
83
+ </a>
84
+ HAML
85
+ <p><![CDATA[
86
+ <a foo="bar" baz="bang">
87
+ <div id="foo">flop</div>
88
+ </a>
89
+ ]]></p>
90
+ HTML
91
+ end
92
+
93
+ protected
94
+
95
+ def render(text, options = {})
96
+ Haml::HTML.new(text, options).render.rstrip
97
+ end
98
+
99
+ def render_rhtml(text)
100
+ render(text, :rhtml => true)
101
+ end
102
+
103
+ def assert_equal_attributes(expected, result)
104
+ expected_attr, result_attr = [expected, result].map { |s| s.gsub!(/\{ (.+) \}/, ''); $1.split(', ').sort }
105
+ assert_equal expected_attr, result_attr
106
+ assert_equal expected, result
107
+ end
108
+ end
@@ -0,0 +1,52 @@
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
@@ -0,0 +1,6 @@
1
+ class Article
2
+ attr_accessor :id, :title, :body
3
+ def initialize
4
+ @id, @title, @body = 1, 'Hello', 'World'
5
+ end
6
+ end
@@ -0,0 +1,15 @@
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='content'>
6
+ Lorem ipsum dolor sit amet
7
+ </div>
8
+ <div id='yieldy'>
9
+ Lorem ipsum dolor sit amet
10
+ </div>
11
+ <div id='nosym'>
12
+ Lorem ipsum dolor sit amet
13
+ </div>
14
+ </body>
15
+ </html>
@@ -0,0 +1,9 @@
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>
@@ -0,0 +1,62 @@
1
+ <style>
2
+ /* line 1 */
3
+ p { border-style: dotted; border-width: 22px; border-color: #ff00ff; }
4
+
5
+ /* line 6 */
6
+ h1 { font-weight: normal; }
7
+ </style>
8
+ TESTING HAHAHAHA!
9
+ <p>
10
+ <script type='text/javascript'>
11
+ //<![CDATA[
12
+ function newline(str) {
13
+ return "\n" + str;
14
+ }
15
+ //]]>
16
+ </script>
17
+ </p>
18
+ This
19
+ Is
20
+ Plain
21
+ Text
22
+ %strong right?
23
+ #{not interpolated}
24
+ \3
25
+ \#{also not}
26
+ \\
27
+ <p>
28
+ <pre>This pre is pretty deeply&#x000A; nested.&#x000A; Does interpolation work?
29
+ This one is, too.&#x000A;Nested, that is.&#x000A;</pre>
30
+ </p>
31
+ <ul>
32
+
33
+ <li>a</li>
34
+
35
+ <li>b</li>
36
+
37
+ <li>c</li>
38
+
39
+ <li>d</li>
40
+
41
+ <li>e</li>
42
+
43
+ <li>f</li>
44
+
45
+ <li>g</li>
46
+
47
+ <li>h</li>
48
+
49
+ <li>i</li>
50
+
51
+ <li>j</li>
52
+
53
+
54
+
55
+ </ul>
56
+ <div class='res'>178</div>
57
+ Text!
58
+ Hello, World!
59
+ How are you doing today?
60
+ &lt;div class=&quot;foo&quot;&gt;
61
+ &lt;p&gt;I think &amp;mdash; or do I?&lt;/p&gt;
62
+ &lt;/div&gt;
@@ -0,0 +1,93 @@
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
+ <p>
49
+ <form action="" method="post">
50
+ </p>
51
+ <div>
52
+ <form action="" method="post">
53
+ <div><input name="commit" type="submit" value="save" /></div>
54
+ <p>
55
+ @foo =
56
+ value one
57
+ </p>
58
+ Toplevel? false
59
+ <p>
60
+ @foo =
61
+ value three
62
+ </p>
63
+ </form>
64
+ <form action="" method="post">
65
+ Title:
66
+ <input id="article_title" name="article[title]" size="30" type="text" value="Hello" />
67
+ Body:
68
+ <input id="article_body" name="article[body]" size="30" type="text" value="World" />
69
+ </form>
70
+ </div>
71
+ <li><a href='http://www.google.com'>google</a></li>
72
+ <p>
73
+ foo
74
+ <div>
75
+ bar
76
+ </div>
77
+ boom
78
+ baz
79
+ boom, again
80
+ </p>
81
+ <table>
82
+ <tr>
83
+ <td class='cell'>
84
+ <strong>strong!</strong>
85
+ data
86
+ </td>
87
+ <td>
88
+ more_data
89
+ </td>
90
+ </tr>
91
+ </table>
92
+ <hr />
93
+ <div></div>
@@ -0,0 +1,10 @@
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>
@@ -0,0 +1,68 @@
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 quux qux' id='article_1'>Blump</p>
60
+ Woah inner quotes
61
+ <p class='dynamic_quote' dyn='3' quotes="single '"></p>
62
+ <p class='dynamic_self_closing' dyn='3' />
63
+ <body>
64
+ hello
65
+ <div>
66
+ <img />
67
+ </div>
68
+ </body>
@@ -0,0 +1,12 @@
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>