1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

add slim support to content_for

This commit is contained in:
Konstantin Haase 2011-03-28 16:56:54 +02:00
parent c80b7233a5
commit e417ccc1e7
8 changed files with 24 additions and 5 deletions

View file

@ -93,12 +93,14 @@ module Sinatra
# generated templates will be cached by Sinatra in production
capture :haml, "!= capture_haml(*args, &block)"
capture :erb, "<% block.call(*args) %>"
capture :erubis, "<% eval '_buf.clear', block.binding %><%= block.call(*args) %>"
capture :erb, "<% yield(*args) %>"
capture :erubis, "<%= yield(*args) %>"
capture :slim, "== yield(*args)"
def capture(engine, args, block)
@_out_buf, buf_was = nil, @_out_buf
render(engine, Sinatra::ContentFor.capture(engine), {}, :args => args, :block => block)
eval '_buf.clear if defined? _buf', block.binding
render(engine, Sinatra::ContentFor.capture(engine), {}, :args => args, :block => block, &block)
ensure
@_out_buf = buf_was
end

View file

@ -0,0 +1,2 @@
- content_for :bar do
| bar

View file

@ -0,0 +1 @@
= yield_content :foo

View file

@ -0,0 +1,8 @@
- content_for :foo do
| foo
- content_for :foo do
| bar
- content_for :baz do
| WON'T RENDER ME
- content_for :foo do
| baz

View file

@ -0,0 +1 @@
== yield_content :foo, 1, 2

View file

@ -0,0 +1,2 @@
- content_for :foo do
| foo

View file

@ -0,0 +1,3 @@
- content_for :foo do |a, b|
i= a
= b

View file

@ -2,8 +2,8 @@ require 'backports'
require_relative 'spec_helper'
describe Sinatra::ContentFor do
# TODO: slim liquid radius markaby builder nokogiri
engines = %w[erb erubis haml]
# TODO: liquid radius markaby builder nokogiri
engines = %w[erb erubis haml slim]
engines.each do |inner|
engines.each do |outer|
describe "#{inner.capitalize} templates with #{outer.capitalize} layouts" do