Skip to content

Commit

Permalink
add :trim and :safe options to ERBTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
lennyburdette authored and rtomayko committed Oct 16, 2009
1 parent db7777e commit 7088f3a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tilt.rb
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/spec_tilt_erbtemplate.rb
Expand Up @@ -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__
Expand Down

0 comments on commit 7088f3a

Please sign in to comment.