New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
:javascript filter breaks #{local} variables #2
Comments
You’re misunderstanding the Javascript filter. Like other Haml filters, it doesn’t take Haml code; it takes Javascript code. For example: ``` |
Have I missed this somewhere in the doc? It seems odd that I can’t generate output inline for a filter. Is this a technical limitation or by design? Think I saw something about scope issues in HAML code comments… |
This is by design. You can put Ruby code in a filter using `#{}`, like so: ``` but you can’t use Haml constructs like “-” and “=”. The purpose of filters is to allow non-Haml languages, like Javascript, to be embedded within Haml. |
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 # (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
```
however, this works just fine. notice that I replaced :javascript filter with regular %script tag.
```
require ‘haml/engine’
template_broken = ’
%script
– [1, 2, 3, 4].each do |item|
= “Hey #{item}”
’
puts Haml::Engine.new(template_broken).to_html
```
The text was updated successfully, but these errors were encountered: