haml 2.0.1 → 2.0.2

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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.0.2
@@ -1030,7 +1030,8 @@ module Haml
1030
1030
  # so we can change the initialization behavior
1031
1031
  # without modifying the file itself.
1032
1032
  def self.init_rails(binding)
1033
- %w[haml/template sass sass/plugin].each(&method(:require))
1033
+ # No &method here for Rails 2.1 compatibility
1034
+ %w[haml/template sass sass/plugin].each {|f| require f}
1034
1035
  end
1035
1036
  end
1036
1037
 
@@ -187,13 +187,13 @@ END
187
187
  def compile(precompiler, text)
188
188
  return if precompiler.options[:suppress_eval]
189
189
  precompiler.instance_eval do
190
- push_silent <<-END.gsub("\n", ';')
190
+ push_silent <<-FIRST.gsub("\n", ';') + text + <<-LAST.gsub("\n", ';')
191
191
  _haml_old_stdout = $stdout
192
192
  $stdout = StringIO.new(_hamlout.buffer, 'a')
193
- #{text}
193
+ FIRST
194
194
  _haml_old_stdout, $stdout = $stdout, _haml_old_stdout
195
195
  _haml_old_stdout.close
196
- END
196
+ LAST
197
197
  end
198
198
  end
199
199
  end
@@ -311,7 +311,7 @@ module Haml
311
311
  #
312
312
  def haml_tag(name, *rest, &block)
313
313
  name = name.to_s
314
- text = rest.shift if rest.first.is_a? String
314
+ text = rest.shift.to_s unless [Symbol, Hash, NilClass].any? {|t| rest.first.is_a? t}
315
315
  flags = []
316
316
  flags << rest.shift while rest.first.is_a? Symbol
317
317
  attributes = Haml::Precompiler.build_attributes(haml_buffer.html?,
@@ -169,7 +169,7 @@ module Haml
169
169
  end
170
170
 
171
171
  def self.haml_tag_loud(text)
172
- "= #{text.gsub(/\n\s*/, '; ').strip}\n"
172
+ "= #{text.gsub(/\n\s*/, ' ').strip}\n"
173
173
  end
174
174
 
175
175
  def self.haml_tag_silent(text)
@@ -197,6 +197,14 @@ END
197
197
  when SILENT_SCRIPT
198
198
  return start_haml_comment if text[1] == SILENT_COMMENT
199
199
 
200
+ raise SyntaxError.new(<<END.rstrip, index) if text[1..-1].strip == "end"
201
+ You don't need to use "- end" in Haml. Use indentation instead:
202
+ - if foo?
203
+ %strong Foo!
204
+ - else
205
+ Not foo.
206
+ END
207
+
200
208
  push_silent(text[1..-1], true)
201
209
  newline_now
202
210
  if (@block_opened && !mid_block_keyword?(text)) || text[1..-1].split(' ', 2)[0] == "case"
@@ -303,13 +311,9 @@ END
303
311
 
304
312
  # Adds +text+ to <tt>@buffer</tt> while flattening text.
305
313
  def push_flat(line)
306
- unless @options[:ugly]
307
- tabulation = line.spaces - @flat_spaces
308
- tabulation = tabulation > -1 ? tabulation : 0
309
- @filter_buffer << "#{' ' * tabulation}#{line.unstripped}\n"
310
- else
311
- @filter_buffer << "#{line.unstripped}\n"
312
- end
314
+ tabulation = line.spaces - @flat_spaces
315
+ tabulation = tabulation > -1 ? tabulation : 0
316
+ @filter_buffer << "#{' ' * tabulation}#{line.unstripped}\n"
313
317
  end
314
318
 
315
319
  # Causes <tt>text</tt> to be evaluated in the context of
@@ -476,7 +480,7 @@ END
476
480
  next
477
481
  end
478
482
 
479
- value = Haml::Helpers.escape_once(value.to_s)
483
+ value = Haml::Helpers.preserve(Haml::Helpers.escape_once(value.to_s))
480
484
  # We want to decide whether or not to escape quotes
481
485
  value.gsub!('&quot;', '"')
482
486
  this_attr_wrapper = attr_wrapper
@@ -112,10 +112,11 @@ module Sass
112
112
  root = Tree::Node.new(@options[:style])
113
113
  index = 0
114
114
  while @lines[index]
115
+ old_index = index
115
116
  child, index = build_tree(index)
116
117
 
117
118
  if child.is_a? Tree::Node
118
- child.line = index
119
+ child.line = old_index + 1
119
120
  root << child
120
121
  elsif child.is_a? Array
121
122
  child.each do |c|
@@ -34,6 +34,13 @@ END
34
34
  "%a/ b" => "Self-closing tags can't have content.",
35
35
  " %p foo" => "Indenting at the beginning of the document is illegal.",
36
36
  " %p foo" => "Indenting at the beginning of the document is illegal.",
37
+ "- end" => <<END.rstrip,
38
+ You don't need to use "- end" in Haml. Use indentation instead:
39
+ - if foo?
40
+ %strong Foo!
41
+ - else
42
+ Not foo.
43
+ END
37
44
  " \n\t\n %p foo" => ["Indenting at the beginning of the document is illegal.", 3],
38
45
 
39
46
  # Regression tests
@@ -49,6 +56,7 @@ END
49
56
  A tab character was used for indentation. Haml must be indented using two spaces.
50
57
  Are you sure you have soft tabs enabled in your editor?
51
58
  END
59
+ "foo\n:ruby\n 1\n 2\n 3\n- raise 'foo'" => ["foo", 6],
52
60
  }
