admin管理员组文章数量:1426097
Is there any way to add options (HTML attributes) to HAML filters?
I wanted to do something like this :
:javascript{:'data-turbolinks-eval' => 'false', :foo => 'bar'}
if(someCondition){
doSomething();
}
And the result would be :
<script 'data-turbolinks-eval'='false' 'foo'='bar'>
if(someCondition){
doSomething();
}
</script>
The closest I could get is :
%script{:'data-turbolinks-eval' => 'false', :foo => 'bar'}
if(someCondition){
doSomething();
}
The drawback is that you can't indent your JS in HAML unless you're using the :javascript filter. It's ok for a few lines, but it can get messy quickly.
I'm well aware that in most cases if you end up with a plex script in a HAML template, it means you're doing something wrong and that's not the answer I'm looking for.
Is there any way to add options (HTML attributes) to HAML filters?
I wanted to do something like this :
:javascript{:'data-turbolinks-eval' => 'false', :foo => 'bar'}
if(someCondition){
doSomething();
}
And the result would be :
<script 'data-turbolinks-eval'='false' 'foo'='bar'>
if(someCondition){
doSomething();
}
</script>
The closest I could get is :
%script{:'data-turbolinks-eval' => 'false', :foo => 'bar'}
if(someCondition){
doSomething();
}
The drawback is that you can't indent your JS in HAML unless you're using the :javascript filter. It's ok for a few lines, but it can get messy quickly.
I'm well aware that in most cases if you end up with a plex script in a HAML template, it means you're doing something wrong and that's not the answer I'm looking for.
Share Improve this question asked Jan 30, 2014 at 7:44 JimJim 1,06211 silver badges24 bronze badges1 Answer
Reset to default 9There is no way to pass extra attributes to the :javascript
filter like this. You could however use a :plain
filter along with a normal script
tag to allow indenting your javascript code:
%script{:'data-turbolinks-eval' => 'false', :foo => 'bar'}
:plain
if(someCondition()) {
doSomething();
}
produces:
<script data-turbolinks-eval='false' foo='bar'>
if(someCondition()) {
doSomething();
}
</script>
本文标签: javascriptSpecify options for a filter in ruby HAMLStack Overflow
版权声明:本文标题:javascript - Specify options for a filter in ruby HAML - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745412599a2657538.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论