haml html属性中的正则表达式 [英] regular expression in haml html attribute

查看:95
本文介绍了haml html属性中的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能有这样的事情吗? :

Is posibble to have something like this? :

%div{"data-regex": "a/regular/expression"}

当我尝试这样做时,出现此错误:

When I try to do this ways, I get this error:

syntax error, unexpected ':', expecting tASSOC

我尝试过:%div{"data-regex": #{"a/regular/expression"}},但还是一样.

I tried this: %div{"data-regex": #{"a/regular/expression"}}, but is the same.

推荐答案

您可能正在寻找的是:

%div{data: {regex: "a/regular/expression"} }

但是,如果您在问题中包含所需的HTML,那就很好了,我们可以肯定地知道.提供的其他答案也可以,但是如果您要提供许多数据属性而不到处重复"data-",则特别好.也就是说,您可以执行以下操作:

However it would be nice if you included the desired HTML in your question so we could know for sure. The other answer provided will also work, but this is especially nice if you want to provide many data attributes without repeating "data-" all over the place. That is, you can do:

%div{data: {regex: "a/reg/ex", attr2: "something", attr3: "something else" } } 

请注意,您的问题是,Ruby 1.9+中用于散列符号键的漂亮语法不适用于冒号之前的字符串.

Note, your problem is that the nice syntax in Ruby 1.9+ for Symbol keys in hashes doesn't work with strings preceding the colon.

{ a: 123 }
# => { :a => 123 }

{ :"a" => 123 }
# => { :a => 123 }

{ "a" => 123 }
# => { "a" => 123 }

{ "a": => 123 }
# => SyntaxError ...

这篇关于haml html属性中的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