53
61
 
54
62
  User = Struct.new('User', :id)
@@ -192,20 +200,24 @@ SOURCE
192
200
 
193
201
  def test_static_attributes_should_be_escaped
194
202
  assert_equal("<img class='atlantis' style='ugly&amp;stupid' />\n",
195
- render("%img.atlantis{:style => 'ugly&stupid'}", :escape_html => true))
203
+ render("%img.atlantis{:style => 'ugly&stupid'}"))
196
204
  assert_equal("<div class='atlantis' style='ugly&amp;stupid'>foo</div>\n",
197
- render(".atlantis{:style => 'ugly&stupid'} foo", :escape_html => true))
205
+ render(".atlantis{:style => 'ugly&stupid'} foo"))
198
206
  assert_equal("<p class='atlantis' style='ugly&amp;stupid'>foo</p>\n",
199
- render("%p.atlantis{:style => 'ugly&stupid'}= 'foo'", :escape_html => true))
207
+ render("%p.atlantis{:style => 'ugly&stupid'}= 'foo'"))
208
+ assert_equal("<p class='atlantis' style='ugly&#x000A;stupid'></p>\n",
209
+ render("%p.atlantis{:style => \"ugly\\nstupid\"}"))
200
210
  end
201
211
 
202
212
  def test_dynamic_attributes_should_be_escaped
203
- assert_equal("<img alt='' src='/foo.png' />\n",
204
- render("%img{:width => nil, :src => '/foo.png', :alt => String.new}", :escape_html => true))
205
- assert_equal("<p alt='' src='/foo.png'>foo</p>\n",
206
- render("%p{:width => nil, :src => '/foo.png', :alt => String.new} foo", :escape_html => true))
207
- assert_equal("<div alt='' src='/foo.png'>foo</div>\n",
208
- render("%div{:width => nil, :src => '/foo.png', :alt => String.new}= 'foo'", :escape_html => true))
213
+ assert_equal("<img alt='' src='&amp;foo.png' />\n",
214
+ render("%img{:width => nil, :src => '&foo.png', :alt => String.new}"))
215
+ assert_equal("<p alt='' src='&amp;foo.png'>foo</p>\n",
216
+ render("%p{:width => nil, :src => '&foo.png', :alt => String.new} foo"))
217
+ assert_equal("<div alt='' src='&amp;foo.png'>foo</div>\n",
218
+ render("%div{:width => nil, :src => '&foo.png', :alt => String.new}= 'foo'"))
219
+ assert_equal("<img alt='' src='foo&#x000A;.png' />\n",
220
+ render("%img{:width => nil, :src => \"foo\\n.png\", :alt => String.new}"))
209
221
  end
210
222
 
211
223
  def test_string_interpolation_should_be_esaped
@@ -285,7 +297,7 @@ SOURCE
285
297
  def test_attrs_parsed_correctly
