Re: [Maypole] .tt extension on templates?

From: Dave Howorth (dhoworth at mrc-lmb.cam.ac.uk)
Date: Mon Sep 20 2004 - 16:23:22 BST


I wrote:
> I'll give it a go as soon as it makes it to the top of my
> next-thing-to-code list.

OK, it works! Now my Maypole templates are in colour :)
The actual code I added in my class was:

sub template {
     my $r = shift;
     my $t = $r->_template_accessor(@_);
     my $ext = $r->{config}->{template_extension};
     return $ext ? $t . $ext : $t;
}

QD1->config->{template_extension} = '.tt';

IMHO, I think it would be nice to have the relevant line or two in
Maypole::View::TT

I wrote a little script to change the names of all the templates and
also all references to files in INCLUDE and PROCESS directives. It makes
a new directory and keeps all the old files unchanged, for insurance. It
will need hacking if you have any more sophisticated templates with
other directives. (For all I know there are some lurking in the factory
directory that I haven't found, but I'm sure they'll announce themselves
in due course ...)

#!/usr/bin/perl
use strict;
use warnings;

my $dir = $ARGV[0];
    $dir =~ s/\/$//;
my $ext = '.tt';
die "Usage: $0 directory-name\n" unless $dir;
opendir DIR, $dir or die "Can't read directory $dir;";
mkdir "$dir$ext" or die "Can't create directory $dir$ext;";
while (my $file = readdir DIR)
{
  next if $file eq '.';
  next if $file eq '..';
  print "$file\n";

  open IN, '<', "$dir/$file" or die "Can't read $dir/$file";
  open OUT, '>', "$dir$ext/$file$ext" or die "Can't create $dir/$file$ext";

  while (my $line = <IN>)
  {
   $line =~ s/(\b(INCLUDE|PROCESS)\s+\S+?(?=\s|;))/$1$ext/g;
   print OUT $line;
  }

  close OUT;
  close IN;
}

rename $dir, "$dir.old";
rename "$dir$ext", $dir;

Just type:
./incpro.pl factory/

or whatever

Cheers, Dave

_______________________________________________
maypole mailing list
maypole at lists.netthink.co.uk
http://lists.netthink.co.uk/listinfo/maypole



This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:56 GMT