From 8190013f0bd1699967d3a1d78d4211c36e16a6b0 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 30 Mar 2011 22:35:09 +0200 Subject: [PATCH] simplify ContentFor.capture --- sinatra-contrib/lib/sinatra/content_for.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/sinatra-contrib/lib/sinatra/content_for.rb b/sinatra-contrib/lib/sinatra/content_for.rb index f22e18d2..3f636b6a 100644 --- a/sinatra-contrib/lib/sinatra/content_for.rb +++ b/sinatra-contrib/lib/sinatra/content_for.rb @@ -75,24 +75,22 @@ module Sinatra content_blocks[key.to_sym].map { |e,b| capture(e, args, b) }.join end - def self.capture(name, template = nil) + def self.capture @capture ||= {} - @capture[name] = template if template - @capture[name] end private # generated templates will be cached by Sinatra in production - capture :haml, "!= capture_haml(*args, &block)" - capture :erb, "<% yield(*args) %>" - capture :erubis, "<%= yield(*args) %>" - capture :slim, "== yield(*args)" + capture[:haml] = "!= capture_haml(*args, &block)" + capture[:erb] = "<% yield(*args) %>" + capture[:erubis] = "<%= yield(*args) %>" + capture[:slim] = "== yield(*args)" def capture(engine, args, block) @_out_buf, buf_was = nil, @_out_buf eval '_buf.clear if defined? _buf', block.binding - render(engine, Sinatra::ContentFor.capture(engine), {}, :args => args, :block => block, &block) + render(engine, Sinatra::ContentFor.capture.fetch(engine), {}, :args => args, :block => block, &block) ensure @_out_buf = buf_was end