非常长的 html 属性的 Haml 多行

Haml multiline for really long html attribute

我和我的编码合作伙伴今天花了很多时间试图弄清楚如何重构具有非常长属性的 link 以使其成为多行:

%a.pull-right{ href: "#", "data-html" => "true", rel: "tooltip", 
  "data-placement" => "left", title: "This is really just so much text. The real thing goes on and on and on, much longer than this. It also contains some line breaks.<br><br>We'd really like to be able to wrap it around so it's readable in the code." }

多行字符串文档中列出的管道方法 (+ |) 在此上下文中似乎不起作用。我们能想到的最易读的解决方案是:

:ruby
  tooltip_text = %Q(
    This is really just so much text. The real thing goes on and on 
    and on, much longer than this. It also contains some line breaks.
    <br><br>
    We'd really like to be able to wrap it around so it's readable
    in the code.
  )

= link_to '#', class: 'pull-right', rel: 'tooltip', title: tooltip_text,
  'data-html' => 'true', 'data-placement' => 'left' do

显然,这样更好,但我更愿意将它们全部放在一个块中。有没有办法在不将文本移动到另一个文件的情况下执行此操作?

使用 | 对我来说没问题:

%a.pull-right{ href: "#", "data-html" => "true", rel: "tooltip",
  "data-placement" => "left", title: "This is really just so much text. |
  The real thing goes on and on and on, much longer than this. It also  |
  contains some line breaks.<br><br>We'd really like to be able to wrap |
   it around so it's readable in the code." }                           |

输出:

<a class='pull-right' data-html='true' data-placement='left' href='#' rel='tooltip' title="This is really just so much text. The real thing goes on and on and on, much longer than this. It also  contains some line breaks.&lt;br&gt;&lt;br&gt;We'd really like to be able to wrap it around so it's readable in the code."></a>

请注意,即使是最后一行也需要在其末尾添加管道字符。

此外,您可能需要将 <br> 更改为 \n 以使新行在浏览器中正常工作。