~ubuntu-branches/ubuntu/oneiric/bugzilla/oneiric

« back to all changes in this revision

Viewing changes to t/Support/Templates.pm

  • Committer: Bazaar Package Importer
  • Author(s): Raphael Bossek
  • Date: 2008-06-27 22:34:34 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080627223434-0ib57vstn43bb4a3
Tags: 3.0.4.1-1
* Update of French, Russian and German translations. (closes: #488251)
* Added Bulgarian and Belarusian translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- Mode: perl; indent-tabs-mode: nil -*-
2
 
#
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/
7
 
#
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.
12
 
#
13
 
# The Original Code are the Bugzilla tests.
14
 
#
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
18
 
# Rights Reserved.
19
 
#
20
 
# Contributor(s): Jacob Steenhagen <jake@bugzilla.org>
21
 
#                 David D. Kilzer <ddkilzer@kilzer.net>
22
 
#                 Tobias Burnus <burnus@net-b.de>
23
 
#
24
 
 
25
 
package Support::Templates;
26
 
 
27
 
use strict;
28
 
 
29
 
use lib 't';
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);
36
 
 
37
 
use Support::Files;
38
 
 
39
 
use File::Find;
40
 
use File::Spec;
41
 
 
42
 
# The available template languages
43
 
@languages = ();
44
 
 
45
 
# The colon separated includepath per language
46
 
%include_path = ();
47
 
 
48
 
# All include paths
49
 
@include_paths = ();
50
 
 
51
 
# Files which are referenced in the cgi files
52
 
@referenced_files = ();
53
 
 
54
 
# All files sorted by include_path
55
 
%actual_files = ();
56
 
 
57
 
# total number of actual_files
58
 
$num_actual_files = 0;
59
 
 
60
 
# Scan for the template available languages and include paths
61
 
{
62
 
    opendir(DIR, "template") || die "Can't open  'template': $!";
63
 
    my @files = grep { /^[a-z-]+$/i } readdir(DIR);
64
 
    closedir DIR;
65
 
 
66
 
    foreach my $langdir (@files) {
67
 
        next if($langdir =~ /^CVS$/i);
68
 
 
69
 
        my $path = File::Spec->catdir('template', $langdir, 'custom');
70
 
        my @dirs = ();
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);
76
 
 
77
 
        next if(scalar(@dirs) == 0);
78
 
        push(@languages, $langdir);
79
 
        push(@include_paths, @dirs);
80
 
        $include_path{$langdir} = join(":",@dirs);
81
 
    }
82
 
}
83
 
 
84
 
 
85
 
my @files;
86
 
 
87
 
# Local subroutine used with File::Find
88
 
sub find_templates {
89
 
    # Prune CVS directories
90
 
    if (-d $_ && $_ eq 'CVS') {
91
 
        $File::Find::prune = 1;
92
 
        return;
93
 
    }
94
 
 
95
 
    # Only include files ending in '.tmpl'
96
 
    if (-f $_ && $_ =~ m/\.tmpl$/i) {
97
 
        my $filename;
98
 
        my $local_dir = File::Spec->abs2rel($File::Find::dir,
99
 
                                            $File::Find::topdir);
100
 
 
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 ".");
104
 
 
105
 
        if ($local_dir) {
106
 
            $filename = File::Spec->catfile($local_dir, $_);
107
 
        } else {
108
 
            $filename = $_;
109
 
        }
110
 
 
111
 
        push(@files, $filename);
112
 
    }
113
 
}
114
 
 
115
 
# Scan the given template include path for templates
116
 
sub find_actual_files {
117
 
  my $include_path = $_[0];
118
 
  @files = ();
119
 
  find(\&find_templates, $include_path);
120
 
  return @files;
121
 
}
122
 
 
123
 
 
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}});
127
 
}
128
 
 
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.
131
 
my %seen;
132
 
 
133
 
foreach my $file (@Support::Files::testitems) {
134
 
    open (FILE, $file);
135
 
    my @lines = <FILE>;
136
 
    close (FILE);
137
 
    foreach my $line (@lines) {
138
 
        if ($line =~ m/template->process\(\"(.+?)\", .+?\)/) {
139
 
            my $template = $1;
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;
146
 
        }
147
 
    }
148
 
}
149
 
 
150
 
1;