From 6c36c82153b1a8bc63830aa79b8b19e07d5d92fd Mon Sep 17 00:00:00 2001 From: Nick Hammond Date: Tue, 24 Oct 2023 17:09:05 -0700 Subject: [PATCH] Enable trim mode with ERB --- lib/kamal/cli/main.rb | 2 +- test/cli/main_test.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/kamal/cli/main.rb b/lib/kamal/cli/main.rb index 36fe1b751..f3e48d202 100644 --- a/lib/kamal/cli/main.rb +++ b/lib/kamal/cli/main.rb @@ -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 diff --git a/test/cli/main_test.rb b/test/cli/main_test.rb index fe174653c..be8f582c8 100644 --- a/test/cli/main_test.rb +++ b/test/cli/main_test.rb @@ -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)