I was looking for rake tasks that would help me track down syntax errors, and I came across haml --check as a possible solution for double checking haml files. Unfortunately, when I passed it this broken example, haml says the syntax is OK.
Have I misunderstood the purpose of haml --check or is this feature not fully implemented?
I suppose I should mention I’m using Haml/Sass 3.0.25 (Classy Cassidy), rails 3.0.3, ruby 1.9.2p0, and Mac 10.6.6.
$ haml --check /tmp/edit.html.haml
Syntax OK
#/tmp/edit.html.haml
- content_for :head do
= include_javascripts :aspects
#aspect_edit_pane
#facebox_header
%h4
= @aspect
.description
= t('contacts', :count =>@aspect_contacts.count)}
The last character (curly brace) should trigger a syntax error, it certainly does when the template is executed as part of a request:
ActionView::Template::Error (compile error
/usr/local/app/diaspora/app/views/aspects/edit.html.haml:13:
syntax error, unexpected '}', expecting ')'
Maybe because
-c, --check Just check syntax, don't evaluate.Guess: it checks just the haml syntax and doesn’t evaluate inline ruby.
–edit
This probably needs some more testing but I got it working on simple haml files 🙂
In theory:
Haml prints out the precompiled Ruby source (and error messages in the end), we try to get just the ruby part and check the syntax.