HAML + Merb Helpers? Very noice.
April 18, 2008 01:12 (Sydney Australia)
A year after the Merb and HAML gravy train whooshed by I’m finally giving them a run for their money.
...and whilst the snippet below may be old news to some, I’m sure there’s a bunch of us whom might not have had the pleasure of using both HAML and Merb Helpers.
Witness the following piece of view code:
%h2 New post
- form_for(@post, :action => url(:admin_posts)) do
%p= text_control :title, :label => "Title"
%p= text_control :slug, :label => "Slug"
%p= text_area_control :body, :label => "Body"
%p= select_control :format, :label => "Format",
:collection => Formatter.formatters,
:selected => MenkiConfig.default_post_format
%p
= submit_button "Publish"
= submit_button "Save as Draft"
See the lack of block parameter on the form_for? Notice the :label option. A select_control whose API simply works. Very noice.
The end result:
<h2>New post</h2>
<form method="post" action="/admin/posts">
<p>
<label for="post_title">Title</label><input type="text" class="text" name="post[title]" value="" id="post_title"/>
</p>
<p>
<label for="post_slug">Slug</label><input type="text" class="text" name="post[slug]" value="" id="post_slug"/>
</p>
<p>
<label for="post_body">Body</label><textarea name="post[body]" id="post_body"></textarea>
</p>
<p>
<label for="post_format">Format</label><select name="post[format]" id="post_format"><option value="html">html</option><option value="textile">textile</option><option value="markdown" selected="selected">markdown</option><option value="haml">haml</option></select>
</p>
<p>
<button type="submit">Publish</button>
<button type="submit">Save as Draft</button>
</p>
</form>
If you’re writing your own view code and not being handed HTML mockups, or you can get your designer to speak HAML, I highly recommend checking it out.

Comments
Jason
Have tried HAML and SASS but ultimately felt adding another layer of cream on the cake did not make for a tastier cake.
HTML is a basic building block. Many people understand it. It’s straight forward. Adding another level of abstraction complicates things. HAML is nice, but be careful!
To comment on this article you must have javascript enabled.