1#============================================================= -*-perl-*- 2# 3# t/wrapper.t 4# 5# Template script testing the WRAPPER directive. 6# 7# Written by Andy Wardley <abw@kfs.org> 8# 9# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved. 10# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd. 11# 12# This is free software; you can redistribute it and/or modify it 13# under the same terms as Perl itself. 14# 15# $Id$ 16# 17#======================================================================== 18 19use strict; 20use lib qw( ../lib ./lib ); 21use Template::Constants qw( :status ); 22use Template; 23use Template::Test; 24$^W = 1; 25 26#$Template::Test::DEBUG = 0; 27#$Template::Context::DEBUG = 0; 28#$Template::Parser::DEBUG = 1; 29#$Template::Directive::PRETTY = 1; 30 31my $dir = -d 't' ? 't/test' : 'test'; 32my $tproc = Template->new({ 33 INCLUDE_PATH => "$dir/src:$dir/lib", 34 TRIM => 1, 35# WRAPPER => 'wrapper', 36}); 37 38 39test_expect(\*DATA, $tproc, &callsign()); 40 41__DATA__ 42-- test -- 43[% BLOCK mypage %] 44This is the header 45[% content %] 46This is the footer 47[% END -%] 48[% WRAPPER mypage -%] 49This is the content 50[%- END %] 51-- expect -- 52This is the header 53This is the content 54This is the footer 55 56-- test -- 57[% WRAPPER mywrap 58 title = 'Another Test' -%] 59This is some more content 60[%- END %] 61-- expect -- 62Wrapper Header 63Title: Another Test 64This is some more content 65Wrapper Footer 66 67-- test -- 68[% WRAPPER mywrap 69 title = 'Another Test' -%] 70This is some content 71[%- END %] 72-- expect -- 73Wrapper Header 74Title: Another Test 75This is some content 76Wrapper Footer 77 78 79-- test -- 80[% WRAPPER page 81 title = 'My Interesting Page' 82%] 83[% WRAPPER section 84 title = 'Quantum Mechanics' 85-%] 86Quantum mechanics is a very interesting subject wish 87should prove easy for the layman to fully comprehend. 88[%- END %] 89 90[% WRAPPER section 91 title = 'Desktop Nuclear Fusion for under $50' 92-%] 93This describes a simple device which generates significant 94sustainable electrical power from common tap water by process 95of nuclear fusion. 96[%- END %] 97[% END %] 98 99[% BLOCK page -%] 100<h1>[% title %]</h1> 101[% content %] 102<hr> 103[% END %] 104 105[% BLOCK section -%] 106<p> 107<h2>[% title %]</h2> 108[% content %] 109</p> 110[% END %] 111 112-- expect -- 113<h1>My Interesting Page</h1> 114 115<p> 116<h2>Quantum Mechanics</h2> 117Quantum mechanics is a very interesting subject wish 118should prove easy for the layman to fully comprehend. 119</p> 120 121<p> 122<h2>Desktop Nuclear Fusion for under $50</h2> 123This describes a simple device which generates significant 124sustainable electrical power from common tap water by process 125of nuclear fusion. 126</p> 127 128<hr> 129 130-- test -- 131[%# FOREACH s = [ 'one' 'two' ]; WRAPPER section; PROCESS $s; END; END %] 132[% PROCESS $s WRAPPER section FOREACH s = [ 'one' 'two' ] %] 133[% BLOCK one; title = 'Block One' %]This is one[% END %] 134[% BLOCK two; title = 'Block Two' %]This is two[% END %] 135[% BLOCK section %] 136<h1>[% title %]</h1> 137<p> 138[% content %] 139</p> 140[% END %] 141-- expect -- 142<h1>Block One</h1> 143<p> 144This is one 145</p><h1>Block Two</h1> 146<p> 147This is two 148</p> 149 150-- test -- 151[% BLOCK one; title = 'Block One' %]This is one[% END %] 152[% BLOCK section %] 153<h1>[% title %]</h1> 154<p> 155[% content %] 156</p> 157[% END %] 158[% WRAPPER section -%] 159[% PROCESS one %] 160[%- END %] 161title: [% title %] 162-- expect -- 163<h1>Block One</h1> 164<p> 165This is one 166</p> 167title: Block One 168 169-- test -- 170[% title = "foo" %] 171[% WRAPPER outer title="bar" -%] 172The title is [% title %] 173[%- END -%] 174[% BLOCK outer -%] 175outer [[% title %]]: [% content %] 176[%- END %] 177-- expect -- 178outer [bar]: The title is foo 179 180-- test-- 181[% BLOCK a; "<a>$content</a>"; END; 182 BLOCK b; "<b>$content</b>"; END; 183 BLOCK c; "<c>$content</c>"; END; 184 WRAPPER a + b + c; 'FOO'; END; 185%] 186-- expect -- 187<a><b><c>FOO</c></b></a> 188 189-- stop -- 190# This next text demonstrates a limitation in the parser 191# http://tt2.org/pipermail/templates/2006-January/008197.html 192 193-- test-- 194[% BLOCK a; "<a>$content</a>"; END; 195 BLOCK b; "<b>$content</b>"; END; 196 BLOCK c; "<c>$content</c>"; END; 197 A='a'; 198 B='b'; 199 C='c'; 200 WRAPPER $A + $B + $C; 'BAR'; END; 201%] 202-- expect -- 203<a><b><c>BAR</c></b></a> 204 205