Permalink
Browse files

Allow helper methods to use blocks in erb views

  • Loading branch information...
1 parent 0044683 commit f3ed6e4dd99522767b27b637dfb100a4628613c3 Matias Käkelä committed with rtomayko Feb 18, 2009
Showing with 18 additions and 1 deletion.
  1. +1 −1 lib/sinatra/base.rb
  2. +17 −0 test/erb_test.rb
View
@@ -282,7 +282,7 @@ def template_path(engine, template, options={})
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}"
View
@@ -47,4 +47,21 @@ def erb_app(&block)
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

0 comments on commit f3ed6e4

Please sign in to comment.