Haml + Ruby 1.9-Style Hashes + CodeKit

23 Feb 2013

Since Shay taught us Haml at The Starter League, I've been hooked. The markup is beautifully clean and easy to read.

With Haml you have a few choices in attribute syntax. I liked Ruby's new hash syntax, which requires Ruby 1.9+:

%a{title: "Dan is cool", href: "http://dankim.org"} I'm a link

Compiling Haml to HTML is a manual process by default, requiring some repetitive command line entries. Luckily there are some great options to automate this, and CodeKit is one of the best.

Unfortunately, CodeKit's internal Haml processor doesn't support Ruby's new hash syntax if your system's Ruby version is below 1.9 (if your system Ruby is 1.9+, you should be set).

Simply changing the Haml executable path in CodeKit preferences may also throw an error:

You have asked CodeKit to use an external Haml compiler that failed verification. Check that you have installed Haml (and its dependencies) correctly and that you've specified the correct path to its executable in CodeKit's preferences.

The only workaround I found was to open CodeKit from a terminal instance that had Ruby 1.9+ loaded:

  1. Use RVM to grab a Ruby 1.9+ build.
  2. Set that RVM environment as your terminal default.
  3. Install Haml into that Ruby environment with gem install haml.
  4. In terminal, execute open /Applications/CodeKit.app.

CodeKit will then use the Ruby 1.9+ executables set in that terminal instance, and will compile Haml with the new Ruby hash syntax.