最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

What kind of RubyErb is allowed inside HAML's :javascript filter? - Stack Overflow

programmeradmin5浏览0评论

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

So this is NOT allowed:

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

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

(somebody said there is not way to hide ment 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?

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

So this is NOT allowed:

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

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

(somebody said there is not way to hide ment 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?

Share Improve this question asked Jun 4, 2010 at 5:05 nonopolaritynonopolarity 151k142 gold badges492 silver badges782 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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 plex 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.

发布评论

评论列表(0)

  1. 暂无评论