add support for erubis to content-for

This commit is contained in:
Konstantin Haase 2011-03-28 16:22:45 +02:00
parent 7e72a34a3a
commit ee59224a99
8 changed files with 18 additions and 6 deletions

View File

@ -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, *)

View File

@ -0,0 +1 @@
<% content_for :bar do %>bar<% end %>

View File

@ -0,0 +1 @@
<%= yield_content :foo %>

View File

@ -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 %>

View File

@ -0,0 +1 @@
<%= yield_content :foo, 1, 2 %>

View File

@ -0,0 +1 @@
<% content_for :foo do %>foo<% end %>

View File

@ -0,0 +1 @@
<% content_for :foo do |a, b| %><i><%= a %></i> <%= b %><% end %>

View File

@ -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