1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Raise Haml::SyntaxError rather than ::SyntaxError

Resolves #579
This commit is contained in:
Norman Clarke 2012-11-27 07:54:55 -05:00
parent 8b9da4e0f6
commit 08c2e803bb
2 changed files with 23 additions and 4 deletions

View file

@ -125,8 +125,11 @@ module Haml
extend Haml::Helpers
@haml_buffer = buffer
end
eval(@compiler.precompiled_with_return_value, scope, @options[:filename], @options[:line])
begin
eval(@compiler.precompiled_with_return_value, scope, @options[:filename], @options[:line])
rescue ::SyntaxError => e
raise SyntaxError, e.message
end
ensure
# Get rid of the current buffer
scope_object.instance_eval do
@ -167,8 +170,12 @@ module Haml
scope = scope_object.instance_eval{binding}
end
eval("Proc.new { |*_haml_locals| _haml_locals = _haml_locals[0] || {};" +
compiler.precompiled_with_ambles(local_names) + "}\n", scope, @options[:filename], @options[:line])
begin
eval("Proc.new { |*_haml_locals| _haml_locals = _haml_locals[0] || {};" +
compiler.precompiled_with_ambles(local_names) + "}\n", scope, @options[:filename], @options[:line])
rescue ::SyntaxError => e
raise SyntaxError, e.message
end
end
# Defines a method on `object` with the given name

View file

@ -1316,6 +1316,18 @@ HAML
assert_nil(scope.send(:haml_buffer))
end
def test_render_proc_should_raise_haml_syntax_error_not_ruby_syntax_error
assert_raises(Haml::SyntaxError) do
Haml::Engine.new("%p{:foo => !}").render_proc(Object.new, :foo).call
end
end
def test_render_should_raise_haml_syntax_error_not_ruby_syntax_error
assert_raises(Haml::SyntaxError) do
Haml::Engine.new("%p{:foo => !}").render
end
end
def test_ugly_true
assert_equal("<div id='outer'>\n<div id='inner'>\n<p>hello world</p>\n</div>\n</div>\n",
render("#outer\n #inner\n %p hello world", :ugly => true))