mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
Tests: 5 template helpers can nest layouts
This commit is contained in:
parent
9087825161
commit
ea0d9673ed
5 changed files with 89 additions and 0 deletions
|
@ -85,6 +85,24 @@ class ERBTest < Test::Unit::TestCase
|
||||||
assert ok?
|
assert ok?
|
||||||
assert_equal '<outer><inner>hi</inner></outer>', body
|
assert_equal '<outer><inner>hi</inner></outer>', body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "can rendere truly nested layouts by accepting a layout and a block with the contents" do
|
||||||
|
mock_app do
|
||||||
|
template(:main_outer_layout) { "<h1>Title</h1>\n<%= yield %>" }
|
||||||
|
template(:an_inner_layout) { "<h2>Subtitle</h2>\n<%= yield %>" }
|
||||||
|
template(:a_page) { "<p>Contents.</p>\n" }
|
||||||
|
get('/') do
|
||||||
|
erb :main_outer_layout, :layout => false do
|
||||||
|
erb :an_inner_layout do
|
||||||
|
erb :a_page
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
get '/'
|
||||||
|
assert ok?
|
||||||
|
assert_body "<h1>Title</h1>\n<h2>Subtitle</h2>\n<p>Contents.</p>\n"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,24 @@ class HAMLTest < Test::Unit::TestCase
|
||||||
haml_app { haml "= foo", :locals => { :foo => 'bar' }}
|
haml_app { haml "= foo", :locals => { :foo => 'bar' }}
|
||||||
assert_equal "bar\n", body
|
assert_equal "bar\n", body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "can rendere truly nested layouts by accepting a layout and a block with the contents" do
|
||||||
|
mock_app do
|
||||||
|
template(:main_outer_layout) { "%h1 Title\n= yield" }
|
||||||
|
template(:an_inner_layout) { "%h2 Subtitle\n= yield" }
|
||||||
|
template(:a_page) { "%p Contents." }
|
||||||
|
get('/') do
|
||||||
|
haml :main_outer_layout, :layout => false do
|
||||||
|
haml :an_inner_layout do
|
||||||
|
haml :a_page
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
get '/'
|
||||||
|
assert ok?
|
||||||
|
assert_body "<h1>Title</h1>\n<h2>Subtitle</h2>\n<p>Contents.</p>\n"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
|
|
|
@ -52,6 +52,24 @@ class LiquidTest < Test::Unit::TestCase
|
||||||
assert ok?
|
assert ok?
|
||||||
assert_equal 'foo', body
|
assert_equal 'foo', body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "can rendere truly nested layouts by accepting a layout and a block with the contents" do
|
||||||
|
mock_app do
|
||||||
|
template(:main_outer_layout) { "<h1>Title</h1>\n{{ yield }}" }
|
||||||
|
template(:an_inner_layout) { "<h2>Subtitle</h2>\n{{ yield }}" }
|
||||||
|
template(:a_page) { "<p>Contents.</p>\n" }
|
||||||
|
get('/') do
|
||||||
|
liquid :main_outer_layout, :layout => false do
|
||||||
|
liquid :an_inner_layout do
|
||||||
|
liquid :a_page
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
get '/'
|
||||||
|
assert ok?
|
||||||
|
assert_body "<h1>Title</h1>\n<h2>Subtitle</h2>\n<p>Contents.</p>\n"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
|
|
|
@ -77,6 +77,24 @@ class SlimTest < Test::Unit::TestCase
|
||||||
assert ok?
|
assert ok?
|
||||||
assert_body '<x foo="bar"></x>'
|
assert_body '<x foo="bar"></x>'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "can rendere truly nested layouts by accepting a layout and a block with the contents" do
|
||||||
|
mock_app do
|
||||||
|
template(:main_outer_layout) { "h1 Title\n== yield" }
|
||||||
|
template(:an_inner_layout) { "h2 Subtitle\n== yield" }
|
||||||
|
template(:a_page) { "p Contents." }
|
||||||
|
get('/') do
|
||||||
|
slim :main_outer_layout, :layout => false do
|
||||||
|
slim :an_inner_layout do
|
||||||
|
slim :a_page
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
get '/'
|
||||||
|
assert ok?
|
||||||
|
assert_body "<h1>Title</h1>\n<h2>Subtitle</h2>\n<p>Contents.</p>\n"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
|
|
|
@ -63,6 +63,23 @@ class WLangTest < Test::Unit::TestCase
|
||||||
assert_body "WLang Layout!\nHello World"
|
assert_body "WLang Layout!\nHello World"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "can rendere truly nested layouts by accepting a layout and a block with the contents" do
|
||||||
|
mock_app do
|
||||||
|
template(:main_outer_layout) { "<h1>Title</h1>\n>{ yield }" }
|
||||||
|
template(:an_inner_layout) { "<h2>Subtitle</h2>\n>{ yield }" }
|
||||||
|
template(:a_page) { "<p>Contents.</p>\n" }
|
||||||
|
get('/') do
|
||||||
|
wlang :main_outer_layout, :layout => false do
|
||||||
|
wlang :an_inner_layout do
|
||||||
|
wlang :a_page
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
get '/'
|
||||||
|
assert ok?
|
||||||
|
assert_body "<h1>Title</h1>\n<h2>Subtitle</h2>\n<p>Contents.</p>\n"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
|
|
Loading…
Reference in a new issue