[Templates] TT2 syntax checker or lint?
darren chamberlain
dlc@users.sourceforge.net
Wed, 6 Mar 2002 15:47:16 -0500
Quoting Perrin Harkins <perrin@elem.com> [Mar 06, 2002 15:22]:
> The original idea of having a "ttlint" is a really cool one
> though. I wonder if there's a way to just re-purpose the
> parser somehow, or if this would need to be a separate one. It
> could be much slower and simpler than the real TT parser, if
> it's just looking for stuff like unclosed IF tags.
If you are running with either COMPILE_DIR or COMPILE_EXT, you
can do:
perl -e 'require "compiled_template.tt2"'
and, if it passes, it has no errors. Here:
#!/usr/bin/env perl
#file ttlint
use Template::Config;
my %params = (
COMPILE_DIR => "/tmp",
ABSOLUTE => 1,
); # set these
my $t = Template::Config->service(\%params);
# Make sure the version in COMPILE_DIR is current...
for (@ARGV) {
# Assumes each element is a full path, or do some fanciness
# with Cwd and File::Spec to get the full path
$t->process($_, {});
}
# Now require them all
for (@ARGV) {
eval {
require "$_";
};
if ($@) {
warn "$_ had issues: $@\n";
}
}
Call it as ./ttlint /path/to/file/1 /path/to/file/2
Tweak to suit.
(darren)
--
It is impossible to experience one's death objectively and still
carry a tune.
-- Woody Allen