Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What kind of Ruby / Erb is allowed inside HAML's :javascript filter?

It seems that inside of HAML's :javascript filter, no Ruby code is allowed, not even a comment.

So this is NOT allowed:

:javascript
  - 1.upto(10) do |i|

:javascript
  -# just a comment not to show to public

(somebody said there is not way to hide comment like that inside a :javascript filter. Is that true?

but it seems the only thing allowed is

:javascript
  $('#aDiv').html('#{a_ruby_variable}');

only this #{ } is allowed. Nothing else that is Ruby is allowed?

like image 755
nonopolarity Avatar asked Jun 04 '10 05:06

nonopolarity


1 Answers

As I said on your other question, filters are (almost) entirely parsed separately from Haml. The only exception to this is #{}: for filters that just transform static text (that is, text that doesn't interact with the Ruby environment at all, so most filters other than :ruby and :erb), Haml adds this as a handy way of adding a Ruby value.

If you're looking for more complex Ruby integration with your text, filters are not the place to go. They're meant to be handy, not the be-all end-all solution to, say, putting JS in your template.

like image 140
Natalie Weizenbaum Avatar answered Oct 13 '22 18:10

Natalie Weizenbaum