Skip to content

Commit

Permalink
Configure ERB trim mode
Browse files Browse the repository at this point in the history
  • Loading branch information
apexatoll committed Oct 28, 2023
1 parent 907d3fd commit f5325b3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/kangaru/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(command)
def render(binding)
return unless view_path.exist?

ERB.new(view_path.read).run(binding)
ERB.new(view_path.read, trim_mode: "-").run(binding)
end

private
Expand Down
42 changes: 42 additions & 0 deletions spec/features/rendering_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,47 @@ def default
end
end
end

describe "whitespace trimming" do
context "when trim tags are not used" do
let(:view_file) do
<<~ERB
<% %i[foo bar baz].each do |symbol| %>
<%= symbol %>
<% end %>
ERB
end

it "outputs the text with the expected formatting" do
expect { run_command! }.to output(<<~TEXT).to_stdout
foo
bar
baz
TEXT
end
end

context "when trim tags are used" do
let(:view_file) do
<<~ERB
<% %i[foo bar baz].each do |symbol| -%>
<%= symbol %>
<% end -%>
ERB
end

it "outputs the text with the expected formatting" do
expect { run_command! }.to output(<<~TEXT).to_stdout
foo
bar
baz
TEXT
end
end
end
end
end

0 comments on commit f5325b3

Please sign in to comment.