haml-edge 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/EDGE_GEM_VERSION +1 -0
- data/FAQ +138 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +332 -0
- data/REVISION +1 -0
- data/Rakefile +226 -0
- data/VERSION +1 -0
- data/bin/css2sass +7 -0
- data/bin/haml +9 -0
- data/bin/html2haml +7 -0
- data/bin/sass +8 -0
- data/extra/edge_gem_watch.rb +13 -0
- data/extra/haml-mode.el +596 -0
- data/extra/sass-mode.el +200 -0
- data/init.rb +8 -0
- data/lib/haml/buffer.rb +255 -0
- data/lib/haml/engine.rb +268 -0
- data/lib/haml/error.rb +22 -0
- data/lib/haml/exec.rb +395 -0
- data/lib/haml/filters.rb +275 -0
- data/lib/haml/helpers/action_view_extensions.rb +45 -0
- data/lib/haml/helpers/action_view_mods.rb +181 -0
- data/lib/haml/helpers.rb +488 -0
- data/lib/haml/html.rb +222 -0
- data/lib/haml/precompiler.rb +904 -0
- data/lib/haml/shared.rb +45 -0
- data/lib/haml/template/patch.rb +58 -0
- data/lib/haml/template/plugin.rb +72 -0
- data/lib/haml/template.rb +42 -0
- data/lib/haml/util.rb +88 -0
- data/lib/haml/version.rb +47 -0
- data/lib/haml.rb +1044 -0
- data/lib/sass/css.rb +388 -0
- data/lib/sass/engine.rb +495 -0
- data/lib/sass/environment.rb +46 -0
- data/lib/sass/error.rb +35 -0
- data/lib/sass/plugin/merb.rb +56 -0
- data/lib/sass/plugin/rails.rb +24 -0
- data/lib/sass/plugin.rb +204 -0
- data/lib/sass/repl.rb +51 -0
- data/lib/sass/script/bool.rb +13 -0
- data/lib/sass/script/color.rb +97 -0
- data/lib/sass/script/funcall.rb +29 -0
- data/lib/sass/script/functions.rb +134 -0
- data/lib/sass/script/lexer.rb +148 -0
- data/lib/sass/script/literal.rb +82 -0
- data/lib/sass/script/number.rb +231 -0
- data/lib/sass/script/operation.rb +30 -0
- data/lib/sass/script/parser.rb +142 -0
- data/lib/sass/script/string.rb +9 -0
- data/lib/sass/script/unary_operation.rb +21 -0
- data/lib/sass/script/variable.rb +20 -0
- data/lib/sass/script.rb +38 -0
- data/lib/sass/tree/attr_node.rb +64 -0
- data/lib/sass/tree/comment_node.rb +30 -0
- data/lib/sass/tree/debug_node.rb +22 -0
- data/lib/sass/tree/directive_node.rb +50 -0
- data/lib/sass/tree/file_node.rb +27 -0
- data/lib/sass/tree/for_node.rb +29 -0
- data/lib/sass/tree/if_node.rb +27 -0
- data/lib/sass/tree/mixin_def_node.rb +18 -0
- data/lib/sass/tree/mixin_node.rb +35 -0
- data/lib/sass/tree/node.rb +99 -0
- data/lib/sass/tree/rule_node.rb +161 -0
- data/lib/sass/tree/variable_node.rb +24 -0
- data/lib/sass/tree/while_node.rb +21 -0
- data/lib/sass.rb +1062 -0
- data/rails/init.rb +1 -0
- data/test/benchmark.rb +99 -0
- data/test/haml/engine_test.rb +795 -0
- data/test/haml/helper_test.rb +228 -0
- data/test/haml/html2haml_test.rb +108 -0
- data/test/haml/markaby/standard.mab +52 -0
- data/test/haml/mocks/article.rb +6 -0
- data/test/haml/results/content_for_layout.xhtml +15 -0
- data/test/haml/results/eval_suppressed.xhtml +9 -0
- data/test/haml/results/filters.xhtml +62 -0
- data/test/haml/results/helpers.xhtml +93 -0
- data/test/haml/results/helpful.xhtml +10 -0
- data/test/haml/results/just_stuff.xhtml +68 -0
- data/test/haml/results/list.xhtml +12 -0
- data/test/haml/results/nuke_inner_whitespace.xhtml +40 -0
- data/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
- data/test/haml/results/original_engine.xhtml +20 -0
- data/test/haml/results/partial_layout.xhtml +5 -0
- data/test/haml/results/partials.xhtml +21 -0
- data/test/haml/results/render_layout.xhtml +3 -0
- data/test/haml/results/silent_script.xhtml +74 -0
- data/test/haml/results/standard.xhtml +162 -0
- data/test/haml/results/tag_parsing.xhtml +23 -0
- data/test/haml/results/very_basic.xhtml +5 -0
- data/test/haml/results/whitespace_handling.xhtml +89 -0
- data/test/haml/rhtml/_av_partial_1.rhtml +12 -0
- data/test/haml/rhtml/_av_partial_2.rhtml +8 -0
- data/test/haml/rhtml/action_view.rhtml +62 -0
- data/test/haml/rhtml/standard.rhtml +54 -0
- data/test/haml/template_test.rb +204 -0
- data/test/haml/templates/_av_partial_1.haml +9 -0
- data/test/haml/templates/_av_partial_1_ugly.haml +9 -0
- data/test/haml/templates/_av_partial_2.haml +5 -0
- data/test/haml/templates/_av_partial_2_ugly.haml +5 -0
- data/test/haml/templates/_layout.erb +3 -0
- data/test/haml/templates/_layout_for_partial.haml +3 -0
- data/test/haml/templates/_partial.haml +8 -0
- data/test/haml/templates/_text_area.haml +3 -0
- data/test/haml/templates/action_view.haml +47 -0
- data/test/haml/templates/action_view_ugly.haml +47 -0
- data/test/haml/templates/breakage.haml +8 -0
- data/test/haml/templates/content_for_layout.haml +10 -0
- data/test/haml/templates/eval_suppressed.haml +11 -0
- data/test/haml/templates/filters.haml +66 -0
- data/test/haml/templates/helpers.haml +95 -0
- data/test/haml/templates/helpful.haml +11 -0
- data/test/haml/templates/just_stuff.haml +83 -0
- data/test/haml/templates/list.haml +12 -0
- data/test/haml/templates/nuke_inner_whitespace.haml +32 -0
- data/test/haml/templates/nuke_outer_whitespace.haml +144 -0
- data/test/haml/templates/original_engine.haml +17 -0
- data/test/haml/templates/partial_layout.haml +3 -0
- data/test/haml/templates/partialize.haml +1 -0
- data/test/haml/templates/partials.haml +12 -0
- data/test/haml/templates/render_layout.haml +2 -0
- data/test/haml/templates/silent_script.haml +40 -0
- data/test/haml/templates/standard.haml +42 -0
- data/test/haml/templates/standard_ugly.haml +42 -0
- data/test/haml/templates/tag_parsing.haml +21 -0
- data/test/haml/templates/very_basic.haml +4 -0
- data/test/haml/templates/whitespace_handling.haml +87 -0
- data/test/haml/util_test.rb +87 -0
- data/test/linked_rails.rb +12 -0
- data/test/sass/css2sass_test.rb +193 -0
- data/test/sass/engine_test.rb +709 -0
- data/test/sass/functions_test.rb +109 -0
- data/test/sass/more_results/more1.css +9 -0
- data/test/sass/more_results/more1_with_line_comments.css +26 -0
- data/test/sass/more_results/more_import.css +29 -0
- data/test/sass/more_templates/_more_partial.sass +2 -0
- data/test/sass/more_templates/more1.sass +23 -0
- data/test/sass/more_templates/more_import.sass +11 -0
- data/test/sass/plugin_test.rb +213 -0
- data/test/sass/results/alt.css +4 -0
- data/test/sass/results/basic.css +9 -0
- data/test/sass/results/compact.css +5 -0
- data/test/sass/results/complex.css +87 -0
- data/test/sass/results/compressed.css +1 -0
- data/test/sass/results/expanded.css +19 -0
- data/test/sass/results/import.css +29 -0
- data/test/sass/results/line_numbers.css +49 -0
- data/test/sass/results/mixins.css +95 -0
- data/test/sass/results/multiline.css +24 -0
- data/test/sass/results/nested.css +22 -0
- data/test/sass/results/parent_ref.css +13 -0
- data/test/sass/results/script.css +16 -0
- data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
- data/test/sass/results/subdir/subdir.css +3 -0
- data/test/sass/results/units.css +11 -0
- data/test/sass/script_test.rb +250 -0
- data/test/sass/templates/_partial.sass +2 -0
- data/test/sass/templates/alt.sass +16 -0
- data/test/sass/templates/basic.sass +23 -0
- data/test/sass/templates/bork.sass +2 -0
- data/test/sass/templates/bork2.sass +2 -0
- data/test/sass/templates/compact.sass +17 -0
- data/test/sass/templates/complex.sass +309 -0
- data/test/sass/templates/compressed.sass +15 -0
- data/test/sass/templates/expanded.sass +17 -0
- data/test/sass/templates/import.sass +11 -0
- data/test/sass/templates/importee.sass +19 -0
- data/test/sass/templates/line_numbers.sass +13 -0
- data/test/sass/templates/mixins.sass +76 -0
- data/test/sass/templates/multiline.sass +20 -0
- data/test/sass/templates/nested.sass +25 -0
- data/test/sass/templates/parent_ref.sass +25 -0
- data/test/sass/templates/script.sass +101 -0
- data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
- data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
- data/test/sass/templates/subdir/subdir.sass +6 -0
- data/test/sass/templates/units.sass +11 -0
- data/test/test_helper.rb +21 -0
- 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
Bar", Haml::Helpers.flatten("Foo\nBar"))
|
35
|
+
|
36
|
+
assert_equal("Hello
World!
YOU ARE FLAT?
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
Bar
 Baz
 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
baz</textarea>\n),
|
94
|
+
render('= text_area :post, :body', :action_view))
|
95
|
+
|
96
|
+
assert_equal(%(<pre>Foo bar
 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&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
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
Bar</pre>
Foo
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,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,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
 nested.
 Does interpolation work?
|
29
|
+
This one is, too.
Nested, that is.
</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
|
+
<div class="foo">
|
61
|
+
<p>I think &mdash; or do I?</p>
|
62
|
+
</div>
|
@@ -0,0 +1,93 @@
|
|
1
|
+
&&&&&&&&&&&
|
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>
|