Skip to content

Commit

Permalink
Enable trim mode with ERB
Browse files Browse the repository at this point in the history
  • Loading branch information
nickhammond committed Oct 25, 2023
1 parent 83a2d52 commit 6c36c82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/kamal/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def envify
env_path = ".env"
end

File.write(env_path, ERB.new(File.read(env_template_path)).result, perm: 0600)
File.write(env_path, ERB.new(File.read(env_template_path), trim_mode: "-").result, perm: 0600)

load_envs # reload new file
invoke "kamal:cli:env:push", options
Expand Down
14 changes: 14 additions & 0 deletions test/cli/main_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,20 @@ class CliMainTest < CliTestCase
run_command("envify")
end

test "envify with blank line trimming" do
file = <<~EOF
HELLO=<%= 'world' %>
<% if true -%>
KEY=value
<% end -%>
EOF

File.expects(:read).with(".env.erb").returns(file.strip)
File.expects(:write).with(".env", "HELLO=world\nKEY=value\n", perm: 0600)

run_command("envify")
end

test "envify with destination" do
File.expects(:read).with(".env.world.erb").returns("HELLO=<%= 'world' %>")
File.expects(:write).with(".env.world", "HELLO=world", perm: 0600)
Expand Down

0 comments on commit 6c36c82

Please sign in to comment.