HAML – TextMate Command

I have been enamored with Ruby lately and one of the gems that has been stuck in the back of my mind for a very long time was HAML. HAML is a really slick way to write some html code with Ruby hooks. If you’re a Ruby on Rails user you can convert all your .rhtml files into .haml files and really reduce the file’s contents to its pure essence. To see what I mean:

!!!
%html
  %head
    %title Simple Page
  %body
    #header
    #sidebar
      %ul.menu
    #content
      %h1 HAML is awesome
      %p
        It even performs Ruby!
        = 50 * 10
    #footer
      %span{:style=>'text-align: center'} Joseph Pecoraro

Produces this super clean HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Simple Page</title>
  </head>
  <body>
    <div id='header'>
    </div>
    <div id='sidebar'>
      <ul class='menu'>
      </ul>
    </div>
    <div id='content'>
      <h1>HAML is awesome</h1>
      <p>
        It even performs Ruby!
        500
      </p>
    </div>
    <div id='footer'>
      <span style='text-align: center'>Joseph Pecoraro</span>
    </div>
  </body>
</html>

Now here is the catch. I don’t currently use Ruby on Rails, but I really value the quick translation of the easy to type HAML to valid and nicely formatted XHTML. I didn’t see a HAML function for TextMate that I wanted so I wrote my own command.

TextMate Hamlize Command

Download the Hamlize Command Here

Feel free to download it and customize the usage to your own workflow. I personally bound the command to ⌃⇧H which will let me choose between the Tidy command or Hamlize. Also the command will work on the selected text, or if nothing is selected it will do the entire document. Now I can whip out a simple XHTML template page in even less time.

Make sure to get HAML first. Just download the gem and you’re all set.

$ sudo gem install haml

Here are some nice HAML references to help show you even more powerful options:
HAML Tutorial
HAML Documentation

3 Responses

1

Keith on August 7, 2008 at 6:31 pm  #

Thanks – being new to HAML (and I AM using Rails), I like being able to do a quick check of the generated code.

2

Ross on October 8, 2008 at 6:02 pm  #

Excellent. I’ve been looking for something like this for a long time. Nice work. :)

3

Joe on October 13, 2008 at 4:28 pm  #

Awsome..

In conjunction with the TextMate HAML & SASS Bundles I couldn’t be happier

http://github.com/seaofclouds/sass-textmate-bundle/tree/master
http://macromates.com/svn/Bundles/trunk/Bundles/Ruby Haml.tmbundle

Add a Comment

search