haml-edge 2.3.60 → 2.3.61
Sign up to get free protection for your applications and to get access to all the features.
- data/EDGE_GEM_VERSION +1 -1
- data/VERSION +1 -1
- data/lib/haml/exec.rb +9 -13
- data/lib/haml/html/erb.rb +2 -2
- data/lib/haml/html.rb +24 -2
- data/test/haml/html2haml/erb_tests.rb +395 -0
- data/test/haml/html2haml_test.rb +12 -288
- metadata +4 -2
data/EDGE_GEM_VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.3.
|
1
|
+
2.3.61
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.3.
|
1
|
+
2.3.61
|
data/lib/haml/exec.rb
CHANGED
@@ -362,17 +362,7 @@ END
|
|
362
362
|
# @param args [Array<String>] The command-line arguments
|
363
363
|
def initialize(args)
|
364
364
|
super
|
365
|
-
|
366
365
|
@module_opts = {}
|
367
|
-
|
368
|
-
begin
|
369
|
-
require 'haml/html'
|
370
|
-
rescue LoadError => err
|
371
|
-
dep = err.message.scan(/^no such file to load -- (.*)/)[0]
|
372
|
-
raise err if @options[:trace] || dep.nil? || dep.empty?
|
373
|
-
$stderr.puts "Required dependency #{dep} not found!\n Use --trace for backtrace."
|
374
|
-
exit 1
|
375
|
-
end
|
376
366
|
end
|
377
367
|
|
378
368
|
# Tells optparse how to parse the arguments.
|
@@ -415,6 +405,8 @@ END
|
|
415
405
|
def process_result
|
416
406
|
super
|
417
407
|
|
408
|
+
require 'haml/html'
|
409
|
+
|
418
410
|
input = @options[:input]
|
419
411
|
output = @options[:output]
|
420
412
|
|
@@ -425,6 +417,11 @@ END
|
|
425
417
|
rescue ::Haml::Error => e
|
426
418
|
raise "#{e.is_a?(::Haml::SyntaxError) ? "Syntax error" : "Error"} on line " +
|
427
419
|
"#{get_line e}: #{e.message}"
|
420
|
+
rescue LoadError => err
|
421
|
+
dep = err.message.scan(/^no such file to load -- (.*)/)[0]
|
422
|
+
raise err if @options[:trace] || dep.nil? || dep.empty?
|
423
|
+
$stderr.puts "Required dependency #{dep} not found!\n Use --trace for backtrace."
|
424
|
+
exit 1
|
428
425
|
end
|
429
426
|
end
|
430
427
|
|
@@ -433,10 +430,7 @@ END
|
|
433
430
|
# @param args [Array<String>] The command-line arguments
|
434
431
|
def initialize(args)
|
435
432
|
super
|
436
|
-
|
437
433
|
@module_opts = {}
|
438
|
-
|
439
|
-
require 'sass/css'
|
440
434
|
end
|
441
435
|
|
442
436
|
# Tells optparse how to parse the arguments.
|
@@ -465,6 +459,8 @@ END
|
|
465
459
|
def process_result
|
466
460
|
super
|
467
461
|
|
462
|
+
require 'sass/css'
|
463
|
+
|
468
464
|
input = @options[:input]
|
469
465
|
output = @options[:output]
|
470
466
|
|
data/lib/haml/html/erb.rb
CHANGED
@@ -30,7 +30,7 @@ module Haml
|
|
30
30
|
|
31
31
|
# `html2haml` doesn't support HTML-escaped expressions.
|
32
32
|
def escaped_expr(code)
|
33
|
-
raise "html2haml doesn't support escaped expressions."
|
33
|
+
raise Haml::Error.new("html2haml doesn't support escaped expressions.")
|
34
34
|
end
|
35
35
|
|
36
36
|
# The ERB-to-Hamlized-HTML conversion has no preamble.
|
@@ -79,7 +79,7 @@ module Haml
|
|
79
79
|
|
80
80
|
# `html2haml` doesn't support debugging expressions.
|
81
81
|
def add_expr_debug(src, code)
|
82
|
-
raise "html2haml doesn't support debugging expressions."
|
82
|
+
raise Haml::Error.new("html2haml doesn't support debugging expressions.")
|
83
83
|
end
|
84
84
|
|
85
85
|
private
|
data/lib/haml/html.rb
CHANGED
@@ -233,7 +233,29 @@ module Haml
|
|
233
233
|
if options[:erb] && name[0...5] == 'haml:'
|
234
234
|
case name[5..-1]
|
235
235
|
when "loud"
|
236
|
-
|
236
|
+
lines = CGI.unescapeHTML(inner_text).split("\n").
|
237
|
+
map {|s| s.rstrip}.reject {|s| s.strip.empty?}
|
238
|
+
lines.first.gsub!(/^[ \t]*/, "= ")
|
239
|
+
|
240
|
+
if lines.size > 1 # Multiline script block
|
241
|
+
# Normalize the indentation so that the last line is the base
|
242
|
+
indent_str = lines.last[/^[ \t]*/]
|
243
|
+
indent_re = /^[ \t]{0,#{indent_str.count(" ") + 8 * indent_str.count("\t")}}/
|
244
|
+
lines.map! {|s| s.gsub!(indent_re, '')}
|
245
|
+
|
246
|
+
# Add an extra " " to make it indented relative to "= "
|
247
|
+
lines[1..-1].each {|s| s.gsub!(/^/, " ")}
|
248
|
+
|
249
|
+
# Add | at the end, properly aligned
|
250
|
+
length = lines.map {|s| s.size}.max + 1
|
251
|
+
lines.map! {|s| "%#{-length}s|" % s}
|
252
|
+
|
253
|
+
if next_sibling && next_sibling.is_a?(Hpricot::Elem) && next_sibling.name == "haml:loud" &&
|
254
|
+
next_sibling.inner_text.split("\n").reject {|s| s.strip.empty?}.size > 1
|
255
|
+
lines << "-#"
|
256
|
+
end
|
257
|
+
end
|
258
|
+
return lines.map {|s| output + s + "\n"}.join
|
237
259
|
when "silent"
|
238
260
|
return CGI.unescapeHTML(inner_text).split("\n").map do |line|
|
239
261
|
next "" if line.strip.empty?
|
@@ -272,7 +294,7 @@ module Haml
|
|
272
294
|
if child.is_a?(::Hpricot::Text)
|
273
295
|
if !child.to_s.include?("\n")
|
274
296
|
text = child.to_haml(tabs + 1, options)
|
275
|
-
return output + " " + text.lstrip unless text.chomp.include?("\n")
|
297
|
+
return output + " " + text.lstrip.gsub(/^\\/, '') unless text.chomp.include?("\n")
|
276
298
|
return output + "\n" + text
|
277
299
|
elsif ["pre", "textarea"].include?(name) ||
|
278
300
|
(name == "code" && parent.is_a?(::Hpricot::Elem) && parent.name == "pre")
|
@@ -0,0 +1,395 @@
|
|
1
|
+
module ErbTests
|
2
|
+
def test_erb
|
3
|
+
assert_equal '- foo = bar', render_erb('<% foo = bar %>')
|
4
|
+
assert_equal '- foo = bar', render_erb('<% foo = bar -%>')
|
5
|
+
assert_equal '= h @item.title', render_erb('<%=h @item.title %>')
|
6
|
+
assert_equal '= h @item.title', render_erb('<%=h @item.title -%>')
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_inline_erb
|
10
|
+
assert_equal("%p= foo", render_erb("<p><%= foo %></p>"))
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_non_inline_erb
|
14
|
+
assert_equal(<<HAML.rstrip, render_erb(<<HTML))
|
15
|
+
%p
|
16
|
+
= foo
|
17
|
+
HAML
|
18
|
+
<p>
|
19
|
+
<%= foo %>
|
20
|
+
</p>
|
21
|
+
HTML
|
22
|
+
assert_equal(<<HAML.rstrip, render_erb(<<HTML))
|
23
|
+
%p
|
24
|
+
= foo
|
25
|
+
HAML
|
26
|
+
<p>
|
27
|
+
<%= foo %></p>
|
28
|
+
HTML
|
29
|
+
assert_equal(<<HAML.rstrip, render_erb(<<HTML))
|
30
|
+
%p
|
31
|
+
= foo
|
32
|
+
HAML
|
33
|
+
<p><%= foo %>
|
34
|
+
</p>
|
35
|
+
HTML
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_erb_in_cdata
|
39
|
+
assert_equal(<<HAML.rstrip, render_erb(<<HTML))
|
40
|
+
:cdata
|
41
|
+
Foo \#{bar} baz
|
42
|
+
HAML
|
43
|
+
<![CDATA[Foo <%= bar %> baz]]>
|
44
|
+
HTML
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_erb_in_script
|
48
|
+
assert_equal(<<HAML.rstrip, render_erb(<<HTML))
|
49
|
+
:javascript
|
50
|
+
function foo() {
|
51
|
+
return \#{foo.to_json};
|
52
|
+
}
|
53
|
+
HAML
|
54
|
+
<script type="text/javascript">
|
55
|
+
function foo() {
|
56
|
+
return <%= foo.to_json %>;
|
57
|
+
}
|
58
|
+
</script>
|
59
|
+
HTML
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_erb_in_line
|
63
|
+
assert_equal 'foo bar #{baz}', render_erb('foo bar <%= baz %>')
|
64
|
+
assert_equal 'foo bar #{baz}! Bang.', render_erb('foo bar <%= baz %>! Bang.')
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_erb_multi_in_line
|
68
|
+
assert_equal('foo bar #{baz}! Bang #{bop}.',
|
69
|
+
render_erb('foo bar <%= baz %>! Bang <%= bop %>.'))
|
70
|
+
assert_equal('foo bar #{baz}#{bop}!',
|
71
|
+
render_erb('foo bar <%= baz %><%= bop %>!'))
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_erb_with_html_special_chars
|
75
|
+
assert_equal '= 3 < 5 ? "OK" : "Your computer is b0rken"',
|
76
|
+
render_erb('<%= 3 < 5 ? "OK" : "Your computer is b0rken" %>')
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_erb_in_class_attribute
|
80
|
+
assert_equal "%div{:class => dyna_class} I have a dynamic attribute",
|
81
|
+
render_erb('<div class="<%= dyna_class %>">I have a dynamic attribute</div>')
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_erb_in_id_attribute
|
85
|
+
assert_equal "%div{:id => dyna_id} I have a dynamic attribute",
|
86
|
+
render_erb('<div id="<%= dyna_id %>">I have a dynamic attribute</div>')
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_erb_in_attribute_results_in_string_interpolation
|
90
|
+
assert_equal('%div{:id => "item_#{i}"} Ruby string interpolation FTW',
|
91
|
+
render_erb('<div id="item_<%= i %>">Ruby string interpolation FTW</div>'))
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_erb_in_attribute_with_trailing_content
|
95
|
+
assert_equal('%div{:class => "#{12}!"} Bang!',
|
96
|
+
render_erb('<div class="<%= 12 %>!">Bang!</div>'))
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_erb_in_html_escaped_attribute
|
100
|
+
assert_equal '%div{:class => "foo"} Bang!',
|
101
|
+
render_erb('<div class="<%= "foo" %>">Bang!</div>')
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_erb_in_attribute_to_multiple_interpolations
|
105
|
+
assert_equal('%div{:class => "#{12} + #{13}"} Math is super',
|
106
|
+
render_erb('<div class="<%= 12 %> + <%= 13 %>">Math is super</div>'))
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_whitespace_eating_erb_tags
|
110
|
+
assert_equal '- form_for', render_erb('<%- form_for -%>')
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_interpolation_in_erb
|
114
|
+
assert_equal('= "Foo #{bar} baz"', render_erb('<%= "Foo #{bar} baz" %>'))
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_interpolation_in_erb_attrs
|
118
|
+
assert_equal('%p{:foo => "#{bar} baz"}',
|
119
|
+
render_erb('<p foo="<%= "#{bar} baz" %>"></p>'))
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_multiline_erb_silent_script
|
123
|
+
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
124
|
+
.blah
|
125
|
+
- foo
|
126
|
+
- bar
|
127
|
+
- baz
|
128
|
+
%p foo
|
129
|
+
HAML
|
130
|
+
<div class="blah">
|
131
|
+
<%
|
132
|
+
foo
|
133
|
+
bar
|
134
|
+
baz
|
135
|
+
%>
|
136
|
+
<p>foo</p>
|
137
|
+
</div>
|
138
|
+
ERB
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_multiline_erb_loud_script
|
142
|
+
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
143
|
+
.blah
|
144
|
+
= foo + |
|
145
|
+
bar.baz.bang + |
|
146
|
+
baz |
|
147
|
+
%p foo
|
148
|
+
HAML
|
149
|
+
<div class="blah">
|
150
|
+
<%=
|
151
|
+
foo +
|
152
|
+
bar.baz.bang +
|
153
|
+
baz
|
154
|
+
%>
|
155
|
+
<p>foo</p>
|
156
|
+
</div>
|
157
|
+
ERB
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_weirdly_indented_multiline_erb_loud_script
|
161
|
+
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
162
|
+
.blah
|
163
|
+
= foo + |
|
164
|
+
bar.baz.bang + |
|
165
|
+
baz |
|
166
|
+
%p foo
|
167
|
+
HAML
|
168
|
+
<div class="blah">
|
169
|
+
<%=
|
170
|
+
foo +
|
171
|
+
bar.baz.bang +
|
172
|
+
baz
|
173
|
+
%>
|
174
|
+
<p>foo</p>
|
175
|
+
</div>
|
176
|
+
ERB
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_two_multiline_erb_loud_scripts
|
180
|
+
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
181
|
+
.blah
|
182
|
+
= foo + |
|
183
|
+
bar.baz.bang + |
|
184
|
+
baz |
|
185
|
+
-#
|
186
|
+
= foo.bar do |
|
187
|
+
bang |
|
188
|
+
end |
|
189
|
+
%p foo
|
190
|
+
HAML
|
191
|
+
<div class="blah">
|
192
|
+
<%=
|
193
|
+
foo +
|
194
|
+
bar.baz.bang +
|
195
|
+
baz
|
196
|
+
%>
|
197
|
+
<%= foo.bar do
|
198
|
+
bang
|
199
|
+
end %>
|
200
|
+
<p>foo</p>
|
201
|
+
</div>
|
202
|
+
ERB
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_multiline_then_single_line_erb_loud_scripts
|
206
|
+
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
207
|
+
.blah
|
208
|
+
= foo + |
|
209
|
+
bar.baz.bang + |
|
210
|
+
baz |
|
211
|
+
= foo.bar
|
212
|
+
%p foo
|
213
|
+
HAML
|
214
|
+
<div class="blah">
|
215
|
+
<%=
|
216
|
+
foo +
|
217
|
+
bar.baz.bang +
|
218
|
+
baz
|
219
|
+
%>
|
220
|
+
<%= foo.bar %>
|
221
|
+
<p>foo</p>
|
222
|
+
</div>
|
223
|
+
ERB
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_multiline_erb_but_really_single_line
|
227
|
+
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
228
|
+
.blah
|
229
|
+
= foo
|
230
|
+
%p foo
|
231
|
+
HAML
|
232
|
+
<div class="blah">
|
233
|
+
<%=
|
234
|
+
foo
|
235
|
+
%>
|
236
|
+
<p>foo</p>
|
237
|
+
</div>
|
238
|
+
ERB
|
239
|
+
end
|
240
|
+
|
241
|
+
### Block Parsing
|
242
|
+
|
243
|
+
def test_block_parsing
|
244
|
+
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
245
|
+
- foo do
|
246
|
+
%p bar
|
247
|
+
HAML
|
248
|
+
<% foo do %>
|
249
|
+
<p>bar</p>
|
250
|
+
<% end %>
|
251
|
+
ERB
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_block_parsing_with_args
|
255
|
+
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
256
|
+
- foo do |a, b, c|
|
257
|
+
%p bar
|
258
|
+
HAML
|
259
|
+
<% foo do |a, b, c| %>
|
260
|
+
<p>bar</p>
|
261
|
+
<% end %>
|
262
|
+
ERB
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_block_parsing_with_equals
|
266
|
+
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
267
|
+
= foo do
|
268
|
+
%p bar
|
269
|
+
HAML
|
270
|
+
<%= foo do %>
|
271
|
+
<p>bar</p>
|
272
|
+
<% end %>
|
273
|
+
ERB
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_block_parsing_with_modified_end
|
277
|
+
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
278
|
+
- foo do
|
279
|
+
blah
|
280
|
+
- end.bip
|
281
|
+
HAML
|
282
|
+
<% foo do %>
|
283
|
+
blah
|
284
|
+
<% end.bip %>
|
285
|
+
ERB
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_block_parsing_with_modified_end_with_block
|
289
|
+
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
290
|
+
- foo do
|
291
|
+
blah
|
292
|
+
- end.bip do
|
293
|
+
brang
|
294
|
+
HAML
|
295
|
+
<% foo do %>
|
296
|
+
blah
|
297
|
+
<% end.bip do %>
|
298
|
+
brang
|
299
|
+
<% end %>
|
300
|
+
ERB
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_multiline_block_opener
|
304
|
+
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
305
|
+
- foo bar
|
306
|
+
- baz bang
|
307
|
+
- biddle do
|
308
|
+
foo
|
309
|
+
HAML
|
310
|
+
<% foo bar
|
311
|
+
baz bang
|
312
|
+
biddle do %>
|
313
|
+
foo
|
314
|
+
<% end %>
|
315
|
+
ERB
|
316
|
+
end
|
317
|
+
|
318
|
+
def test_if_elsif_else_parsing
|
319
|
+
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
320
|
+
- if foo
|
321
|
+
%p bar
|
322
|
+
- elsif bar.foo("zip")
|
323
|
+
#bang baz
|
324
|
+
- else
|
325
|
+
%strong bibble
|
326
|
+
HAML
|
327
|
+
<% if foo %>
|
328
|
+
<p>bar</p>
|
329
|
+
<% elsif bar.foo("zip") %>
|
330
|
+
<div id="bang">baz</div>
|
331
|
+
<% else %>
|
332
|
+
<strong>bibble</strong>
|
333
|
+
<% end %>
|
334
|
+
ERB
|
335
|
+
end
|
336
|
+
|
337
|
+
def test_case_when_parsing
|
338
|
+
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
339
|
+
- case foo.bar
|
340
|
+
- when "bip"
|
341
|
+
%p bip
|
342
|
+
- when "bop"
|
343
|
+
%p BOP
|
344
|
+
- when bizzle.bang.boop.blip
|
345
|
+
%em BIZZLE BANG BOOP BLIP
|
346
|
+
HAML
|
347
|
+
<% case foo.bar %>
|
348
|
+
<% when "bip" %>
|
349
|
+
<p>bip</p>
|
350
|
+
<% when "bop" %>
|
351
|
+
<p>BOP</p>
|
352
|
+
<% when bizzle.bang.boop.blip %>
|
353
|
+
<em>BIZZLE BANG BOOP BLIP</em>
|
354
|
+
<% end %>
|
355
|
+
ERB
|
356
|
+
|
357
|
+
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
358
|
+
- case foo.bar
|
359
|
+
- when "bip"
|
360
|
+
%p bip
|
361
|
+
- when "bop"
|
362
|
+
%p BOP
|
363
|
+
- when bizzle.bang.boop.blip
|
364
|
+
%em BIZZLE BANG BOOP BLIP
|
365
|
+
HAML
|
366
|
+
<% case foo.bar
|
367
|
+
when "bip" %>
|
368
|
+
<p>bip</p>
|
369
|
+
<% when "bop" %>
|
370
|
+
<p>BOP</p>
|
371
|
+
<% when bizzle.bang.boop.blip %>
|
372
|
+
<em>BIZZLE BANG BOOP BLIP</em>
|
373
|
+
<% end %>
|
374
|
+
ERB
|
375
|
+
end
|
376
|
+
|
377
|
+
def test_begin_rescue_ensure
|
378
|
+
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
379
|
+
- begin
|
380
|
+
%p a
|
381
|
+
- rescue FooException => e
|
382
|
+
%p b
|
383
|
+
- ensure
|
384
|
+
%p c
|
385
|
+
HAML
|
386
|
+
<% begin %>
|
387
|
+
<p>a</p>
|
388
|
+
<% rescue FooException => e %>
|
389
|
+
<p>b</p>
|
390
|
+
<% ensure %>
|
391
|
+
<p>c</p>
|
392
|
+
<% end %>
|
393
|
+
ERB
|
394
|
+
end
|
395
|
+
end
|
data/test/haml/html2haml_test.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require File.dirname(__FILE__) + '/../test_helper'
|
3
|
+
require File.dirname(__FILE__) + '/html2haml/erb_tests'
|
3
4
|
require 'haml/html'
|
4
5
|
|
5
6
|
class Html2HamlTest < Test::Unit::TestCase
|
@@ -205,300 +206,23 @@ HAML
|
|
205
206
|
HTML
|
206
207
|
end
|
207
208
|
|
208
|
-
|
209
|
-
|
210
|
-
def test_erb
|
211
|
-
assert_equal '- foo = bar', render_erb('<% foo = bar %>')
|
212
|
-
assert_equal '- foo = bar', render_erb('<% foo = bar -%>')
|
213
|
-
assert_equal '= h @item.title', render_erb('<%=h @item.title %>')
|
214
|
-
assert_equal '= h @item.title', render_erb('<%=h @item.title -%>')
|
215
|
-
end
|
216
|
-
|
217
|
-
def test_inline_erb
|
218
|
-
assert_equal("%p= foo", render_erb("<p><%= foo %></p>"))
|
219
|
-
end
|
220
|
-
|
221
|
-
def test_non_inline_erb
|
222
|
-
assert_equal(<<HAML.rstrip, render_erb(<<HTML))
|
223
|
-
%p
|
224
|
-
= foo
|
225
|
-
HAML
|
226
|
-
<p>
|
227
|
-
<%= foo %>
|
228
|
-
</p>
|
229
|
-
HTML
|
230
|
-
assert_equal(<<HAML.rstrip, render_erb(<<HTML))
|
231
|
-
%p
|
232
|
-
= foo
|
233
|
-
HAML
|
234
|
-
<p>
|
235
|
-
<%= foo %></p>
|
236
|
-
HTML
|
237
|
-
assert_equal(<<HAML.rstrip, render_erb(<<HTML))
|
238
|
-
%p
|
239
|
-
= foo
|
240
|
-
HAML
|
241
|
-
<p><%= foo %>
|
242
|
-
</p>
|
243
|
-
HTML
|
244
|
-
end
|
245
|
-
|
246
|
-
def test_erb_in_cdata
|
247
|
-
assert_equal(<<HAML.rstrip, render_erb(<<HTML))
|
248
|
-
:cdata
|
249
|
-
Foo \#{bar} baz
|
250
|
-
HAML
|
251
|
-
<![CDATA[Foo <%= bar %> baz]]>
|
252
|
-
HTML
|
209
|
+
def test_minus_in_tag
|
210
|
+
assert_equal("%p - foo bar -", render("<p>- foo bar -</p>"))
|
253
211
|
end
|
254
212
|
|
255
|
-
def
|
256
|
-
assert_equal(
|
257
|
-
:javascript
|
258
|
-
function foo() {
|
259
|
-
return \#{foo.to_json};
|
260
|
-
}
|
261
|
-
HAML
|
262
|
-
<script type="text/javascript">
|
263
|
-
function foo() {
|
264
|
-
return <%= foo.to_json %>;
|
265
|
-
}
|
266
|
-
</script>
|
267
|
-
HTML
|
268
|
-
end
|
269
|
-
|
270
|
-
def test_erb_in_line
|
271
|
-
assert_equal 'foo bar #{baz}', render_erb('foo bar <%= baz %>')
|
272
|
-
assert_equal 'foo bar #{baz}! Bang.', render_erb('foo bar <%= baz %>! Bang.')
|
213
|
+
def test_equals_in_tag
|
214
|
+
assert_equal("%p = foo bar =", render("<p>= foo bar =</p>"))
|
273
215
|
end
|
274
216
|
|
275
|
-
def
|
276
|
-
assert_equal(
|
277
|
-
render_erb('foo bar <%= baz %>! Bang <%= bop %>.'))
|
278
|
-
assert_equal('foo bar #{baz}#{bop}!',
|
279
|
-
render_erb('foo bar <%= baz %><%= bop %>!'))
|
217
|
+
def test_hash_in_tag
|
218
|
+
assert_equal("%p # foo bar #", render("<p># foo bar #</p>"))
|
280
219
|
end
|
281
220
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
def test_erb_in_class_attribute
|
288
|
-
assert_equal "%div{:class => dyna_class} I have a dynamic attribute",
|
289
|
-
render_erb('<div class="<%= dyna_class %>">I have a dynamic attribute</div>')
|
290
|
-
end
|
291
|
-
|
292
|
-
def test_erb_in_id_attribute
|
293
|
-
assert_equal "%div{:id => dyna_id} I have a dynamic attribute",
|
294
|
-
render_erb('<div id="<%= dyna_id %>">I have a dynamic attribute</div>')
|
295
|
-
end
|
296
|
-
|
297
|
-
def test_erb_in_attribute_results_in_string_interpolation
|
298
|
-
assert_equal('%div{:id => "item_#{i}"} Ruby string interpolation FTW',
|
299
|
-
render_erb('<div id="item_<%= i %>">Ruby string interpolation FTW</div>'))
|
300
|
-
end
|
301
|
-
|
302
|
-
def test_erb_in_attribute_with_trailing_content
|
303
|
-
assert_equal('%div{:class => "#{12}!"} Bang!',
|
304
|
-
render_erb('<div class="<%= 12 %>!">Bang!</div>'))
|
305
|
-
end
|
306
|
-
|
307
|
-
def test_erb_in_html_escaped_attribute
|
308
|
-
assert_equal '%div{:class => "foo"} Bang!',
|
309
|
-
render_erb('<div class="<%= "foo" %>">Bang!</div>')
|
310
|
-
end
|
311
|
-
|
312
|
-
def test_erb_in_attribute_to_multiple_interpolations
|
313
|
-
assert_equal('%div{:class => "#{12} + #{13}"} Math is super',
|
314
|
-
render_erb('<div class="<%= 12 %> + <%= 13 %>">Math is super</div>'))
|
315
|
-
end
|
316
|
-
|
317
|
-
def test_whitespace_eating_erb_tags
|
318
|
-
assert_equal '- form_for', render_erb('<%- form_for -%>')
|
319
|
-
end
|
320
|
-
|
321
|
-
def test_interpolation_in_erb
|
322
|
-
assert_equal('= "Foo #{bar} baz"', render_erb('<%= "Foo #{bar} baz" %>'))
|
323
|
-
end
|
324
|
-
|
325
|
-
def test_interpolation_in_erb_attrs
|
326
|
-
assert_equal('%p{:foo => "#{bar} baz"}',
|
327
|
-
render_erb('<p foo="<%= "#{bar} baz" %>"></p>'))
|
328
|
-
end
|
329
|
-
|
330
|
-
def test_multiline_erb_silent_script
|
331
|
-
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
332
|
-
.blah
|
333
|
-
- foo
|
334
|
-
- bar
|
335
|
-
- baz
|
336
|
-
%p foo
|
337
|
-
HAML
|
338
|
-
<div class="blah">
|
339
|
-
<%
|
340
|
-
foo
|
341
|
-
bar
|
342
|
-
baz
|
343
|
-
%>
|
344
|
-
<p>foo</p>
|
345
|
-
</div>
|
346
|
-
ERB
|
347
|
-
end
|
348
|
-
|
349
|
-
### Block Parsing
|
350
|
-
|
351
|
-
def test_block_parsing
|
352
|
-
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
353
|
-
- foo do
|
354
|
-
%p bar
|
355
|
-
HAML
|
356
|
-
<% foo do %>
|
357
|
-
<p>bar</p>
|
358
|
-
<% end %>
|
359
|
-
ERB
|
360
|
-
end
|
361
|
-
|
362
|
-
def test_block_parsing_with_args
|
363
|
-
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
364
|
-
- foo do |a, b, c|
|
365
|
-
%p bar
|
366
|
-
HAML
|
367
|
-
<% foo do |a, b, c| %>
|
368
|
-
<p>bar</p>
|
369
|
-
<% end %>
|
370
|
-
ERB
|
371
|
-
end
|
372
|
-
|
373
|
-
def test_block_parsing_with_equals
|
374
|
-
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
375
|
-
= foo do
|
376
|
-
%p bar
|
377
|
-
HAML
|
378
|
-
<%= foo do %>
|
379
|
-
<p>bar</p>
|
380
|
-
<% end %>
|
381
|
-
ERB
|
382
|
-
end
|
383
|
-
|
384
|
-
def test_block_parsing_with_modified_end
|
385
|
-
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
386
|
-
- foo do
|
387
|
-
blah
|
388
|
-
- end.bip
|
389
|
-
HAML
|
390
|
-
<% foo do %>
|
391
|
-
blah
|
392
|
-
<% end.bip %>
|
393
|
-
ERB
|
394
|
-
end
|
395
|
-
|
396
|
-
def test_block_parsing_with_modified_end_with_block
|
397
|
-
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
398
|
-
- foo do
|
399
|
-
blah
|
400
|
-
- end.bip do
|
401
|
-
brang
|
402
|
-
HAML
|
403
|
-
<% foo do %>
|
404
|
-
blah
|
405
|
-
<% end.bip do %>
|
406
|
-
brang
|
407
|
-
<% end %>
|
408
|
-
ERB
|
409
|
-
end
|
410
|
-
|
411
|
-
def test_multiline_block_opener
|
412
|
-
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
413
|
-
- foo bar
|
414
|
-
- baz bang
|
415
|
-
- biddle do
|
416
|
-
foo
|
417
|
-
HAML
|
418
|
-
<% foo bar
|
419
|
-
baz bang
|
420
|
-
biddle do %>
|
421
|
-
foo
|
422
|
-
<% end %>
|
423
|
-
ERB
|
424
|
-
end
|
425
|
-
|
426
|
-
def test_if_elsif_else_parsing
|
427
|
-
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
428
|
-
- if foo
|
429
|
-
%p bar
|
430
|
-
- elsif bar.foo("zip")
|
431
|
-
#bang baz
|
432
|
-
- else
|
433
|
-
%strong bibble
|
434
|
-
HAML
|
435
|
-
<% if foo %>
|
436
|
-
<p>bar</p>
|
437
|
-
<% elsif bar.foo("zip") %>
|
438
|
-
<div id="bang">baz</div>
|
439
|
-
<% else %>
|
440
|
-
<strong>bibble</strong>
|
441
|
-
<% end %>
|
442
|
-
ERB
|
443
|
-
end
|
444
|
-
|
445
|
-
def test_case_when_parsing
|
446
|
-
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
447
|
-
- case foo.bar
|
448
|
-
- when "bip"
|
449
|
-
%p bip
|
450
|
-
- when "bop"
|
451
|
-
%p BOP
|
452
|
-
- when bizzle.bang.boop.blip
|
453
|
-
%em BIZZLE BANG BOOP BLIP
|
454
|
-
HAML
|
455
|
-
<% case foo.bar %>
|
456
|
-
<% when "bip" %>
|
457
|
-
<p>bip</p>
|
458
|
-
<% when "bop" %>
|
459
|
-
<p>BOP</p>
|
460
|
-
<% when bizzle.bang.boop.blip %>
|
461
|
-
<em>BIZZLE BANG BOOP BLIP</em>
|
462
|
-
<% end %>
|
463
|
-
ERB
|
464
|
-
|
465
|
-
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
466
|
-
- case foo.bar
|
467
|
-
- when "bip"
|
468
|
-
%p bip
|
469
|
-
- when "bop"
|
470
|
-
%p BOP
|
471
|
-
- when bizzle.bang.boop.blip
|
472
|
-
%em BIZZLE BANG BOOP BLIP
|
473
|
-
HAML
|
474
|
-
<% case foo.bar
|
475
|
-
when "bip" %>
|
476
|
-
<p>bip</p>
|
477
|
-
<% when "bop" %>
|
478
|
-
<p>BOP</p>
|
479
|
-
<% when bizzle.bang.boop.blip %>
|
480
|
-
<em>BIZZLE BANG BOOP BLIP</em>
|
481
|
-
<% end %>
|
482
|
-
ERB
|
483
|
-
end
|
484
|
-
|
485
|
-
def test_begin_rescue_ensure
|
486
|
-
assert_equal(<<HAML.rstrip, render_erb(<<ERB))
|
487
|
-
- begin
|
488
|
-
%p a
|
489
|
-
- rescue FooException => e
|
490
|
-
%p b
|
491
|
-
- ensure
|
492
|
-
%p c
|
493
|
-
HAML
|
494
|
-
<% begin %>
|
495
|
-
<p>a</p>
|
496
|
-
<% rescue FooException => e %>
|
497
|
-
<p>b</p>
|
498
|
-
<% ensure %>
|
499
|
-
<p>c</p>
|
500
|
-
<% end %>
|
501
|
-
ERB
|
221
|
+
begin
|
222
|
+
require 'haml/html/erb'
|
223
|
+
include ErbTests
|
224
|
+
rescue LoadError => e
|
225
|
+
puts "\n** Couldn't require #{e.message[/-- (.*)$/, 1]}, skipping some tests"
|
502
226
|
end
|
503
227
|
|
504
228
|
# Encodings
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haml-edge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.61
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Weizenbaum
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-10-
|
13
|
+
date: 2009-10-29 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -190,6 +190,8 @@ files:
|
|
190
190
|
- test/haml/templates/very_basic.haml
|
191
191
|
- test/haml/templates/whitespace_handling.haml
|
192
192
|
- test/haml/spec_test.rb
|
193
|
+
- test/haml/html2haml
|
194
|
+
- test/haml/html2haml/erb_tests.rb
|
193
195
|
- test/linked_rails.rb
|
194
196
|
- test/sass
|
195
197
|
- test/sass/css2sass_test.rb
|