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