Phi*_*man 2 ruby haml ruby-on-rails
我和我的编码伙伴今天花了很多时间试图弄清楚如何重构具有很长属性的链接以使其成为多行:
%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." }
Run Code Online (Sandbox Code Playgroud)
多行字符串文档中列出的管道方法 ( + |) 似乎在这种情况下不起作用。我们能想到的最易读的解决方案是:
: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
Run Code Online (Sandbox Code Playgroud)
显然,这更好,但我更愿意将它们全部集中在一个块中。有没有办法在不将文本移动到另一个文件的情况下执行此操作?
使用|对我来说没问题:
%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." } |
Run Code Online (Sandbox Code Playgroud)
输出:
<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.<br><br>We'd really like to be able to wrap it around so it's readable in the code."></a>
Run Code Online (Sandbox Code Playgroud)
请注意,即使最后一行也需要在其末尾有管道字符。
此外,您可能需要将<br>s 更改为\n以使新行在浏览器中正常工作。
| 归档时间: |
|
| 查看次数: |
1911 次 |
| 最近记录: |