Reputation: 5558
I've installed HAML into my project and it is working like a charm - the templates are beeing rendered without a problem. My question is how can I do the rendering on the command line, by using HAML program. That would be super for debugging purposes, meantime while I try to compile HAML file I get the error on first Rails related Ruby code to be found:
% cat app/views/dashboard/index.html.haml
- title "Home"
%p
Lorem ipsum dolor sit amet...
% haml app/views/dashboard/index.html.haml
Exception on line 1: undefined method `title' for #<Object:0xb73283b0>
Use --trace for backtrace.
Page is rendered fine returned correctly through the webserver.
Upvotes: 2
Views: 4553
Reputation: 66525
I'd say that you want to take a look at the haml engine
template = File.read('templates/really_cool_template.haml')
haml_engine = Haml::Engine.new(template)
output = haml_engine.render
puts output
edit: Then put that into a rake task to load the rails environment. Once it's done you can pass all the parameters you want to your template
Upvotes: 4
Reputation: 5974
You can use the --check
flag on the Haml executable to check for syntax without evaluating the Ruby code:
% haml --check app/views/dashboard/index.html.haml
For future reference, the --help
flag will print out all options for the executable.
Upvotes: 14