3

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 ')'
Philip C
  • 691
  • 7
  • 18

1 Answers1

4

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 :)

haml --debug newsletter.html.haml 2> /dev/null | sed '$d' | ruby -c

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.

Heikki
  • 15,329
  • 2
  • 54
  • 49
  • I'm not sure that makes sense, because this is a syntax error. – Philip C Jan 12 '11 at 20:09
  • 1
    Haml is template markup, not ruby. Similar case would be validating html and not picking up javascript errors. – Heikki Jan 12 '11 at 20:10
  • 2
    @Philip C: It's a *Ruby* syntax error, not a *HAML* syntax error. If you want to check for Ruby syntax errors, you can use `ruby -c` in Ruby 1.9. – Jörg W Mittag Jan 12 '11 at 20:16
  • @Philip C: Added a bit hackish solution for checking ruby syntax errors in haml. – Heikki Jan 12 '11 at 21:22
  • @Heikki: I was following a similar route, testing... But in the context of a rake task, it was easier to use HAML::Engine.new().precompiled(), ie http://diaspunk.blogspot.com/2011/01/rake-task-to-syntax-check-erb-haml-rb.html – Philip C Jan 13 '11 at 18:10
  • @Philip C: Hey, that's more like it. Btw, what is your use case? Do you have some specific use for those? – Heikki Jan 13 '11 at 20:53
  • @Philip C: Blah, never mind :) I should have read the blog post first. I might have use for those tasks myself, thanks for sharing. – Heikki Jan 13 '11 at 20:57