HAML bug with :javascript filter and undefined local variable or method
http://github.com/nex3/haml/issues#issue/2
on haml 2.0.9
require 'haml/engine'
template_broken = '
:javascript
- [1, 2, 3, 4].each do |item|
= "Hey #{item}"
'
puts Haml::Engine.new(template_broken).to_html
causes
(haml):3:in `to_html': undefined local variable or method `item' for #<Object:0x2bedf64> (NameError)
from c:/ruby/lib/ruby/gems/1.8/gems/haml-2.0.9/lib/haml/engine.rb:149:in `to_html'
from c:/ruby/lib/ruby/gems/1.8/gems/haml-2.0.9/lib/haml/engine.rb:149:in `instance_eval'
from c:/ruby/lib/ruby/gems/1.8/gems/haml-2.0.9/lib/haml/engine.rb:149:in `to_html'
from haml.rb:9
Replacing :javascript filter with regular %script tag fixed the issue. It’s a workaround.
require 'haml/engine'
template_broken = '
%script
- [1, 2, 3, 4].each do |item|
= "Hey #{item}"
'
puts Haml::Engine.new(template_broken).to_html