1
# -*- Mode: perl; indent-tabs-mode: nil -*-
3
# The contents of this file are subject to the Mozilla Public
4
# License Version 1.1 (the "License"); you may not use this file
5
# except in compliance with the License. You may obtain a copy of
6
# the License at http://www.mozilla.org/MPL/
8
# Software distributed under the License is distributed on an "AS
9
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
# implied. See the License for the specific language governing
11
# rights and limitations under the License.
13
# The Original Code are the Bugzilla tests.
15
# The Initial Developer of the Original Code is Jacob Steenhagen.
16
# Portions created by Jacob Steenhagen are
17
# Copyright (C) 2001 Jacob Steenhagen. All
20
# Contributor(s): Jacob Steenhagen <jake@bugzilla.org>
21
# David D. Kilzer <ddkilzer@kilzer.net>
22
# Tobias Burnus <burnus@net-b.de>
25
package Support::Templates;
30
use base qw(Exporter);
31
@Support::Templates::EXPORT =
32
qw(@languages @include_paths %include_path @referenced_files
33
%actual_files $num_actual_files);
34
use vars qw(@languages @include_paths %include_path @referenced_files
35
%actual_files $num_actual_files);
42
# The available template languages
45
# The colon separated includepath per language
51
# Files which are referenced in the cgi files
52
@referenced_files = ();
54
# All files sorted by include_path
57
# total number of actual_files
58
$num_actual_files = 0;
60
# Scan for the template available languages and include paths
62
opendir(DIR, "template") || die "Can't open 'template': $!";
63
my @files = grep { /^[a-z-]+$/i } readdir(DIR);
66
foreach my $langdir (@files) {
67
next if($langdir =~ /^CVS$/i);
69
my $path = File::Spec->catdir('template', $langdir, 'custom');
71
push(@dirs, $path) if(-d $path);
72
$path = File::Spec->catdir('template', $langdir, 'extension');
73
push(@dirs, $path) if(-d $path);
74
$path = File::Spec->catdir('template', $langdir, 'default');
75
push(@dirs, $path) if(-d $path);
77
next if(scalar(@dirs) == 0);
78
push(@languages, $langdir);
79
push(@include_paths, @dirs);
80
$include_path{$langdir} = join(":",@dirs);
87
# Local subroutine used with File::Find
89
# Prune CVS directories
90
if (-d $_ && $_ eq 'CVS') {
91
$File::Find::prune = 1;
95
# Only include files ending in '.tmpl'
96
if (-f $_ && $_ =~ m/\.tmpl$/i) {
98
my $local_dir = File::Spec->abs2rel($File::Find::dir,
101
# File::Spec 3.13 and newer return "." instead of "" if both
102
# arguments of abs2rel() are identical.
103
$local_dir = "" if ($local_dir eq ".");
106
$filename = File::Spec->catfile($local_dir, $_);
111
push(@files, $filename);
115
# Scan the given template include path for templates
116
sub find_actual_files {
117
my $include_path = $_[0];
119
find(\&find_templates, $include_path);
124
foreach my $include_path (@include_paths) {
125
$actual_files{$include_path} = [ find_actual_files($include_path) ];
126
$num_actual_files += scalar(@{$actual_files{$include_path}});
129
# Scan Bugzilla's perl code looking for templates used and put them
130
# in the @referenced_files array to be used by the 004template.t test.
133
foreach my $file (@Support::Files::testitems) {
137
foreach my $line (@lines) {
138
if ($line =~ m/template->process\(\"(.+?)\", .+?\)/) {
140
# Ignore templates with $ in the name, since they're
141
# probably vars, not real files
142
next if $template =~ m/\$/;
143
next if $seen{$template};
144
push (@referenced_files, $template);
145
$seen{$template} = 1;