From 7088f3a3e2046d2259f98e6bc531c2fa7857b31c Mon Sep 17 00:00:00 2001 From: Lenny Burdette Date: Mon, 12 Oct 2009 17:10:00 -0700 Subject: [PATCH] add :trim and :safe options to ERBTemplate --- lib/tilt.rb | 2 +- test/spec_tilt_erbtemplate.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/tilt.rb b/lib/tilt.rb index 9a453b78..4635b106 100644 --- a/lib/tilt.rb +++ b/lib/tilt.rb @@ -180,7 +180,7 @@ def template_source class ERBTemplate < Template def compile! require_template_library 'erb' unless defined?(::ERB) - @engine = ::ERB.new(data, nil, nil, '@_out_buf') + @engine = ::ERB.new(data, options[:safe], options[:trim], '@_out_buf') end def template_source diff --git a/test/spec_tilt_erbtemplate.rb b/test/spec_tilt_erbtemplate.rb index ef6b5e17..af01361b 100644 --- a/test/spec_tilt_erbtemplate.rb +++ b/test/spec_tilt_erbtemplate.rb @@ -65,6 +65,21 @@ line.should.equal '6' end end + + it "renders erb templates with new lines by default" do + template = Tilt.new('test.erb', 1) { "\n<%= 1 + 1 %>\n" } + template.render.should.equal "\n2\n" + end + + it "strips new lines explicitly when :trim option is set to '-'" do + template = Tilt.new('test.erb', 1, :trim => '-') { "\n<%= 1 + 1 -%>\n" } + template.render.should.equal "\n2" + end + + it "processes lines start with % when :trim option is set to '%'" do + template = Tilt.new('test.erb', 1, :trim => '%') { "\n% if true\nhello\n%end\n" } + template.render.should.equal "\nhello\n" + end end __END__