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

Adding in the edgy changes.

git-svn-id: svn://hamptoncatlin.com/haml/branches/faster@86 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
hcatlin 2006-10-21 20:16:26 +00:00
parent 082f78c412
commit 4042253323
4 changed files with 41 additions and 23 deletions

View file

@ -120,7 +120,13 @@ module Haml
# Takes a hash and builds a list of XHTML attributes from it, returning
# the result.
def build_attributes(attributes = {})
result = attributes.collect do |a,v|
attributes.each do |key, value|
unless key.is_a? String
attributes.delete key
attributes[key.to_s] = value
end
end
result = attributes.sort.collect do |a,v|
unless v.nil?
first_quote_type = v.to_s.scan(/['"]/).first
quote_type = (first_quote_type == "'") ? '"' : "'"

View file

@ -213,10 +213,13 @@ _erbout = _hamlout.buffer
#{@precompiled}
END
# Evaluate the buffer in the context of the scope object
begin
# Evaluate the buffer in the context of the scope object
@scope_object.instance_eval @precompiled
rescue Exception => e
# Get information from the exception and format it so that
# Rails can understand it.
compile_error = e.message.scan(/\(eval\):([0-9]*):in `[-_a-zA-Z]*': compile error/)[0]
filename = "(haml)"
if @scope_object.methods.include? "haml_filename"
# For some reason that I can't figure out,
@ -227,7 +230,15 @@ END
filename = "#{@scope_object.haml_filename}.haml"
end
end
e.backtrace.unshift "#{filename}:#{@scope_object.haml_lineno}"
lineno = @scope_object.haml_lineno
if compile_error
eval_line = compile_error[0].to_i
line_marker = @precompiled.split("\n")[0...eval_line].grep(/@haml_lineno = [0-9]*/)[-1]
lineno = line_marker.scan(/[0-9]+/)[0].to_i if line_marker
end
e.backtrace.unshift "#{filename}:#{lineno}"
raise e
end

View file

@ -2,7 +2,7 @@
<html xml-lang='en-US'>
<head>
<title>Hampton Catlin Is Totally Awesome</title>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
</head>
<body>
<!-- You're In my house now! -->

View file

@ -9,17 +9,6 @@ require File.dirname(__FILE__) + '/../lib/haml/template'
require File.dirname(__FILE__) + '/mocks/article'
class TemplateTest < Test::Unit::TestCase
# These are specific lines of templates that, for one reason or
# another, might not be exactly equivalent to the pre-rendered
# version.
EXCEPTIONS = {
'standard' => [
# Line 4 has many attributes; because attributes aren't sorted,
# this can vary unpredictably.
4
]
}
def setup
ActionView::Base.register_template_handler("haml", Haml::Template)
@base = ActionView::Base.new(File.dirname(__FILE__) + "/../test/templates/")
@ -38,14 +27,8 @@ class TemplateTest < Test::Unit::TestCase
def assert_renders_correctly(name)
load_result(name).split("\n").zip(@base.render(name).split("\n")).each_with_index do |pair, line|
if (EXCEPTIONS['name'].nil? || EXCEPTIONS['name'].include?(line))
if pair.first != pair.last
puts "\nWarning: line #{line} of template \"#{name}\" may have rendered incorrectly."
end
else
message = "template: #{name}\nline: #{line}"
assert_equal(pair.first, pair.last, message)
end
message = "template: #{name}\nline: #{line}"
assert_equal(pair.first, pair.last, message)
end
end
@ -112,5 +95,23 @@ END
rescue Exception => e
assert_equal("(haml):4", e.backtrace[0])
end
template = <<END
%p
%h1 Hello!
= "lots of lines"
= "even more!"
- compile_error(
%p
this is after the exception
%strong yes it is!
ho ho ho.
END
begin
render(template.chomp)
rescue Exception => e
assert_equal("(haml):5", e.backtrace[0])
end
end
end