Providing attributes as a variable results in dropping predefined classnames: `.foo{$atts}` removes the `foo` class
lolmaus opened this issue · comments
Andrey Mikhaylov (lolmaus) commented
Example of correct behavior
MtHaml:
- $class = 'bar'
.foo{'class' => $class} Baz
Output:
<div class="foo bar">Baz</div>
Example of buggy behavior
MtHaml:
- $attrs = array('class' = 'bar')
.foo{$attrs} Baz
Expected output:
<div class="foo bar">Baz</div>
This is how vanilla Haml works: http://sassmeister.com/gist/466bdb71c5af3414bbd9
Actual output:
<div class="bar">Baz</div>
Andrey Mikhaylov (lolmaus) commented
Can you please fix this quickly? 😭
Arnaud Le Blanc commented
Thanks for your report. I'll try to find time to fix this (unless someone submits a pull-request before I do :) ).
In the meantime, here is a workaround:
.foo{class=$attrs['class']} Baz
Andrey Mikhaylov (lolmaus) commented
I've outlined this workaround in the post. Unfortunately, it's not an option because it prevents from applying a dynamically generated list of attributes.
Andrey Mikhaylov (lolmaus) commented
Have to use this workaround instead:
- $args['class'] = 'my-element' . (array_key_exists($args, 'class') ? ' ' . $args['class] : '')
%div{$args} Foo
Very ugly. :(
Arnaud Le Blanc commented
Fixed, thanks for your detailed report
Andrey Mikhaylov (lolmaus) commented
My pleasure. ^______^