Sunday, May 9, 2010

Haml For Grails

Writing a Grails app? Find out why so many Rubyists swear by Haml for writing views.

<!-- GSP/JSP -->
<div id="profile">
<div class="left column">
<div id="date"><%= date %></div>
<div id="address"><%= user.address %></div>
</div>
<div class="right column">
<div id="email"><%= user.email %></div>
<div id="bio"><%= user.bio %></div>
</div>
</div>


/ Haml
#profile
.left.column
#date= date
#address= user.address
.right.column
#email= user.email
#bio= user.bio

Interested parties have created JHaml, a Java implementation of Haml, and a corresponding Grails plugin. (Patches welcome!)

To try it out, just grab the plugin:
grails install-plugin haml
Then add this bean definition to your grails-app/conf/spring/resources.groovy.

beans = { // ...
groovyPageResourceLoader(com.cadrlife.jhaml.grailsplugin.HamlGroovyPageResourceLoader) {
baseResource = new org.springframework.core.io.FileSystemResource(".")
}
}

Now, you have the option of writing views (with the .haml extension) that will be automatically rendered to GSPs.

Learn more in the Haml tutorial.

Official Grails Plugin Page

4 comments:

Anonymous said...

glad you finally posted this ray -- btw have you seen http://scalate.fusesource.org ?? -- looking to use playframework with scalate for my next 'big web project'

Burt said...

Cool stuff - I created a plugin page that references the download at Github - see http://grails.org/plugin/haml

You can edit it to update the description or FAQ section or whatever, just create an account.

yo_humano said...
This comment has been removed by the author.
yo_humano said...

It has some errors. It doesn't work for empty lines and the error that it throw is confusing