add support for erubis to content-for
This commit is contained in:
parent
7e72a34a3a
commit
ee59224a99
|
@ -92,12 +92,15 @@ module Sinatra
|
|||
private
|
||||
|
||||
# generated templates will be cached by Sinatra in production
|
||||
capture :haml, "= capture_haml(*args, &block)"
|
||||
capture :erb, "<% block.call(*args) %>"
|
||||
capture :haml, "= capture_haml(*args, &block)"
|
||||
capture :erb, "<% block.call(*args) %>"
|
||||
capture :erubis, "<% eval '_buf.clear', block.binding %><%= block.call(*args) %>"
|
||||
|
||||
def capture(engine, args, block)
|
||||
render(engine, Sinatra::ContentFor.capture(engine), {},
|
||||
:args => args, :block => block)
|
||||
@_out_buf, buf_was = nil, @_out_buf
|
||||
render(engine, Sinatra::ContentFor.capture(engine), {}, :args => args, :block => block)
|
||||
ensure
|
||||
@_out_buf = buf_was
|
||||
end
|
||||
|
||||
def render(engine, *)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<% content_for :bar do %>bar<% end %>
|
|
@ -0,0 +1 @@
|
|||
<%= yield_content :foo %>
|
|
@ -0,0 +1,4 @@
|
|||
<% content_for :foo do %>foo<% end %>
|
||||
<% content_for :foo do %>bar<% end %>
|
||||
<% content_for :baz do %>WON'T RENDER ME<% end %>
|
||||
<% content_for :foo do %>baz<% end %>
|
|
@ -0,0 +1 @@
|
|||
<%= yield_content :foo, 1, 2 %>
|
|
@ -0,0 +1 @@
|
|||
<% content_for :foo do %>foo<% end %>
|
|
@ -0,0 +1 @@
|
|||
<% content_for :foo do |a, b| %><i><%= a %></i> <%= b %><% end %>
|
|
@ -2,8 +2,8 @@ require 'backports'
|
|||
require_relative 'spec_helper'
|
||||
|
||||
describe Sinatra::ContentFor do
|
||||
# TODO: erubis slim liquid radius markaby builder nokogiri
|
||||
engines = %w[erb haml]
|
||||
# TODO: slim liquid radius markaby builder nokogiri
|
||||
engines = %w[erb erubis haml]
|
||||
engines.each do |inner|
|
||||
engines.each do |outer|
|
||||
describe "#{inner.capitalize} templates with #{outer.capitalize} layouts" do
|
||||
|
|
Loading…
Reference in New Issue