Sunday, May 02, 2010

Using Haml with Rails 3.0

One of the things I [heart] about being a Ruby/Rails developer for ThoughtWorks is that I occasionally get asked to do something really cool on the side, like being a technical reviewer for an upcoming book on Rails 3.0.

In this particular book, the author uses Haml instead of Erb for templating views in the sample code. When I'm reviewing a book, I like to actually exercise as much of the sample code as I reasonably can, as it tends to be among the hardest stuff to get right, and among the easiest ways to discourage a reader when it's not right. But Rails defaults to Erb for templating, and I'm not exactly Haml-enabled.

What's a geek to do?

Well, my friend Google had a thing or two to suggest, but the process is slightly non-trivial so I thought I'd collate it here, thusly:

  • NB: All commands are entered from your Rails 3.0 application's root directory.

  • Edit [your_app]/Gemfile, and add the line gem 'haml' somewhere convenient.

  • Edit [your_app]/config/application.rb, and add the line g.template_engine :haml to the config.generators block (uncommenting the block if necessary).

  • gem install haml

  • bundle install

  • haml --rails .

  • git clone git://github.com/psynix/rails3_haml_scaffold_generator.git lib/generators/haml


That last bit is particularly important for allowing Rails' scaffold generators to Do The Haml Thang(TM) when generating view templates.

Now back to my regularly scheduled tech review ...

P.S.: The book is going to be awesome. Reserve your copy now!

Saturday, May 01, 2010

Enter the Lich!

So I've finally spent a little bit of time unpacking and bookshelving my trove of geek books from my move last summer. Among many that I want/need to read Real Soon Now (TM), the book "Lisp in Small Pieces" by Christian Queinnec caught my eye and reminded me that I need to actually do something about learning Clojure.

So I've set out to implement Lisp in Clojure, following Queinnec's book. I've put the shell of the project -- featuring 100% test coverage; go me! -- on GitHub, at http://github.com/davidrupp/lich. For some reason I haven't taken the time to obsess about (yet), lein repl doesn't include the project's src directory on the CLASSPATH, so you can't really require your code and play with it in the REPL. So I've included my own in script/repl. I suspect that once I really get the hang of unit testing I won't need/want to rely on it so much, but at least it's there for now.

This should be fun ...