mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
simplify ContentFor.capture
This commit is contained in:
parent
cf6de883d0
commit
8190013f0b
1 changed files with 6 additions and 8 deletions
|
@ -75,24 +75,22 @@ module Sinatra
|
||||||
content_blocks[key.to_sym].map { |e,b| capture(e, args, b) }.join
|
content_blocks[key.to_sym].map { |e,b| capture(e, args, b) }.join
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.capture(name, template = nil)
|
def self.capture
|
||||||
@capture ||= {}
|
@capture ||= {}
|
||||||
@capture[name] = template if template
|
|
||||||
@capture[name]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# generated templates will be cached by Sinatra in production
|
# generated templates will be cached by Sinatra in production
|
||||||
capture :haml, "!= capture_haml(*args, &block)"
|
capture[:haml] = "!= capture_haml(*args, &block)"
|
||||||
capture :erb, "<% yield(*args) %>"
|
capture[:erb] = "<% yield(*args) %>"
|
||||||
capture :erubis, "<%= yield(*args) %>"
|
capture[:erubis] = "<%= yield(*args) %>"
|
||||||
capture :slim, "== yield(*args)"
|
capture[:slim] = "== yield(*args)"
|
||||||
|
|
||||||
def capture(engine, args, block)
|
def capture(engine, args, block)
|
||||||
@_out_buf, buf_was = nil, @_out_buf
|
@_out_buf, buf_was = nil, @_out_buf
|
||||||
eval '_buf.clear if defined? _buf', block.binding
|
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
|
ensure
|
||||||
@_out_buf = buf_was
|
@_out_buf = buf_was
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue