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, "templates/webpages") || die "Can't open 'templates': $!";
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('templates', $langdir, 'custom');
71 # push(@dirs, $path) if(-d $path);
72 # $path = File::Spec->catdir('templates', $langdir, 'extension');
73 # push(@dirs, $path) if(-d $path);
74 # $path = File::Spec->catdir('templates', $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);
86 # Local subroutine used with File::Find
88 # Prune CVS directories
89 if (-d $_ && $_ eq 'CVS') {
90 $File::Find::prune = 1;
94 # Only include files ending in '.html'
95 if (-f $_ && $_ =~ m/\.html$/i) {
97 my $local_dir = File::Spec->abs2rel($File::Find::dir,
100 # File::Spec 3.13 and newer return "." instead of "" if both
101 # arguments of abs2rel() are identical.
102 $local_dir = "" if ($local_dir eq ".");
105 $filename = File::Spec->catfile($local_dir, $_);
110 push(@files, $filename);
114 # Scan the given template include path for templates
115 sub find_actual_files {
116 my $include_path = $_[0];
118 find(\&find_templates, $include_path);
122 @include_paths = qw(templates/webpages);
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\(\"(.+?)\", .+?\)/) {
139 if ($line =~ m/->parse_html_template\((['"])(.+?)\1/) {
141 # Ignore templates with $ in the name, since they're
142 # probably vars, not real files
143 next if $template =~ m/\$/;
144 next if $seen{$template};
145 push (@referenced_files, $template);
146 $seen{$template} = 1;