【问题标题】:Haml not parsing the element with a dash in it's nameHaml 不解析名称中带有破折号的元素
【发布时间】:2016-03-18 12:01:44
【问题描述】:

给定这个haml代码

%uib-pagination{:boundary-links => "true", :total-items => "totalItems", :ng-model => "currentPage", :class => "pagination-sm", :previous-text => "‹", :next-text => "›", :first-text => "«", :last-text => "»"}

输出如下所示

<uib>-pagination{:boundary-links =&gt; "true", :total-items =&gt; "totalItems", :ng-model =&gt; "currentPage", :class =&gt; "pagination-sm", :previous-text =&gt; "‹", :next-text =&gt; "›", :first-text =&gt; "«", :last-text =&gt; "»"}</uib>

是否可以设置破折号?

【问题讨论】:

  • 你是如何生成 HTML 的? Haml 的 Ruby 实现不会给出这样的结果,你会得到一个类似 undefined local variable or method `links' 的错误(你需要在属性中使用字符串而不是符号来避免这种情况)。
  • @matt,我正在使用hamlpy python 库。

标签: python angularjs haml


【解决方案1】:

在HamlPy中,用于提取标签名称的正则表达式为?P&lt;tag&gt;%\w+(\:\w+)?,因此无法设置破折号。

用下划线替换即可:

[thyrst@THy tmp]$ cat file.haml
%uib_pagination{:boundary-links => "true", :total-items => "totalItems", :ng-model => "currentPage", :class => "pagination-sm", :previous-text => "&lsaquo;", :next-text => "&rsaquo;", :first-text => "&laquo;", :last-text => "&raquo;"}

[thyrst@THy tmp]$ hamlpy file.haml
<uib_pagination class='pagination-sm' boundary-links='true' total-items='totalItems' ng-model='currentPage' previous-text='&lsaquo;' next-text='&rsaquo;' first-text='&laquo;' last-text='&raquo;'></uib_pagination>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-15
    • 1970-01-01
    • 2021-04-03
    • 2016-01-28
    • 2017-07-01
    • 1970-01-01
    • 2013-02-04
    • 2014-04-28
    相关资源
    最近更新 更多