我认为没有这样的内置东西。幸运的是,在 Hamlet 中使用辅助函数很容易。例如,如果您的项目是纯字符串,您可以使用Data.List.intercalate
在它们之间添加逗号。
The values in the list are
#{intercalate ", " list}
and that is it.
如果您想做更奇特的事情,您可以编写函数来处理哈姆雷特值。例如,这是一个在列表中的 Hamlet 值之间添加逗号和“and”的函数。
commaify [x] = x
commaify [x, y] = [hamlet|^{x} and ^{y}|]
commaify (x:xs) = [hamlet|^{x}, ^{commaify xs}|]
这使用^{...}
将一个 Hamlet 值插入另一个值的语法。现在,我们可以用它来编写一个逗号分隔的下划线单词列表。
The values in the list are
^{commaify (map underline list)}
and that is it.
Here, underline
只是一个小辅助函数,可以生成比纯文本更有趣的内容。
underline word = [hamlet|<u>#{word}|]
渲染后,会产生以下结果。
The values in the list are <u>foo</u>, <u>bar</u> and <u>baz</u> and that is it.