merbjedi-haml 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/FAQ +138 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +332 -0
- data/REVISION +1 -0
- data/Rakefile +184 -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/haml-mode.el +434 -0
- data/extra/sass-mode.el +98 -0
- data/init.rb +8 -0
- data/lib/haml.rb +1025 -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 +276 -0
- data/lib/haml/helpers.rb +465 -0
- data/lib/haml/helpers/action_view_extensions.rb +45 -0
- data/lib/haml/helpers/action_view_mods.rb +181 -0
- data/lib/haml/html.rb +218 -0
- data/lib/haml/precompiler.rb +896 -0
- data/lib/haml/shared.rb +45 -0
- data/lib/haml/template.rb +51 -0
- data/lib/haml/template/patch.rb +58 -0
- data/lib/haml/template/plugin.rb +72 -0
- data/lib/haml/util.rb +77 -0
- data/lib/haml/version.rb +47 -0
- data/lib/sass.rb +1062 -0
- data/lib/sass/css.rb +388 -0
- data/lib/sass/engine.rb +501 -0
- data/lib/sass/environment.rb +33 -0
- data/lib/sass/error.rb +35 -0
- data/lib/sass/plugin.rb +203 -0
- data/lib/sass/plugin/merb.rb +56 -0
- data/lib/sass/plugin/rails.rb +24 -0
- data/lib/sass/repl.rb +44 -0
- data/lib/sass/script.rb +38 -0
- data/lib/sass/script/bool.rb +13 -0
- data/lib/sass/script/color.rb +97 -0
- data/lib/sass/script/funcall.rb +28 -0
- data/lib/sass/script/functions.rb +122 -0
- data/lib/sass/script/lexer.rb +144 -0
- data/lib/sass/script/literal.rb +60 -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 +42 -0
- data/lib/sass/script/unary_operation.rb +21 -0
- data/lib/sass/script/variable.rb +20 -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 +34 -0
- data/lib/sass/tree/node.rb +97 -0
- data/lib/sass/tree/rule_node.rb +120 -0
- data/lib/sass/tree/variable_node.rb +24 -0
- data/lib/sass/tree/while_node.rb +20 -0
- data/rails/init.rb +1 -0
- data/test/benchmark.rb +99 -0
- data/test/haml/engine_test.rb +852 -0
- data/test/haml/helper_test.rb +224 -0
- data/test/haml/html2haml_test.rb +92 -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 +42 -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/linked_rails.rb +12 -0
- data/test/sass/css2sass_test.rb +193 -0
- data/test/sass/engine_test.rb +752 -0
- data/test/sass/functions_test.rb +96 -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 +208 -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 +152 -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 +273 -0
@@ -0,0 +1,224 @@
|
|
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_is_haml
|
145
|
+
assert(!ActionView::Base.new.is_haml?)
|
146
|
+
assert_equal("true\n", render("= is_haml?"))
|
147
|
+
assert_equal("true\n", render("= is_haml?", :action_view))
|
148
|
+
assert_equal("false", @base.render(:inline => '<%= is_haml? %>'))
|
149
|
+
assert_equal("false\n", render("= render :inline => '<%= is_haml? %>'", :action_view))
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_page_class
|
153
|
+
controller = Struct.new(:controller_name, :action_name).new('troller', 'tion')
|
154
|
+
scope = Struct.new(:controller).new(controller)
|
155
|
+
result = render("%div{:class => page_class} MyDiv", :scope_object => scope)
|
156
|
+
expected = "<div class='troller tion'>MyDiv</div>\n"
|
157
|
+
assert_equal expected, result
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_indented_capture
|
161
|
+
assert_equal(" \n Foo\n ", @base.render(:inline => " <% res = capture do %>\n Foo\n <% end %><%= res %>"))
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_capture_deals_properly_with_collections
|
165
|
+
Haml::Helpers.module_eval do
|
166
|
+
def trc(collection, &block)
|
167
|
+
collection.each do |record|
|
168
|
+
haml_concat capture_haml(record, &block)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
assert_equal("1\n\n2\n\n3\n\n", render("- trc([1, 2, 3]) do |i|\n = i.inspect"))
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_find_and_preserve_with_block
|
177
|
+
assert_equal("<pre>Foo
Bar</pre>\nFoo\nBar\n",
|
178
|
+
render("= find_and_preserve do\n %pre\n Foo\n Bar\n Foo\n Bar"))
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_preserve_with_block
|
182
|
+
assert_equal("<pre>Foo
Bar</pre>
Foo
Bar\n",
|
183
|
+
render("= preserve do\n %pre\n Foo\n Bar\n Foo\n Bar"))
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_init_haml_helpers
|
187
|
+
context = Object.new
|
188
|
+
class << context
|
189
|
+
include Haml::Helpers
|
190
|
+
end
|
191
|
+
context.init_haml_helpers
|
192
|
+
|
193
|
+
result = context.capture_haml do
|
194
|
+
context.haml_tag :p, :attr => "val" do
|
195
|
+
context.haml_concat "Blah"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
assert_equal("<p attr='val'>\n Blah\n</p>\n", result)
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_non_haml
|
203
|
+
assert_equal("false\n", render("= non_haml { is_haml? }"))
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_content_tag_nested
|
207
|
+
assert_equal "<span><div>something</div></span>", render("= nested_tag", :action_view).strip
|
208
|
+
end
|
209
|
+
|
210
|
+
class ActsLikeTag
|
211
|
+
# We want to be able to have people include monkeypatched ActionView helpers
|
212
|
+
# without redefining is_haml?.
|
213
|
+
# This is accomplished via Object#is_haml?, and this is a test for it.
|
214
|
+
include ActionView::Helpers::TagHelper
|
215
|
+
def to_s
|
216
|
+
content_tag :p, 'some tag content'
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_random_class_includes_tag_helper
|
221
|
+
assert_equal "<p>some tag content</p>", ActsLikeTag.new.to_s
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
@@ -0,0 +1,92 @@
|
|
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
|
+
protected
|
78
|
+
|
79
|
+
def render(text, options = {})
|
80
|
+
Haml::HTML.new(text, options).render.rstrip
|
81
|
+
end
|
82
|
+
|
83
|
+
def render_rhtml(text)
|
84
|
+
render(text, :rhtml => true)
|
85
|
+
end
|
86
|
+
|
87
|
+
def assert_equal_attributes(expected, result)
|
88
|
+
expected_attr, result_attr = [expected, result].map { |s| s.gsub!(/\{ (.+) \}/, ''); $1.split(', ').sort }
|
89
|
+
assert_equal expected_attr, result_attr
|
90
|
+
assert_equal expected, result
|
91
|
+
end
|
92
|
+
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>
|