286
298
  assert_equal("<p boom=>biddly='bar =&gt; baz'></p>\n", render("%p{'boom=>biddly' => 'bar => baz'}"))
287
299
  assert_equal("<p foo,bar='baz, qux'></p>\n", render("%p{'foo,bar' => 'baz, qux'}"))
288
- assert_equal("<p escaped='quo\nte'></p>\n", render("%p{ :escaped => \"quo\\nte\"}"))
300
+ assert_equal("<p escaped='quo&#x000A;te'></p>\n", render("%p{ :escaped => \"quo\\nte\"}"))
289
301
  assert_equal("<p escaped='quo4te'></p>\n", render("%p{ :escaped => \"quo\#{2 + 2}te\"}"))
290
302
  end
291
303
 
@@ -477,6 +489,13 @@ SOURCE
477
489
  END
478
490
  end
479
491
 
492
+ def test_ugly_filter
493
+ assert_equal(<<END, render(":sass\n #foo\n bar: baz", :ugly => true))
494
+ #foo {
495
+ bar: baz; }
496
+ END
497
+ end
498
+
480
499
  def test_local_assigns_dont_modify_class
481
500
  assert_equal("bar\n", render("= foo", :locals => {:foo => 'bar'}))
482
501
  assert_equal(nil, defined?(foo))
@@ -25,7 +25,16 @@ class TemplateTest < Test::Unit::TestCase
25
25
  filters nuke_outer_whitespace nuke_inner_whitespace }
26
26
 
27
27
  def setup
28
- @base = ActionView::Base.new(TEMPLATE_PATH, 'article' => Article.new, 'foo' => 'value one')
28
+ vars = { 'article' => Article.new, 'foo' => 'value one' }
29
+
30
+ unless ActionView::Base.instance_methods.include? 'finder'
31
+ @base = ActionView::Base.new(TEMPLATE_PATH, vars)
32
+ else
33
+ # Rails 2.1.0
34
+ @base = ActionView::Base.new([], vars)
35
+ @base.finder.append_view_path(TEMPLATE_PATH)
36
+ end
37
+
29
38
  @base.send(:evaluate_assigns)
30
39
 
31
40
  # This is used by form_for.
@@ -42,7 +42,7 @@ END
42
42
  "a\n :b c" => "4 spaces were used for indentation. Sass must be indented using two spaces.",
43
43
  "a\n :b c\n !d = 3" => "Constants may only be declared at the root of a document.",
44
44
  "!a = 1b + 2c" => "Incompatible units: b and c.",
45
- "& a\n :b c" => "Base-level rules cannot contain the parent-selector-referencing character '&'.",
45
+ "& a\n :b c" => ["Base-level rules cannot contain the parent-selector-referencing character '&'.", 1],
46
46
  "a\n :b\n c" => "Illegal nesting: Only attributes may be nested beneath attributes.",
47
47
  "a,\n :b c" => "Rules can\'t end in commas.",
48
48
  "a," => "Rules can\'t end in commas.",
@@ -60,7 +60,9 @@ END
60
60
  " \n \n\t\n a\n b: c" => ["Indenting at the beginning of the document is illegal.", 4],
61
61
 
62
62
  # Regression tests
63
- "a\n b:\n c\n d" => ["Illegal nesting: Only attributes may be nested beneath attributes.", 3]
63
+ "a\n b:\n c\n d" => ["Illegal nesting: Only attributes may be nested beneath attributes.", 3],
64
+ "& foo\n bar: baz\n blat: bang" => ["Base-level rules cannot contain the parent-selector-referencing character '&'.", 1],
65
+ "a\n b: c\n& foo\n bar: baz\n blat: bang" => ["Base-level rules cannot contain the parent-selector-referencing character '&'.", 3],
64
66
  }
65
67
 
66
68
  def test_basic_render
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: 2.0.1
4
+ version: 2.0.2
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: 2008-06-28 00:00:00 -04:00
13
+ date: 2008-07-30 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -173,6 +173,7 @@ files:
173
173
  - test/haml/templates/_text_area.haml
174
174
  - test/haml/engine_test.rb
175
175
  - test/test_helper.rb
176
+ - test/rails
176
177
  - Rakefile
177
178
  - init.rb
178
179
  - FAQ