Thread: RE: [htmltmpl] Trimming whitespace
Brought to you by:
samtregar
From: Paulsen, B. <BPa...@le...> - 2003-02-07 17:52:47
|
I would recommend using a filter function. Something like the following: s/(<TMPL_IF [^>]*>)\s*/$1/sg; and s/\s*(<\/TMPL_IF>)/$1/sg; Those two regexes should strip out the whitespace. Brian -----Original Message----- From: Drew Taylor [mailto:dr...@dr...] Sent: Friday, February 07, 2003 12:09 PM To: htm...@li... Subject: [htmltmpl] Trimming whitespace In my templates for readability I layout things like: <TMPL_IF whatever> Print something here </TMPL_IF> Which in the resulting html gives: <<HTML; Print something here HTML 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. Drew -- 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 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. |
From: Paulsen, B. <BPa...@le...> - 2003-02-11 20:27:33
|
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. |
From: Drew T. <dr...@dr...> - 2003-02-11 21:03:40
|
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 ---------------------------------------------------------------------- |
From: Paulsen, B. <BPa...@le...> - 2003-02-11 21:13:29
|
Well, if we had people providing these filter functions, it still would be a simple config option: It might look something like this: my %opts = ( filter => [ HTML::Template::Filter::PreChomp, HTML::Template::FilterPostChomp ] ) $tt = Template->new( %opts ); 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. |
From: <m.s...@gm...> - 2003-02-11 21:43:11
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi list, sure, post filtering would be a good feature! Meanwhile I get by with pre filtering in the following way: $CLEANFILTER = sub { return if $CFG->{no_filter} == 1; my $text_ref = shift; my $h = new HTML::Clean($text_ref, 9); $h->strip({whitespace => 1, shortertags => 1, contenttype => 1, dequote => 1, comments => 1, }); $text_ref = $h->data; }; $TEMPLATE = HTML::Template->new( filename => $CFG->{map_template}, filter => $CLEANFILTER, shared_cache => 1, ); In C::A you have to define your own load_tmpl method to use this kind of filtering. You might do this anyway to associate your query and/or session object with the template in advance -- a technique which I found very keystroke-saving. This pre filtering helps to keep the cache small, too. It cleans up the whitespace I write to get an editable template, and normally in the filled in values I have not that many unnecessary space chars. As C::A takes the $tempate->output as return value of it's run-modes, post filtering could easily be applied there without touching H::T. Just my 2ct. Markus -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: Processed by Mailcrypt 3.5.6 and Gnu Privacy Guard <http://www.gnupg.org/> iD8DBQE+SW5jxxUzQSse11ARAlyrAJ9tSYtBSxMF2CmLDHF5ayxPWWCnbwCfWxif nC8XjrSsbBoDV17kx0Q9xC0= =Lluv -----END PGP SIGNATURE----- |
From: Drew T. <dr...@dr...> - 2003-02-11 21:48:36
|
Ok, I buy that. My final question is how does adding filters affect the speed? It seems like adding a couple filters that work on 20-100kb of text would start to bog down under high load. Of course, that's really a non-issue since we'll never come close to approaching a "high" load but I still wonder. :-) IMHO, as the parser is working through the document it seems it would be relatively simple to tweak the substitutions being done. Caveat: I've never tried to follow the H:T code. Drew At 04:13 PM 2/11/03 -0500, Paulsen, Brian wrote: >Well, if we had people providing these filter functions, it still would be a >simple config option: > >It might look something like this: > >my %opts = ( > filter => [ HTML::Template::Filter::PreChomp, >HTML::Template::FilterPostChomp ] >) >$tt = Template->new( %opts ); > >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. -- 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 ---------------------------------------------------------------------- |
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. |
From: Paulsen, B. <BPa...@le...> - 2003-02-11 21:51:37
|
I always use the cache options, so I've never really cared about the speed of how much the filter effects the rendering. However, this seems like it would be a fairly simple regex, and if there is something that perl does really fast, it's regexes. I would think that doing a regex on 100K of data would be incredibly fast. Brian -----Original Message----- From: Drew Taylor [mailto:dr...@dr...] Sent: Tuesday, February 11, 2003 4:53 PM To: Paulsen, Brian Cc: htm...@li... Subject: RE: [htmltmpl] Trimming whitespace Ok, I buy that. My final question is how does adding filters affect the speed? It seems like adding a couple filters that work on 20-100kb of text would start to bog down under high load. Of course, that's really a non-issue since we'll never come close to approaching a "high" load but I still wonder. :-) IMHO, as the parser is working through the document it seems it would be relatively simple to tweak the substitutions being done. Caveat: I've never tried to follow the H:T code. Drew At 04:13 PM 2/11/03 -0500, Paulsen, Brian wrote: >Well, if we had people providing these filter functions, it still would >be a simple config option: > >It might look something like this: > >my %opts = ( > filter => [ HTML::Template::Filter::PreChomp, >HTML::Template::FilterPostChomp ] >) >$tt = Template->new( %opts ); > >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. -- 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. |
From: Jay 'W. G. <elf...@lu...> - 2003-02-10 18:27:09
|
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". 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; |
From: simran <sim...@le...> - 2003-02-10 22:07:31
|
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 |
From: Jody B. <big...@ya...> - 2003-02-11 20:19:33
|
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 |