From 0ea157839f7fbc98d058cf4af2dac0d007ea4416 Mon Sep 17 00:00:00 2001 From: Matt Wildig Date: Thu, 21 Feb 2013 00:21:58 +0000 Subject: [PATCH 1/2] Add test for attribute methods When an attribute method (or literal nested hash) is used in an old style attribute hash and there is also a (non-static) new style hash there is an error. The generated code looks something like: foo.merge(method_that_returns_hash, :foo => 'bar') Add a test to expose this. --- test/engine_test.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/engine_test.rb b/test/engine_test.rb index dcf7fcde..4f9c5bb0 100644 --- a/test/engine_test.rb +++ b/test/engine_test.rb @@ -214,6 +214,11 @@ HAML render(".no_attributes{:nil => nil}").chomp) end + def test_attribute_method_with_both_attrib_styles_and_non_static_hashes + assert_equal("
", + render("%div{{:foo => 'bar'}, :baz => 'qux'}(zig = val)", :locals => {:val => 'zag'}).chomp) + end + def test_strings_should_get_stripped_inside_tags assert_equal("
This should have no spaces in front of it
", render(".stripped This should have no spaces in front of it").chomp) From e475b015d3171fb4c4f140db304f7970c787d6e3 Mon Sep 17 00:00:00 2001 From: Matt Wildig Date: Thu, 21 Feb 2013 00:34:26 +0000 Subject: [PATCH 2/2] Fix for attribute methods See 0ea157839f7fbc98d058cf4af2dac0d007ea4416 The call to `merge` isn't necessary since the hashes are merged in the call to `Buffer#attributes` with `merge_attrs` This commit can result in different behaviour in certain case, since the hashes are being merged with `merge_attrs` which handles `class` and `id` attributes. Previously the value from the 'old style' would replace the value from the 'new style` e.g. %p.the_class{:class => old_attrs}(class = new_attrs) (where `old_attrs` and `new_attrs` are methods that return 'old' or 'new') Previously this would result in:

with this commit the result is:

--- lib/haml/compiler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/haml/compiler.rb b/lib/haml/compiler.rb index 3784bbc5..51001c11 100644 --- a/lib/haml/compiler.rb +++ b/lib/haml/compiler.rb @@ -195,7 +195,7 @@ END elsif attributes_hashes.size == 1 attributes_hashes = ", #{attributes_hashes.first}" else - attributes_hashes = ", (#{attributes_hashes.join(").merge(")})" + attributes_hashes = ", #{attributes_hashes.join(", ")}" end push_merged_text "<#{t[:name]}", 0, !t[:nuke_outer_whitespace]