Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/curly/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ def compile_component(component)
end

def compile_text(text)
output "buffer.safe_concat(#{text.value.inspect})"
if non_whitespace_text = text.value.presence
output "buffer.safe_concat(#{non_whitespace_text.inspect})"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would remove indentional whitespace as well, right?

{{one}}   {{two}}   {{three}}

There may be a reason for the whitespace, e.g. when sending plain text emails.

end
end

def compile_comment(comment)
Expand Down
7 changes: 7 additions & 0 deletions spec/compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ def method_missing(*args)
evaluate("test{{^false?}}bar{{/false?}}").should == "testbar"
end

it "removes extra whitespace from the output" do
presenter.stub(:foo) { "" }
template = "{{^false?}}\n{{foo}}\n<a href='bar'>bar</a>\n{{foo}}\n{{/false?}}\n"

evaluate(template).should == "\n<a href='bar'>bar</a>\n"
end

it "passes an argument to blocks" do
evaluate("{{#hello.world?}}foo{{/hello.world?}}{{#hello.foo?}}bar{{/hello.foo?}}").should == "foo"
end
Expand Down