diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 1c3881e2..37fab962 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -282,7 +282,7 @@ module Sinatra def render_erb(template, data, options, &block) data = data.call if data.kind_of? Proc - instance = ::ERB.new(data) + instance = ::ERB.new(data, nil, nil, '@_out_buf') locals = options[:locals] || {} locals_assigns = locals.to_a.collect { |k,v| "#{k} = locals[:#{k}]" } src = "#{locals_assigns.join("\n")}\n#{instance.src}" diff --git a/test/erb_test.rb b/test/erb_test.rb index e3fd9dcf..df3902d2 100644 --- a/test/erb_test.rb +++ b/test/erb_test.rb @@ -47,4 +47,21 @@ describe "ERB Templates" do assert ok? assert_equal "ERB Layout!\nHello World\n", body end + + it "renders erb with blocks" do + mock_app { + def container + @_out_buf << "THIS." + yield + @_out_buf << "SPARTA!" + end + def is; "IS." end + get '/' do + erb '<% container do %> <%= is %> <% end %>' + end + } + get '/' + assert ok? + assert_equal 'THIS. IS. SPARTA!', body + end end