[Templates-cvs] cvs commit: TT3/t compiler.t
cvs@template-toolkit.org
cvs@template-toolkit.org
Wed, 01 Dec 2004 11:06:30 +0000
cvs 04/12/01 11:06:30
Modified: t compiler.t
Log:
* changed tagset package and added a custom tag
Revision Changes Path
1.16 +48 -6 TT3/t/compiler.t
Index: compiler.t
===================================================================
RCS file: /template-toolkit/TT3/t/compiler.t,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- compiler.t 2004/11/29 12:21:56 1.15
+++ compiler.t 2004/12/01 11:06:30 1.16
@@ -9,7 +9,7 @@
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
-# $Id: compiler.t,v 1.15 2004/11/29 12:21:56 abw Exp $
+# $Id: compiler.t,v 1.16 2004/12/01 11:06:30 abw Exp $
#
#========================================================================
@@ -17,15 +17,16 @@
use warnings;
use lib qw( ./lib ../lib );
-use Template::Tagset::TT;
+use Template::TT3::Tagset;
use Template::Compiler;
use Template::Context;
use Template::Resource::Variable;
use Template::Resources;
-use Template::Test tests => 27, import => ':all';
+use Template::Test tests => 21, import => ':all';
my $DEBUG =
$Template::Compiler::DEBUG =
+$Template::Tagset::DEBUG =
grep(/^--?d(ebug)?/, @ARGV);
@@ -52,7 +53,7 @@
#------------------------------------------------------------------------
my $pkg = 'Template::Compiler';
-my $compiler = $pkg->new( tagset => 'Template::Tagset::TT',
+my $compiler = $pkg->new( tagset => 'Template::TT3::Tagset',
interpolate => 1 ) || die $pkg->error();
ok( $compiler, 'created a compiler' );
@@ -257,7 +258,14 @@
# create compiler
#------------------------------------------------------------------------
-$compiler = $pkg->new( tagset => 'Template::Tagset::TT' )
+my $imgtag = Template::Tag->new({
+ start => qr/<(image|img)/,
+ end => qr/\/?>/,
+ parse => \&parse_image,
+});
+
+$compiler = $pkg->new( tagset => 'Template::TT3::Tagset',
+ tags => [ image => $imgtag ])
|| die $pkg->error();
ok( $compiler, 'created a compiler' );
@@ -285,8 +293,27 @@
return $result;
}
-print "dump: ", $context->dump(), "\n" if $DEBUG;
+sub parse_image {
+ my ($self, $text, $handler, $match) = @_;
+ my %attr;
+
+ if ($$text =~ / \G : (.*?) (?=$match->{ end }) /cgx) {
+ # <img:foo.gif/>
+ $attr{ src } = $1;
+ }
+ else {
+ # <img src="foo.gif"/>
+ while ($$text =~ / \G \s* (\w+)="(.*?)" /cgx) {
+ $attr{ $1 } = $2;
+ }
+ }
+
+ $handler->text("<img src=\"$attr{src}\" width=\"20\" height=\"30\" />");
+}
+
+#print "dump: ", $context->dump(), "\n" if $DEBUG;
+
__END__
-- test set --
@@ -349,6 +376,21 @@
-- expect --
nothing really matters
+-- start --
+-- test img tag --
+before <img src="foo.gif"/> after
+-- expect --
+before <img src="foo.gif" width="20" height="30" /> after
+
+-- test image tag --
+before <image src="bar.gif"/> after
+-- expect --
+before <img src="bar.gif" width="20" height="30" /> after
+
+-- test image: tag --
+before <image:baz.gif/> after
+-- expect --
+before <img src="baz.gif" width="20" height="30" /> after
__END__