X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FGitalist.git;a=blobdiff_plain;f=local-lib5%2Fbin%2Ftpage;fp=local-lib5%2Fbin%2Ftpage;h=ef912b63df1dc079cea548d35294bdfd89d5f69b;hp=0000000000000000000000000000000000000000;hb=3fea05b9fbf95091f4522528b9980a33e0235603;hpb=af746827daa7a8feccee889e1d12ebc74cc9201e diff --git a/local-lib5/bin/tpage b/local-lib5/bin/tpage new file mode 100755 index 0000000..ef912b6 --- /dev/null +++ b/local-lib5/bin/tpage @@ -0,0 +1,257 @@ +#!/usr/bin/perl -w + +eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}' + if 0; # not running under some shell +#======================================================================== +# +# tpage +# +# DESCRIPTION +# Script for processing and rendering a template document using the +# Perl Template Toolkit. +# +# AUTHOR +# Andy Wardley +# +# COPYRIGHT +# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved. +# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd. +# +# This module is free software; you can redistribute it and/or +# modify it under the same terms as Perl itself. +# +#------------------------------------------------------------------------ +# +# $Id: tpage 1068 2007-04-27 13:33:25Z abw $ +# +#======================================================================== + +use strict; +use Template; +use AppConfig; + +my $NAME = "tpage"; +my $VERSION = 2.70; +my $HOME = $ENV{ HOME } || ''; +my $RCFILE = $ENV{"\U${NAME}rc"} || "$HOME/.${NAME}rc"; +my $TTMODULE = 'Template'; + +# read .tpagerc file and any command line arguments +my $config = read_config($RCFILE); + +# unshift any perl5lib directories onto front of INC +unshift(@INC, @{ $config->perl5lib }); + +# get all template_* options from the config and fold keys to UPPER CASE +my %ttopts = $config->varlist('^template_', 1); +my $ttmodule = delete($ttopts{ module }); +my $ucttopts = { + map { my $v = $ttopts{ $_ }; defined $v ? (uc $_, $v) : () } + keys %ttopts, +}; + +# load custom template module +if ($ttmodule) { + my $ttpkg = $ttmodule; + $ttpkg =~ s[::][/]g; + $ttpkg .= '.pm'; + require $ttpkg; +} +else { + $ttmodule = $TTMODULE; +} + +# add current directory to INCLUDE_PATH +unshift(@{ $ucttopts->{ INCLUDE_PATH } }, '.'); + +# read from STDIN if no files specified +push(@ARGV, '-') unless @ARGV; + +my $template = $ttmodule->new($ucttopts) + || die $ttmodule->error(); + +# process each input file +foreach my $file (@ARGV) { + $file = \*STDIN if $file eq '-'; + $template->process($file) + || die $template->error(); +} + + +sub read_config { + my $file = shift; + + my $config = AppConfig->new( + { + ERROR => sub { die(@_, "\ntry `$NAME --help'\n") } + }, + 'help|h' => { ACTION => \&help }, + 'template_absolute|absolute' => { DEFAULT => 1 }, + 'template_relative|relative' => { DEFAULT => 1 }, + 'template_module|module=s', + 'template_anycase|anycase', + 'template_eval_perl|eval_perl', + 'template_load_perl|load_perl', + 'template_interpolate|interpolate', + 'template_pre_chomp|pre_chomp|prechomp', + 'template_post_chomp|post_chomp|postchomp', + 'template_trim|trim', + 'template_variables|variables|define=s%', + 'template_include_path|include_path|include|I=s@', + 'template_pre_process|pre_process|preprocess=s@', + 'template_post_process|post_process|postprocess=s@', + 'template_process|process=s', + 'template_wrapper|wrapper=s', + 'template_recursion|recursion', + 'template_expose_blocks|expose_blocks', + 'template_default|default=s', + 'template_error|error=s', + 'template_debug|debug=s', + 'template_start_tag|start_tag|starttag=s', + 'template_end_tag|end_tag|endtag=s', + 'template_tag_style|tag_style|tagstyle=s', + 'template_compile_ext|compile_ext=s', + 'template_compile_dir|compile_dir=s', + 'template_plugin_base|plugin_base|pluginbase=s@', + 'perl5lib|perllib=s@' + ); + + # add the 'file' option now that we have a $config object that we + # can reference in a closure + $config->define( + 'file|f=s@' => { + EXPAND => AppConfig::EXPAND_ALL, + ACTION => sub { + my ($state, $item, $file) = @_; + $file = $state->cfg . "/$file" + unless $file =~ /^[\.\/]|(?:\w:)/; + $config->file($file) } + } + ); + + # process main config file, then command line args + $config->file($file) if -f $file; + $config->args(); + return $config; +} + + +sub help { + print< script is a simple wrapper around the Template Toolkit processor. +Files specified by name on the command line are processed in turn by the +template processor and the resulting output is sent to STDOUT and can be +redirected accordingly. e.g. + + tpage myfile > myfile.out + tpage header myfile footer > myfile.html + +If no file names are specified on the command line then B will read +STDIN for input. + +The C<--define> option can be used to set the values of template variables. +e.g. + + tpage --define author="Andy Wardley" skeleton.pm > MyModule.pm + +See L