为什么 HAML 认为我有内容在线和嵌套? (我不)
Why does HAML think I have content on the line and nested? (I don't)
我的 HAML 读取:
%table.screenshots
%thead
%trow
%td{:colspan => 12} Screenshots for #{element.name}
%tbody
- screenshots.each do |set|
%tr
- set[1].each do |shot|
- if shot == :blank_cell
%td{:colspan => set[0]}.twelfth
- else
%td{:colspan => set[0]}.twelfth
= image_tag(shot[1]) # <= ERROR APPEARS HERE
- if @redacted
%h1.blur
%span Image blurred in
%br
%span demo report only
%p #{shot[0]}
.twelfth
后没有不可见的空格或制表符。
那么,为什么会出现此错误?
Illegal nesting: content can't be both given on the same line as %td and nested within it.
顺便说一句,当我 运行:
时,我得到了同样的异常
haml --debug print.html.haml
通过将有问题的行更改为以下内容来修复它:
%td{:colspan => set[0], :class => "twelfth"}
HAML 解释器中似乎存在错误
class 和 id 标识符(.
和 #
)必须位于标签名称之后,任何属性散列之前。
在你的代码中,问题在于行:
%td{:colspan => set[0]}.twelfth
这被解释为具有 colspan
属性的 td
元素,包含内容 .twelfth
,如果它本身呈现时看起来像这样:
<td colspan='7'>.twelfth</td>
但是这一行下面还有嵌套的内容,这是 Haml 不允许的。
您可以通过在属性哈希中使用显式 class
条目来解决此问题,就像您在 中所做的那样,或者将 .twelth
class 说明符移到前面属性散列,像这样:
%th.twelfth{:colspan => set[0]}
我的 HAML 读取:
%table.screenshots
%thead
%trow
%td{:colspan => 12} Screenshots for #{element.name}
%tbody
- screenshots.each do |set|
%tr
- set[1].each do |shot|
- if shot == :blank_cell
%td{:colspan => set[0]}.twelfth
- else
%td{:colspan => set[0]}.twelfth
= image_tag(shot[1]) # <= ERROR APPEARS HERE
- if @redacted
%h1.blur
%span Image blurred in
%br
%span demo report only
%p #{shot[0]}
.twelfth
后没有不可见的空格或制表符。
那么,为什么会出现此错误?
Illegal nesting: content can't be both given on the same line as %td and nested within it.
顺便说一句,当我 运行:
时,我得到了同样的异常haml --debug print.html.haml
通过将有问题的行更改为以下内容来修复它:
%td{:colspan => set[0], :class => "twelfth"}
HAML 解释器中似乎存在错误
class 和 id 标识符(.
和 #
)必须位于标签名称之后,任何属性散列之前。
在你的代码中,问题在于行:
%td{:colspan => set[0]}.twelfth
这被解释为具有 colspan
属性的 td
元素,包含内容 .twelfth
,如果它本身呈现时看起来像这样:
<td colspan='7'>.twelfth</td>
但是这一行下面还有嵌套的内容,这是 Haml 不允许的。
您可以通过在属性哈希中使用显式 class
条目来解决此问题,就像您在 .twelth
class 说明符移到前面属性散列,像这样:
%th.twelfth{:colspan => set[0]}