[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] Template Toolkit MACRO



Hey Dave --

I'm hoping you can help me with an apparent MACRO problem in the Perl Mongers bin/build script.

When I run the script, it runs for all source files creating all the destination files, but then this source:

Select a continent:
[% link_to("/groups/africa.html", "Africa") %],
[% link_to("/groups/asia.html", "Asia") %],
[% link_to("/groups/central_america.html", "Central America") %],
[% link_to("/groups/europe.html", "Europe") %],
[% link_to("/groups/non_geographical.html", "Non-geographical") %],
[% link_to("/groups/north_america.html", "North America") %],
[% link_to("/groups/oceania.html", "Oceania") %],
[% link_to("/groups/south_america.html", "South America") %].

Turns into this output:

Select a continent:
, , , , , , , .

So it looks like TT is not finding link_to(). link_to() lives in lib/layout like so:

[% MACRO link_to(url, text) BLOCK %]
<a href="[% PROCESS relative %]">[% text %]</a>
[% END %]

and the bin/build script below uses INCLUDE_PATH 'lib', and the source file in question starts with

[% WRAPPER layout title = "Perl Mongers: User groups" %]

So shouldn't link_to() work and kick out URLs? It concerns me that when I rename the link_to() to anything else, TT still doesn't complain...

How do I debug this thing? DEBUG_ALL => 1 in the Template->new() call doesn't seem to do anything...

I'm not used to TT macros...

Thanks,

j



bin/build:
--------------------------
#!/usr/bin/perl -w

use strict;
use File::Copy;
use File::Find::Rule;
use File::Path;
use File::Spec::Functions qw(splitpath);
use Template;

my $tt = Template->new({
 POST_CHOMP => 1,
 PRE_CHOMP => 1,
 TRIM => 1,
 EVAL_PERL => 1 ,
 INCLUDE_PATH => ['.', 'lib', 'src'],
});

my $source = 'src';
my $destination = 'www';
my $parms;

my $rule = File::Find::Rule->new;
$rule->or(
 $rule->new->directory->name('.svn')->prune->discard,
 $rule->new
);
my @files = $rule->file()->name(qr/^.[^~]+$/)->in($source);

foreach my $file (@files) {
print STDERR $file, "\n";
 my $destfile = $file;
 $destfile =~ s/^$source/$destination/;
 my($volume, $directories, $filepart) = splitpath($destfile);
 mkpath $directories;
 warn "$file -> $destfile\n";

 if ($file =~ /\.png$/) {
   copy($file, $destfile);
 } else {
   $tt->process($file, $parms, $destfile) || die $tt->error;
 }
}