Hello, fellow Hamlites,
It's always been a cool feature of Haml that the attribute hashes are
literal Ruby hashes. But what if you wanted to have a helper that sets
attributes? You had to actually do {:foo => get_foo}. And if you wanted
to set multiple attributes with one method, you were just out of luck.
Say, for instance, the attributes for the <html> element... a pain to
type out, but there's not a lot you can do about it.
Well, now there is. Now, in addition to literal Ruby hash goodness,
attributes can take methods that return hashes. As an example, we added
the html_attrs method to the standard set of Haml helpers. It simply
returns {:xmlns => "http://www.w3.org/1999/xhtml", 'xml:lang' => 'en',
:lang => 'en'}. You can then use those attributes simply by calling the
method in the attributes section:
%html{html_attrs}
Simple, as silk (okay, bad metaphor). You can then add more attributes
afterward if you want something else:
%html{html_attrs, :class => "myclass"}
You can, of course, make your own methods that output hashes and then
embed them in your attributes. This feature is implemented right now in
Trunk, so give it a try.
Enjoy!
- Nathan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---