HAML中的多行字符串

因为我不希望我的任何行超过80列,所以我想将最后一行拆分为两行。 在行尾添加逗号按照此处的建议工作,但逗号后面会出现逗号。 使用HAML有一个很好的清洁方法吗?

- if object.errors.any? %section.form_error_message %h4.form_error_message__title = "#{pluralize(object.errors.size, 'errors')} prevented this form from submitting. Please fix these errors and try again." 

我希望所有内容都隐藏在80个列中,就像它们在此屏幕截图的左侧一样。

在此处输入图像描述

Haml使用| 支持这样的多行序列 字符:

 - if object.errors.any? %section.form_error_message %h4.form_error_message__title = "#{pluralize(object.errors.size, 'errors')} prevented this form from | submitting. Please fix these errors and try again." | 

在这种情况下你不需要这个,你可以直接在纯文本中使用插值 ,你不需要=

 - if object.errors.any? %section.form_error_message %h4.form_error_message__title #{pluralize(object.errors.size, 'errors')} prevented this form from submitting. Please fix these errors and try again. 

(这个的输出会略有不同,因为它会包含换行符。你应该注意到在渲染的HTML中,除非你在例如


标签内。)

 %div First line | and second line | 

将呈现:

 
First line and second line

如果你甚至不想要一个标签:

 First line | and second line | 

会产生:

 First line and second line 

您可以使用命令工具haml ,例如复制代码然后pbpaste | haml pbpaste | haml在macOS上,或者用文件cat file.haml | haml cat file.haml | haml