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:
parent
c80b7233a5
commit
e417ccc1e7
8 changed files with 24 additions and 5 deletions
|
@ -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
|
||||
|
|
2
sinatra-contrib/spec/content_for/different_key.slim
Normal file
2
sinatra-contrib/spec/content_for/different_key.slim
Normal file
|
@ -0,0 +1,2 @@
|
|||
- content_for :bar do
|
||||
| bar
|
1
sinatra-contrib/spec/content_for/layout.slim
Normal file
1
sinatra-contrib/spec/content_for/layout.slim
Normal file
|
@ -0,0 +1 @@
|
|||
= yield_content :foo
|
8
sinatra-contrib/spec/content_for/multiple_blocks.slim
Normal file
8
sinatra-contrib/spec/content_for/multiple_blocks.slim
Normal 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
|
1
sinatra-contrib/spec/content_for/passes_values.slim
Normal file
1
sinatra-contrib/spec/content_for/passes_values.slim
Normal file
|
@ -0,0 +1 @@
|
|||
== yield_content :foo, 1, 2
|
2
sinatra-contrib/spec/content_for/same_key.slim
Normal file
2
sinatra-contrib/spec/content_for/same_key.slim
Normal file
|
@ -0,0 +1,2 @@
|
|||
- content_for :foo do
|
||||
| foo
|
3
sinatra-contrib/spec/content_for/takes_values.slim
Normal file
3
sinatra-contrib/spec/content_for/takes_values.slim
Normal file
|
@ -0,0 +1,3 @@
|
|||
- content_for :foo do |a, b|
|
||||
i= a
|
||||
= b
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue