RE: [htmltmpl] Trimming whitespace
Brought to you by:
samtregar
From: Paulsen, B. <BPa...@le...> - 2003-02-11 21:17:41
|
One other advantage of doing this as a filter function. Any updates to the function can be done independently of Sam's release of H::T (provide that it's in a separate package) Brian -----Original Message----- From: Drew Taylor [mailto:dr...@dr...] Sent: Tuesday, February 11, 2003 4:08 PM To: Paulsen, Brian Cc: htm...@li... Subject: RE: [htmltmpl] Trimming whitespace I'm coming from the TT world, where this is just an option to new(). I get all kinds of useful options to make the results look prettier: my %opts = ( TRIM => 1, PRE_CHOMP => 1, POST_CHOMP => 1, ); $tt = Template->new(%opts); From http://www.template-toolkit.org/docs/default/Manual/Config.html >PRE_CHOMP, POST_CHOMP > >Anything outside a directive tag is considered plain text and is >generally >passed through unaltered (but see the INTERPOLATE option). This includes >all whitespace and newlines characters surrounding directive tags. >Directives that don't generate any output will leave gaps in the output >document. That's what I want - a simple config option. If this adds a filter behind the scenes I don't care. No, it doesn't matter much to the resulting HTML. But nicely formatted & spaced HTML makes it easier for me when there's a problem and I'm trying to find it. Yes, I create my H:T object in a centralized place and could easily add a filter, but that's not the point. :-) Drew At 03:27 PM 2/11/03 -0500, Paulsen, Brian wrote: >I'm still at a loss why a simple filter function couldn't do this work. > >Perhaps what we need is people to contribute filter functions to do >these kinds of things. > >Brian > >-----Original Message----- >From: Jody Biggs [mailto:big...@ya...] >Sent: Tuesday, February 11, 2003 3:19 PM >To: simran; Jay 'Whip' Grizzard >Cc: htm...@li... >Subject: Re: [htmltmpl] Trimming whitespace > > >hear hear! > >I've got some _extremely_ ugly templates that are outputting CSV or tab >delimited data, as they loop through data cells in each row, and have >several conditions within each row and cell... > >perhaps it would be reasonable to consider adding an option for >stripping white space out of lines which contain nothing but an >HTML::Template tag? > > - j > >--- simran <sim...@le...> wrote: > > On Tue, 2003-02-11 at 05:27, Jay 'Whip' Grizzard wrote: > > > On Fri, Feb 07, 2003 at 12:54:59PM -0500, Sam Tregar wrote: > > > > On Fri, 7 Feb 2003, Drew Taylor wrote: > > > > > > > > > Is there a way to trim the extra whitespace\newlines from the > > final output? > > > > > I didn't notice anything in the docs so I thought I'd ask > > > > > here. > > > > > > > > HTML::Clean works for some people. In general I don't let it > > bother me. > > > > It's just a few extra bytes and the browser certainly doesn't > > care. > > > > > > Problem is, sometimes the browser -does- care. There's not a > > difference > > > between "one character of whitespace" and "many characters of > > whitespace", but > > > there is a difference between those and "zero characters of > > whitespace". > > > > Agree. Also, HTML::Template is i think used in quite a wide range of > > applications - and its not uncommon (at least at my workplace) to > > encounter this templating mechanism to produce output for other > > applications (eg, XML, CSV, TXT, ...) and sometimes those > > applications do care about the number of whitespaces. > > > > > > > > > > > Me personally, I use an HTML::Template::Extension module to do it. > > Heck, > > > said module even appears to be appended to this email. Usage: use > > PACKTAGS > > > as an extension, and close some of your tags with " #>" (note the > > space) > > > instead of >. Any tags closed that way will cut off output until > > the next > > > tag in the template. (This could be trivially adjusted to just > > remove > > > whitespace, as well .. adjust _pack_tags in the obvious way). > > > > > > Incidentally, this script solves one of the two complaints I've > > > had > > about > > > HTML::Template. The other complaint? There isn't a way to > > incrementally > > > render loops, since you have to give it the entire contents of the > > loop at > > > once. It seems silly to hold several thousand iterations of data > > > in > > memory, > > > when one could just output an iteration at a time... > > > > > > Anyhoo. Enjoy. > > > > > > -jay > > > > > > ----- CUT HERE ----- > > > > > > > > > package HTML::Template::Extension::PACKTAGS; > > > > > > $VERSION = "0.01"; > > > sub Version { $VERSION; } > > > > > > use Carp; > > > use strict; > > > > > > my $classname; > > > my $parentname; > > > > > > > > > my %fields = > > > ( > > > ecp_compatibility_mode => 0, > > > ); > > > > > > > > > my @fields_req = qw//; > > > > > > > > > sub new > > > { > > > $classname = shift; > > > my $self = shift; > > > $parentname = ref($self); > > > bless $self,$classname; > > > > > > $self->_init_local(@_); > > > return $self; > > > } > > > > > > > > > sub _init_local { > > > my $self = shift; > > > my (%options) = @_; > > > > > > # Assign default options > > > while (my ($key,$value) = each(%fields)) { > > > $self->{$key} = $self->{$key} || $value; > > > } > > > > > > # Assign options > > > while (my ($key,$value) = each(%options)) { > > > $self->{$key} = $value > > > } > > > > > > # Check required params > > > foreach (@fields_req) { > > > croak "You must declare '$_' in " . ref($self) . "::new" > > > if (!defined $self->{$_}); > > > } > > > > > > $self->push_filter(); > > > } > > > > > > > > > sub push_filter { > > > my $self = shift; > > > bless($self, $classname); > > > > > > push(@{$self->{filter}}, @{$self->_get_filter()}); > > > bless($self, $parentname); > > > } > > > > > > > > > sub _get_filter { > > > my $self = shift; > > > my @ret ; > > > > > > # Sorry for this :->. I've an e-commerce project called ecp > > that > > > # use a CSTART modified syntax using html comment > > > push @ret,\&_pack_tags if ($self->{ecp_compatibility_mode}); > > > > > > # Standard CSTART syntax > > > push @ret,\&_pack_tags; > > > > > > return \@ret; > > > } > > > > > > > > > sub _pack_tags { > > > my $template = shift; > > > > > > # $template = $$template; > > > # print STDERR $template; > > > > > > $$template =~ s/\s+#>[^<]*</></g; > > > > > > return $template; > > > } > > > > > > 1; > > > > > > > > > ------------------------------------------------------- > > > This SF.NET email is sponsored by: > > > SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 > > See! > > > http://www.vasoftware.com > > > _______________________________________________ > > > Html-template-users mailing list > > > Htm...@li... > > > https://lists.sourceforge.net/lists/listinfo/html-template-users > > > > > > > > > > ------------------------------------------------------- > > This SF.NET email is sponsored by: > > SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! > > http://www.vasoftware.com > > _______________________________________________ > > Html-template-users mailing list > > Htm...@li... > > https://lists.sourceforge.net/lists/listinfo/html-template-users > > >__________________________________________________ >Do you Yahoo!? >Yahoo! Shopping - Send Flowers for Valentine's Day >http://shopping.yahoo.com > > >------------------------------------------------------- >This SF.NET email is sponsored by: >SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! >http://www.vasoftware.com >_______________________________________________ >Html-template-users mailing list Htm...@li... >https://lists.sourceforge.net/lists/listinfo/html-template-users > >----------------------------------------------------------------------- >------- >This message is intended only for the personal and confidential use of the >designated recipient(s) named above. If you are not the intended >recipient of this message you are hereby notified that any review, >dissemination, distribution or copying of this message is strictly >prohibited. This communication is for information purposes only and >should not be regarded as an offer to sell or as a solicitation of an >offer to buy any financial product, an official confirmation of any >transaction, or as an official statement of Lehman Brothers. Email >transmission cannot be guaranteed to be secure or error-free. Therefore, >we do not represent that this information is complete or accurate and it >should not be relied upon as such. All information is subject to change >without notice. > > > > >------------------------------------------------------- >This SF.NET email is sponsored by: >SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! >http://www.vasoftware.com >_______________________________________________ >Html-template-users mailing list >Htm...@li... >https://lists.sourceforge.net/lists/listinfo/html-template-users -- Drew Taylor | Web development & consulting http://www.drewtaylor.com/ | perl/mod_perl/DBI/mysql/postgres ---------------------------------------------------------------------- Netflix: DVD Rentals by mail with NO late fees or due dates! Free Trial - http://www.netflix.com/Default?mqso=36126240 ---------------------------------------------------------------------- ------------------------------------------------------------------------------ This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. |