Chef infra ERB模板中的Chef换行符

Chef infra ERB模板中的Chef换行符,chef-infra,newline,erb,Chef Infra,Newline,Erb,我有一个变量,当在Chef ERB模板中输出时,我希望跨越两行 因此,如果node['apples']等于“Cortland\nRed Delicious\nGolden Delicious\nEmpire\nFuji\nGala” 我希望它显示为: Cortland, Red Delicious, Golden Delicious, Empire, Fuji, Gala 当我打电话时: <%= node['apples'] %> 在我的模板中。换行符\n似乎不起作用。这种行

我有一个变量,当在Chef ERB模板中输出时,我希望跨越两行

因此,如果
node['apples']
等于
“Cortland\nRed Delicious\nGolden Delicious\nEmpire\nFuji\nGala”

我希望它显示为:

Cortland,
Red Delicious,
Golden Delicious,
Empire,
Fuji,
Gala
当我打电话时:

<%= node['apples'] %>

在我的模板中。换行符
\n
似乎不起作用。这种行为是如何实现的


谢谢

我终于想出了解决这个问题的办法

问题中描述的场景通过简单地添加新行字符来表示变量中的中断来解决

因此,一个变量声明为:

"Cortland, " + 0x0D.chr + 0x0A.chr + "Red Delicious"
将作为以下内容输出到模板:

Cortland,
Red Delicious

您可以在模板中的a列表中循环,而不是将控制字符添加到字符串中

配方:

$ cat test.rb 
node.set['apples'] = %W(Cortland Red\ Delicious Golden\ Delicious Empire Fuji Gala)

template "test" do
  local true
  source "./test.erb"
end
使用rubys
join
在每个元素末尾添加所需字符的模板:

$ cat test.erb 
<%= node['apples'].join(",\n") %>
您还可以查看Rubys
split
,将字符串转换为列表


编辑后添加到原始请求中。\n。

此解决方案更干净。非常感谢。
$ chef-apply test.rb 
Recipe: (chef-apply cookbook)::(chef-apply recipe)
  * template[test] action create
    - create new file test
    - update content in file test from none to 70d960
    --- test    2015-08-02 12:32:23.000000000 -0500
    +++ /var/folders/r6/9h72_qg11f18brxvpdpn6lbm0000gn/T/chef-rendered-template20150802-76337-130h5sl   2015-08-02 12:32:23.000000000 -0500
    @@ -1 +1,8 @@
        +Cortland,
        +Red,
        +Delicious,
        +Golden Delicious,
        +Empire,
        +Fuji,
        +Gala