HAML: A new view template language for Rails
HAML is a new template language for Ruby on Rails developed by Hampton Catlin, a Canadian Rails developer. It's a high-level, heavily semantic language that breaks the mold of RHTML and makes it very hard to make markup errors. In a way similar to Python, HAML relies on indentation, which it uses to enforce DOM hierarchy.
Here's an example of some HAML code in action:
!!! %html %head %title Client Admin Site %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ = stylesheet_link_tag 'tabbed' = javascript_include_tag 'tabbed' %body #application #header .container .statusbar .logo %strong Admin Interface .menu= link_to 'logout', :controller => 'account', :action => 'logout' %br{:style=>"clear:both;"}/ .tabs %ul.navigation %li= link_to 'Member Approval', member_admin_url %li= link_to 'User Management', user_admin_url, :class => 'selected' %li= link_to 'Pages', page_admin_url %li= link_to 'Reports', reports_url %li= link_to 'Help', '/' #page #content //These will only render if there is a non-false value returned from the helper #errors= print_flash(:error) #notice= print_flash(:notice) = @content_for_layout #sidebar= @content_for_sidebar || false %hr/ #footer %p= "Copyright Hampton Catlin 2006"
Learn more in this article.
September 14, 2006 at 12:25 am
Yuk! Yet another templating engine...when will people learn, lol.
September 14, 2006 at 1:08 am
This hurts my head. I have a hard time seeing what advantages this has of any other template engine.
I'm still waiting for someone (myself?) to implement a TAL (http://www.zope.org/Wikis/DevSite/Projects/ZPT/TAL%20Specification%201.4) engine. If you're going to use a template engine, it might as well be nice valid XML.
September 14, 2006 at 1:39 am
Actually, I think nice in its own way. The only real showstopper is that it does not handle multi line ruby statements. So you can't write the normal @foo.each multi line iteration. Not sure why they decided to do that but its fairly limiting unless I am missing something here.
September 14, 2006 at 1:55 am
I quite like this from the standpoint that I hate HTML and XHTML, but I think this will be hard for people to adopt only because it is yet another thing for someone to learn and there will be fewer examples. I'm not saying this is good, just the way it probably will be.
September 14, 2006 at 3:38 am
I don't like this.
Markaby http://markaby.rubyforge.org/ does this better, if you must.
September 14, 2006 at 7:44 am
Quite nice actually, I like how he got it simular to actuall CSS with "#" for uniqe ids, "." for classes and well, I guess % is ok for normal tags :). As ezra is pointing out it wouldn't be bad still having the possibilities.. or maybe it's there, I see some link_to's in there after ='s..
September 14, 2006 at 8:45 am
Oh, no... Looks like HARM to me...
September 14, 2006 at 9:05 am
I wonder how this performs! I can't imagine that it's quicker than the current template engine. Does anybody know this?
September 14, 2006 at 9:32 am
I don't see much benefit to this over Markaby. With Markaby, your markup must validate as valid Ruby code, blocks and all, because it is real Ruby code. This means anything in Ruby is supported, you can't misnest anything, errors are caught early, and you don't have to learn any new syntax (ok, 30 seconds of new syntax: [ tag.idname!.classname ] == [ tag :id => 'idname', :class => 'classname' ]== [ ] ).
September 14, 2006 at 9:33 am
WordPress swallowed my html tag example; sigh...
September 14, 2006 at 10:31 am
One thing I do like about it (whether for good or bad reasons) is the way you don't need to remember to close off a block.. but then I hit into one reason why I hate Python.
September 14, 2006 at 12:39 pm
Ugh, why try to turn any aspect of Ruby into Python? Awful, disgusting whitespace requirements...
September 14, 2006 at 2:14 pm
Would be great if someone could implement PageTemplates that Python has. Its great way how to embed code into tags and let designer goes his way.
September 14, 2006 at 4:14 pm
I agree with Chadwick about TAL. It has its good and bad, but if you are working with a designer and want to do round-trip design with something like dreamweaver, it is the best solution I have seen to date.
September 14, 2006 at 4:54 pm
More discussion can be found on the RoR-talk list: http://groups.google.com/group/rubyonrails-talk/browse_frm/thread/52a625a3f379f73a/e61fa29c4a48ef67?