From ea0d9673ed31df69c22b5a127d2026851a89cb8b Mon Sep 17 00:00:00 2001 From: Alexey Muranov Date: Sun, 17 Feb 2013 12:53:34 +0100 Subject: [PATCH] Tests: 5 template helpers can nest layouts --- test/erb_test.rb | 18 ++++++++++++++++++ test/haml_test.rb | 18 ++++++++++++++++++ test/liquid_test.rb | 18 ++++++++++++++++++ test/slim_test.rb | 18 ++++++++++++++++++ test/wlang_test.rb | 17 +++++++++++++++++ 5 files changed, 89 insertions(+) diff --git a/test/erb_test.rb b/test/erb_test.rb index 75d932de..364b3a70 100644 --- a/test/erb_test.rb +++ b/test/erb_test.rb @@ -85,6 +85,24 @@ class ERBTest < Test::Unit::TestCase assert ok? assert_equal 'hi', body 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) { "

Title

\n<%= yield %>" } + template(:an_inner_layout) { "

Subtitle

\n<%= yield %>" } + template(:a_page) { "

Contents.

\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 "

Title

\n

Subtitle

\n

Contents.

\n" + end end diff --git a/test/haml_test.rb b/test/haml_test.rb index bc2ddb25..5d4c67be 100644 --- a/test/haml_test.rb +++ b/test/haml_test.rb @@ -84,6 +84,24 @@ class HAMLTest < Test::Unit::TestCase haml_app { haml "= foo", :locals => { :foo => 'bar' }} assert_equal "bar\n", body 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 "

Title

\n

Subtitle

\n

Contents.

\n" + end end rescue LoadError diff --git a/test/liquid_test.rb b/test/liquid_test.rb index 4988dbd8..8a8f48ef 100644 --- a/test/liquid_test.rb +++ b/test/liquid_test.rb @@ -52,6 +52,24 @@ class LiquidTest < Test::Unit::TestCase assert ok? assert_equal 'foo', body 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) { "

Title

\n{{ yield }}" } + template(:an_inner_layout) { "

Subtitle

\n{{ yield }}" } + template(:a_page) { "

Contents.

\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 "

Title

\n

Subtitle

\n

Contents.

\n" + end end rescue LoadError diff --git a/test/slim_test.rb b/test/slim_test.rb index 59057047..01981c32 100644 --- a/test/slim_test.rb +++ b/test/slim_test.rb @@ -77,6 +77,24 @@ class SlimTest < Test::Unit::TestCase assert ok? assert_body '' 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 "

Title

\n

Subtitle

\n

Contents.

\n" + end end rescue LoadError diff --git a/test/wlang_test.rb b/test/wlang_test.rb index 9b3e4467..67065ec1 100644 --- a/test/wlang_test.rb +++ b/test/wlang_test.rb @@ -63,6 +63,23 @@ class WLangTest < Test::Unit::TestCase assert_body "WLang Layout!\nHello World" 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) { "

Title

\n>{ yield }" } + template(:an_inner_layout) { "

Subtitle

\n>{ yield }" } + template(:a_page) { "

Contents.

\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 "

Title

\n

Subtitle

\n

Contents.

\n" + end end rescue LoadError