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.


  • 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

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:


No comments: