Let's say I want to render the following
<div id="foo" class="f开发者_如何学Pythonoo">
Bar
</div>
In HAML, I'd typically write
#foo.foo Bar
Is there an easy way to do something like the following?
#foo{ :class => id_for_this_tag }
What I really want is the ability to hook into the markup generation of HAML to clean up some views.
The code in your example should work as is. The following line:
#foo{:class => @my_class }
Will generate the following HTML:
<div class='foobar' id='foo'></div>
Assuming that @my_class = "foobar"
is defined appropriately.
I'm not aware of any way to trim it any further, but you can get away with anything using this format. For example:
- bob = "silly"
#foo{:class => bob, :summary => "whatever", :arbitrary => "arbitrary"}
Generates:
<div arbitrary='arbitrary' class='silly' id='foo' summary='whatever'>
精彩评论