From 2de8d1c9b701f2ca02ed4238fb1adaa5d8167278 Mon Sep 17 00:00:00 2001 From: nex3 Date: Fri, 20 Oct 2006 02:38:53 +0000 Subject: [PATCH] The attributes list is now sorted. git-svn-id: svn://hamptoncatlin.com/haml/branches/edge@82 7063305b-7217-0410-af8c-cdc13e5119b9 --- lib/haml/buffer.rb | 8 +++++++- test/results/standard.xhtml | 2 +- test/template_test.rb | 21 ++------------------- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/lib/haml/buffer.rb b/lib/haml/buffer.rb index 001a58ca..1232a2a5 100644 --- a/lib/haml/buffer.rb +++ b/lib/haml/buffer.rb @@ -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 == "'") ? '"' : "'" diff --git a/test/results/standard.xhtml b/test/results/standard.xhtml index d2634d68..706b29a8 100644 --- a/test/results/standard.xhtml +++ b/test/results/standard.xhtml @@ -2,7 +2,7 @@ Hampton Catlin Is Totally Awesome - + diff --git a/test/template_test.rb b/test/template_test.rb index 861d9f27..6996d833 100644 --- a/test/template_test.rb +++ b/test/template_test.rb @@ -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