Tuesday, December 8, 2009

Templates with HAML

HAML(XHTML Abstraction Markup Language) is an alternative to RHTML for writing templates for views in a Rails application. Its advantages over RHTML include brevity and clarity.

Features:

  • Whitespace active
  • Well-formatted markup
  • DRY
  • Follows CSS conventions
  • Integrates Ruby code
  • Implements Rails templates with the .haml extension
  • it is elegant
how to install:
We can use gem or plugin

1)install gem :
sudo gem install haml
2)install plugin:
ruby script/plugin install git clone git://github.com/nex3/haml.git

Usage:
save files with extension .haml

Let's look at the HAML: index.html.haml

%h1 Hello to you all
%p This is a test page

A '%' symbol creates an HTML tag. 2 spaces are used to indent the code into sub-elements and we need not to specify end tags.so that reducing so many lines code.

I tried to post examples with brief introduction, but the blog site seems to be not supporting html tags.
There is a lot more to learn check these References:

http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#plugin
http://haml-lang.com/about.html
http://wiki.rubyonrails.org/howtos/templates/haml

No comments: