haml 3.1.0.alpha.27 → 3.1.0.alpha.28

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of haml might be problematic. Click here for more details.

data/EDGE_GEM_VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0.alpha.27
1
+ 3.1.0.alpha.28
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0.alpha.27
1
+ 3.1.0.alpha.28
data/lib/haml/buffer.rb CHANGED
@@ -187,38 +187,14 @@ module Haml
187
187
  <% end %>
188
188
  RUBY
189
189
 
190
- # Takes the various information about the opening tag for an element,
191
- # formats it, and appends it to the buffer.
192
- def open_tag(name, self_closing, try_one_line, preserve_tag, escape_html, class_id,
193
- nuke_outer_whitespace, nuke_inner_whitespace, obj_ref, content, *attributes_hashes)
194
- tabulation = @real_tabs
195
-
190
+ def attributes(class_id, obj_ref, *attributes_hashes)
196
191
  attributes = class_id
197
192
  attributes_hashes.each do |old|
198
193
  self.class.merge_attrs(attributes, to_hash(old.map {|k, v| [k.to_s, v]}))
199
194
  end
200
195
  self.class.merge_attrs(attributes, parse_object_ref(obj_ref)) if obj_ref
201
-
202
- if self_closing && xhtml?
203
- str = " />" + (nuke_outer_whitespace ? "" : "\n")
204
- else
205
- str = ">" + ((if self_closing && html?
206
- nuke_outer_whitespace
207
- else
208
- try_one_line || preserve_tag || nuke_inner_whitespace
209
- end) ? "" : "\n")
210
- end
211
-
212
- attributes = Compiler.build_attributes(
196
+ Compiler.build_attributes(
213
197
  html?, @options[:attr_wrapper], @options[:escape_attrs], attributes)
214
- @buffer << "#{nuke_outer_whitespace || @options[:ugly] ? '' : tabs(tabulation)}<#{name}#{attributes}#{str}"
215
-
216
- if content
217
- @buffer << "#{content}</#{name}>" << (nuke_outer_whitespace ? "" : "\n")
218
- return
219
- end
220
-
221
- @real_tabs += 1 unless self_closing || nuke_inner_whitespace
222
198
  end
223
199
 
224
200
  # Remove the whitespace from the right side of the buffer string.
data/lib/haml/compiler.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'cgi'
2
+
1
3
  module Haml
2
4
  module Compiler
3
5
  include Haml::Util
@@ -130,7 +132,6 @@ END
130
132
  @dont_indent_next_line = dont_indent_next_line
131
133
  return if tag_closed
132
134
  else
133
- content = parse ? 'nil' : inspect_obj(value)
134
135
  if attributes_hashes.empty?
135
136
  attributes_hashes = ''
136
137
  elsif attributes_hashes.size == 1
@@ -139,11 +140,27 @@ END
139
140
  attributes_hashes = ", (#{attributes_hashes.join(").merge(")})"
140
141
  end
141
142
 
142
- args = [t[:name], t[:self_closing], !block_given?, t[:preserve_tag],
143
- t[:escape_html], t[:attributes], t[:nuke_outer_whitespace],
144
- t[:nuke_inner_whitespace]].map {|v| inspect_obj(v)}.join(', ')
145
- push_silent "_hamlout.open_tag(#{args}, #{object_ref}, #{content}#{attributes_hashes})"
146
- @dont_tab_up_next_text = @dont_indent_next_line = dont_indent_next_line
143
+ push_merged_text "<#{t[:name]}", 0, !t[:nuke_outer_whitespace]
144
+ push_generated_script(
145
+ "_hamlout.attributes(#{inspect_obj(t[:attributes])}, #{object_ref}#{attributes_hashes})")
146
+ concat_merged_text(
147
+ if t[:self_closing] && xhtml?
148
+ " />" + (t[:nuke_outer_whitespace] ? "" : "\n")
149
+ else
150
+ ">" + ((if t[:self_closing] && html?
151
+ t[:nuke_outer_whitespace]
152
+ else
153
+ !block_given? || t[:preserve_tag] || t[:nuke_inner_whitespace]
154
+ end) ? "" : "\n")
155
+ end)
156
+
157
+ if value && !parse
158
+ concat_merged_text("#{value}</#{t[:name]}>#{t[:nuke_outer_whitespace] ? "" : "\n"}")
159
+ else
160
+ @to_merge << [:text, '', 1] unless t[:nuke_inner_whitespace]
161
+ end
162
+
163
+ @dont_indent_next_line = dont_indent_next_line
147
164
  end
148
165
 
149
166
  return if t[:self_closing]
@@ -309,9 +326,7 @@ END
309
326
  push_merged_text '' unless opts[:in_tag]
310
327
 
311
328
  unless block_given?
312
- script = no_format ? "#{text}\n" : "#{static_method}(#{output_expr});"
313
- @to_merge << [:script, resolve_newlines + script]
314
- @output_line += script.count("\n")
329
+ push_generated_script(no_format ? "#{text}\n" : "#{static_method}(#{output_expr});")
315
330
  concat_merged_text("\n") unless opts[:in_tag] || opts[:nuke_inner_whitespace]
316
331
  return
317
332
  end
@@ -324,6 +339,11 @@ END
324
339
  concat_merged_text("\n") unless opts[:in_tag] || opts[:nuke_inner_whitespace] || @options[:ugly]
325
340
  end
326
341
 
342
+ def push_generated_script(text)
343
+ @to_merge << [:script, resolve_newlines + text]
344
+ @output_line += text.count("\n")
345
+ end
346
+
327
347
  # This is a class method so it can be accessed from Buffer.
328
348
  def self.build_attributes(is_html, attr_wrapper, escape_attrs, attributes = {})
329
349
  quote_escape = attr_wrapper == '"' ? "&quot;" : "&apos;"
data/lib/haml/parser.rb CHANGED
@@ -317,16 +317,21 @@ END
317
317
  end
318
318
 
319
319
  attributes = Parser.parse_class_and_id(attributes)
320
- attributes_hashes.map! do |syntax, attributes_hash|
321
- if syntax == :old
322
- static_attributes = parse_static_hash(attributes_hash)
323
- attributes_hash = nil if static_attributes
324
- else
325
- static_attributes, attributes_hash = attributes_hash
326
- end
320
+ attributes_list = []
321
+
322
+ if attributes_hashes[:new]
323
+ static_attributes, attributes_hash = attributes_hashes[:new]
324
+ Buffer.merge_attrs(attributes, static_attributes) if static_attributes
325
+ attributes_list << attributes_hash
326
+ end
327
+
328
+ if attributes_hashes[:old]
329
+ static_attributes = parse_static_hash(attributes_hashes[:old])
327
330
  Buffer.merge_attrs(attributes, static_attributes) if static_attributes
328
- attributes_hash
329
- end.compact!
331
+ attributes_list << attributes_hashes[:old] unless static_attributes || @options[:suppress_eval]
332
+ end
333
+
334
+ attributes_list.compact!
330
335
 
331
336
  raise SyntaxError.new("Illegal nesting: nesting within a self-closing tag is illegal.", @next_line.index) if block_opened? && self_closing
332
337
  raise SyntaxError.new("There's no Ruby code for #{action} to evaluate.", last_line - 1) if parse && value.empty?
@@ -341,7 +346,7 @@ END
341
346
  value = handle_ruby_multiline(value) if parse
342
347
 
343
348
  ParseNode.new(:tag, @index, :name => tag_name, :attributes => attributes,
344
- :attributes_hashes => attributes_hashes, :self_closing => self_closing,
349
+ :attributes_hashes => attributes_list, :self_closing => self_closing,
345
350
  :nuke_inner_whitespace => nuke_inner_whitespace,
346
351
  :nuke_outer_whitespace => nuke_outer_whitespace, :object_ref => object_ref,
347
352
  :escape_html => escape_html, :preserve_tag => preserve_tag,
@@ -462,17 +467,17 @@ END
462
467
 
463
468
  new_attributes_hash = old_attributes_hash = last_line = nil
464
469
  object_ref = "nil"
465
- attributes_hashes = []
470
+ attributes_hashes = {}
466
471
  while rest
467
472
  case rest[0]
468
473
  when ?{
469
474
  break if old_attributes_hash
470
475
  old_attributes_hash, rest, last_line = parse_old_attributes(rest)
471
- attributes_hashes << [:old, old_attributes_hash]
476
+ attributes_hashes[:old] = old_attributes_hash
472
477
  when ?(
473
478
  break if new_attributes_hash
474
479
  new_attributes_hash, rest, last_line = parse_new_attributes(rest)
475
- attributes_hashes << [:new, new_attributes_hash]
480
+ attributes_hashes[:new] = new_attributes_hash
476
481
  when ?[
477
482
  break unless object_ref == "nil"
478
483
  object_ref, rest = balance(rest, ?[, ?])
data/test/benchmark.rb CHANGED
@@ -12,7 +12,7 @@ end
12
12
 
13
13
  require File.dirname(__FILE__) + '/../lib/haml'
14
14
  require File.dirname(__FILE__) + '/linked_rails'
15
- %w[rubygems erb erubis markaby active_support action_controller
15
+ %w[rubygems erb erubis active_support action_controller
16
16
  action_view action_pack haml/template rbench].each {|dep| require(dep)}
17
17
 
18
18
  def view
@@ -40,7 +40,6 @@ RBench.run(times) do
40
40
  directory = File.dirname(__FILE__) + '/haml'
41
41
  haml_template = File.read("#{directory}/templates/#{template_name}.haml")
42
42
  erb_template = File.read("#{directory}/erb/#{template_name}.erb")
43
- markaby_template = File.read("#{directory}/markaby/#{template_name}.mab")
44
43
 
45
44
  report "Cached" do
46
45
  obj = Object.new
@@ -291,6 +291,31 @@ HAML
291
291
  assert_equal(hash, {:color => 'red'})
292
292
  end
293
293
 
294
+ def test_ugly_semi_prerendered_tags
295
+ assert_equal(<<HTML, render(<<HAML, :ugly => true))
296
+ <p a='2'></p>
297
+ <p a='2'>foo</p>
298
+ <p a='2' />
299
+ <p a='2'>foo</p>
300
+ <p a='2'>foo
301
+ bar</p>
302
+ <p a='2'>foo
303
+ bar</p>
304
+ <p a='2'>
305
+ foo
306
+ </p>
307
+ HTML
308
+ %p{:a => 1 + 1}
309
+ %p{:a => 1 + 1} foo
310
+ %p{:a => 1 + 1}/
311
+ %p{:a => 1 + 1}= "foo"
312
+ %p{:a => 1 + 1}= "foo\\nbar"
313
+ %p{:a => 1 + 1}~ "foo\\nbar"
314
+ %p{:a => 1 + 1}
315
+ foo
316
+ HAML
317
+ end
318
+
294
319
  def test_end_of_file_multiline
295
320
  assert_equal("<p>0</p>\n<p>1</p>\n<p>2</p>\n", render("- for i in (0...3)\n %p= |\n i |"))
296
321
  end
@@ -1470,7 +1495,7 @@ HAML
1470
1495
 
1471
1496
  def test_new_attribute_ids
1472
1497
  assert_equal("<div id='foo_bar'></div>\n", render("#foo(id='bar')"))
1473
- assert_equal("<div id='foo_bar_baz'></div>\n", render("#foo{:id => 'bar'}(id='baz')"))
1498
+ assert_equal("<div id='foo_baz_bar'></div>\n", render("#foo{:id => 'bar'}(id='baz')"))
1474
1499
  assert_equal("<div id='foo_baz_bar'></div>\n", render("#foo(id='baz'){:id => 'bar'}"))
1475
1500
  foo = User.new(42)
1476
1501
  assert_equal("<div class='struct_user' id='foo_baz_bar_struct_user_42'></div>\n",
@@ -1479,7 +1504,7 @@ HAML
1479
1504
  render("#foo(id='baz')[foo]{:id => 'bar'}", :locals => {:foo => foo}))
1480
1505
  assert_equal("<div class='struct_user' id='foo_baz_bar_struct_user_42'></div>\n",
1481
1506
  render("#foo[foo](id='baz'){:id => 'bar'}", :locals => {:foo => foo}))
1482
- assert_equal("<div class='struct_user' id='foo_bar_baz_struct_user_42'></div>\n",
1507
+ assert_equal("<div class='struct_user' id='foo_baz_bar_struct_user_42'></div>\n",
1483
1508
  render("#foo[foo]{:id => 'bar'}(id='baz')", :locals => {:foo => foo}))
1484
1509
  end
1485
1510
 
@@ -1551,11 +1576,17 @@ HAML
1551
1576
  assert_equal("<a a='b' c='d'>bar</a>\n", render("%a(c='d'){:a => 'b'} bar"))
1552
1577
  assert_equal("<a a='b' c='d'>bar</a>\n", render("%a{:a => 'b'}(c='d') bar"))
1553
1578
 
1554
- assert_equal("<a a='d'>bar</a>\n", render("%a{:a => 'b'}(a='d') bar"))
1579
+ # Old-style always takes precedence over new-style,
1580
+ # because theoretically old-style could have arbitrary end-of-method-call syntax.
1581
+ assert_equal("<a a='b'>bar</a>\n", render("%a{:a => 'b'}(a='d') bar"))
1555
1582
  assert_equal("<a a='b'>bar</a>\n", render("%a(a='d'){:a => 'b'} bar"))
1556
1583
 
1557
1584
  assert_equal("<a a='b' b='c' c='d' d='e'>bar</a>\n",
1558
1585
  render("%a{:a => 'b',\n:b => 'c'}(c='d'\nd='e') bar"))
1586
+
1587
+ locals = {:b => 'b', :d => 'd'}
1588
+ assert_equal("<p a='b' c='d'></p>\n", render("%p{:a => b}(c=d)", :locals => locals))
1589
+ assert_equal("<p a='b' c='d'></p>\n", render("%p(a=b){:c => d}", :locals => locals))
1559
1590
  end
1560
1591
 
1561
1592
  # Ruby Multiline
@@ -18,7 +18,7 @@
18
18
  <% end -%>
19
19
  <div id='body'><%= " Quotes should be loved! Just like people!" %></div>
20
20
  Wow.
21
- <p>
21
+ <p code="<%= 1 + 2 %>">
22
22
  <%= "Holy cow " +
23
23
  "multiline " +
24
24
  "tags! " +
@@ -28,7 +28,8 @@
28
28
  n.to_s
29
29
  }.join("|") %>
30
30
  </p>
31
- <div class='silent'>
31
+ <% bar = 17 %>
32
+ <div class='silent' foo="<%= bar %>">
32
33
  <% foo = String.new
33
34
  foo << "this"
34
35
  foo << " shouldn't"
@@ -134,12 +134,12 @@
134
134
  118
135
135
  119
136
136
  Wow.|
137
- <p>
137
+ <p code='3'>
138
138
  Holy cow multiline tags! A pipe (|) even!
139
139
  PipesIgnored|PipesIgnored|PipesIgnored|
140
140
  1|2|3
141
141
  </p>
142
- <div class='silent'>
142
+ <div class='silent' foo='17'>
143
143
  this shouldn't evaluate but now it should!
144
144
  </div>
145
145
  <ul class='really cool'>
@@ -14,7 +14,7 @@
14
14
  - 120.times do |number|
15
15
  = number
16
16
  Wow.|
17
- %p
17
+ %p{:code => 1 + 2}
18
18
  = "Holy cow " + |
19
19
  "multiline " + |
20
20
  "tags! " + |
@@ -23,7 +23,8 @@
23
23
  = [1, 2, 3].collect { |n| |
24
24
  n.to_s |
25
25
  }.join("|") |
26
- %div.silent
26
+ - bar = 17
27
+ %div.silent{:foo => bar}
27
28
  - foo = String.new
28
29
  - foo << "this"
29
30
  - foo << " shouldn't"
@@ -14,7 +14,7 @@
14
14
  - 120.times do |number|
15
15
  = number
16
16
  Wow.|
17
- %p
17
+ %p{:code => 1 + 2}
18
18
  = "Holy cow " + |
19
19
  "multiline " + |
20
20
  "tags! " + |
@@ -23,7 +23,8 @@
23
23
  = [1, 2, 3].collect { |n| |
24
24
  n.to_s |
25
25
  }.join("|") |
26
- %div.silent
26
+ - bar = 17
27
+ %div.silent{:foo => bar}
27
28
  - foo = String.new
28
29
  - foo << "this"
29
30
  - foo << " shouldn't"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0.alpha.27
4
+ version: 3.1.0.alpha.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum
@@ -57,13 +57,13 @@ files:
57
57
  - lib/haml/html.rb
58
58
  - lib/haml/html/erb.rb
59
59
  - lib/haml/railtie.rb
60
+ - lib/haml/template.rb
60
61
  - lib/haml/root.rb
61
62
  - lib/haml/shared.rb
62
- - lib/haml/template.rb
63
+ - lib/haml/util.rb
63
64
  - lib/haml/template/options.rb
64
65
  - lib/haml/template/patch.rb
65
66
  - lib/haml/template/plugin.rb
66
- - lib/haml/util.rb
67
67
  - lib/haml/version.rb
68
68
  - lib/haml/compiler.rb
69
69
  - lib/haml/parser.rb