Closed matify closed 12 years ago
Good catch! Both () and {} should be supported. I will fix this asap. Haml Reference
Actually they doesn't work in the same way. When you use ()s the attributes inside them are pushed to the tag exactly as they were written. Should we keep this behavior or not? I can't see any advantage in the way ()'s work
We should keep both styles available.
I agree. But the question is: should they behave differently? (like in haml)
Yes, they should behave the same way.
I have compiled list of requirements for the attributes functionality (from haml documentation). See if you agree with all:
Attribute hashes can be stretched out over multiple lines to accommodate many attributes. However, newlines may only be placed immediately after commas.
%script{type => "text/javascript", src => "javascripts/script_#{2 + 7}"}
The class
and id
attributes can also be specified as an array whose elements will be joined together. A class
array is joined with " " and an id
array is joined with "_". For example:
%div{id => [$item->type, $item->number], class => [$item->type, $item->urgency]}
is equivalent to:
%div{id => "#{$item->type}_#{$item->number}", class => "#{$item->type} #{$item->urgency}"}
A function or method call that returns an array map (key => value) can be substituted for the hash contents. You can use as many such attribute methods as you want by separating them with commas. All the hashes will me merged together, from left to right.
function hash1() { return array('bread' => 'white', 'filling' => 'peanut butter and jelly'); }
function hash2() { return array('bread' => 'whole wheat'); }
then
%sandwich{hash1(), hash2(), $this->langAttrs('pt-BR'), delicious => true}/
would compile to:
<sandwich bread='whole wheat' filling='peanut butter and jelly' xml:lang='pt-BR' lang='pt-BR' delicious='true' />
Custom data attributes can be used in Haml by using the key data
with a Hash value in an attribute hash. Each of the key/value pairs in the Hash will be transformed into a custom data attribute. For example:
%a{href=>"/posts", data => {author_id => 123}} Posts By Author
will render as:
<a data-author_id='123' href='/posts'>Posts By Author</a>
I agree with you. Are keys written without quotes?
Yeah, they are. I've updated my last comment because I had left some ruby syntax. Now it's all php. I think we shouldn't require the colon (:) before the attribute, but we could allow it and just strip it out. It can be helpful for syntax coloring. There's some open source plugins for various IDEs we can modify.
I already started working on this. I'll let the multiline requirement to the end. We have to decide if the NodeFactory will pull the next line or if the parser will join the lines as needed before passing it to the NodeFactory. I prefer the first one for the cohesion, since NodeFactory has the knowledge of how nodes are written.
Just curious, is this still an active issue?
yes, and no. Yes, it is still an issue, and no, nobody is actually working on it, I whish I could work on it. But I'm too busy.
I'm gonna check if all the syntax's specified here are valid
Took me a little while to figure out why the {}'s weren't working. I am wondering if it's coded that way for a specific reason?