[Templates-cvs] cvs commit: TT3/lib/Template/TT3 Document.pm
cvs@template-toolkit.org
cvs@template-toolkit.org
Thu, 11 Dec 2003 15:09:39 +0000
cvs 03/12/11 15:09:39
Modified: lib/Template/TT3 Document.pm
Log:
* added pre_chomp() and post_chomp() methods
Revision Changes Path
1.2 +42 -5 TT3/lib/Template/TT3/Document.pm
Index: Document.pm
===================================================================
RCS file: /template-toolkit/TT3/lib/Template/TT3/Document.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Document.pm 2003/12/10 14:15:24 1.1
+++ Document.pm 2003/12/11 15:09:39 1.2
@@ -18,7 +18,7 @@
# modify it under the same terms as Perl itself.
#
# REVISION
-# $Id: Document.pm,v 1.1 2003/12/10 14:15:24 abw Exp $
+# $Id: Document.pm,v 1.2 2003/12/11 15:09:39 abw Exp $
#
#========================================================================
@@ -27,13 +27,15 @@
use strict;
use warnings;
use Template::TT3::Base;
+use Template::TT3::Constants qw( :chomp );
use vars qw( $VERSION $DEBUG $ERROR $WARNING $TAGS );
use base qw( Template::TT3::Base );
-$VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/);
+$VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
$DEBUG = 0 unless defined $DEBUG;
$ERROR = '';
+use constant TEXT => 'text';
#------------------------------------------------------------------------
@@ -91,8 +93,17 @@
$self->debug("text at line $self->{ line } [$$textref]\n") if $DEBUG;
$self->{ line } += ($$textref =~ tr/\n//);
$self->{ size } = 0;
+ my $flag;
- my $textdir = [ text => $textref ];
+ # remove leading whitespace if post_chomp flag set
+ if ($flag = delete $self->{ post_chomp }) {
+ $flag ||= CHOMP_ALL;
+ $flag = ($flag == CHOMP_COLLAPSE ? ' ' : '');
+ $self->debug("post-chomping text\n") if $DEBUG;
+ $$textref =~ s/^\s+/$flag/;
+ }
+
+ my $textdir = [ TEXT, $textref ];
push(@{ $self->{ body } }, $textdir);
# TODO ???
@@ -102,6 +113,30 @@
}
+sub pre_chomp {
+ my ($self, $flag) = @_;
+ $flag ||= CHOMP_ALL;
+ $flag = ($flag == CHOMP_COLLAPSE ? ' ' : '');
+
+ my $last = $self->{ body }->[-1] || return 1;
+ return 1 unless $last->[0] eq TEXT;
+ my $textref = $last->[-1];
+
+ $self->debug("pre-chomping text [$$textref]\n") if $DEBUG;
+ $$textref =~ s/\s+$/$flag/;
+ $self->debug("pre-chomped text [$$textref]\n") if $DEBUG;
+ return 1;
+}
+
+sub post_chomp {
+ my ($self, $flag) = @_;
+ $flag ||= 1;
+ $self->{ post_chomp } = $flag;
+}
+
+
+
+
#------------------------------------------------------------------------
# body()
# body($item)
@@ -120,12 +155,14 @@
push(@{ $self->{ body } }, $item);
# TODO ???
- $self->{ pending } = 0;
+ $self->{ pending } = 0;
+ $self->{ post_chomp } = 0;
return $item;
}
+
sub name {
my $self = shift;
return @_ ? ($self->{ name } = shift) : $self->{ name };
@@ -312,7 +349,7 @@
=head1 VERSION
-$Revision: 1.1 $
+$Revision: 1.2 $
=head1 COPYRIGHT