]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Fix for bug 229658: Implements a mechanism for extensions to hook into standard Bugzi...
authormyk%mozilla.org <>
Mon, 12 Jan 2004 01:12:13 +0000 (01:12 +0000)
committermyk%mozilla.org <>
Mon, 12 Jan 2004 01:12:13 +0000 (01:12 +0000)
r=bbaetz, gerv
a=myk

Bugzilla/Template.pm
Bugzilla/Template/Plugin/Hook.pm [new file with mode: 0644]
checksetup.pl
t/004template.t
t/Support/Templates.pm
template/en/default/global/initialize.none.tmpl [new file with mode: 0644]

index d981c7a598b88a1a50724ed89ab489691095eed6..d370627d34f85f155f2622bfbe819113ad6b63d9 100644 (file)
@@ -79,6 +79,7 @@ sub getTemplateIncludePath () {
     if (not ($languages =~ /,/)) {
         return $template_include_path =
                ["$templatedir/$languages/custom",
+                "$templatedir/$languages/extension",
                 "$templatedir/$languages/default"];
     }
     my @languages       = sortAcceptLanguage($languages);
@@ -97,6 +98,7 @@ sub getTemplateIncludePath () {
     push(@usedlanguages, Param('defaultlanguage'));
     return $template_include_path =
         [map(("$templatedir/$_/custom",
+              "$templatedir/$_/extension",
               "$templatedir/$_/default"),
              @usedlanguages)];
 }
@@ -185,6 +187,9 @@ sub create {
 
         COMPILE_DIR => "$datadir/template",
 
+        # Initialize templates (f.e. by loading plugins like Hook).
+        PRE_PROCESS => "global/initialize.none.tmpl",
+
         # Functions for processing text within templates in various ways.
         # IMPORTANT!  When adding a filter here that does not override a
         # built-in filter, please also add a stub filter to checksetup.pl
diff --git a/Bugzilla/Template/Plugin/Hook.pm b/Bugzilla/Template/Plugin/Hook.pm
new file mode 100644 (file)
index 0000000..b189c5d
--- /dev/null
@@ -0,0 +1,83 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Bugzilla Bug Tracking System.
+#
+# The Initial Developer of the Original Code is Netscape Communications
+# Corporation. Portions created by Netscape are
+# Copyright (C) 1998 Netscape Communications Corporation. All
+# Rights Reserved.
+#
+# Contributor(s): Myk Melez <myk@mozilla.org>
+#
+
+package Bugzilla::Template::Plugin::Hook;
+
+use strict;
+
+use base qw(Template::Plugin);
+
+sub load {
+    my ($class, $context) = @_;
+    return $class;
+}
+
+sub new {
+    my ($class, $context) = @_;
+    return bless { _CONTEXT => $context }, $class;
+}
+
+sub process {
+    my ($self, $hook_name) = @_;
+
+    my $paths = $self->{_CONTEXT}->{LOAD_TEMPLATES}->[0]->paths;
+    my $template = $self->{_CONTEXT}->stash->{component}->{name};
+    my @hooks = ();
+
+    foreach my $path (@$paths) {
+        my @files = glob("$path/hook/$template/$hook_name/*.tmpl");
+
+        # Have to remove the templates path (INCLUDE_PATH) from the
+        # file path since the template processor auto-adds it back.
+        @files = map($_ =~ /^$path\/(.*)$/ ? $1 : {}, @files);
+
+        # Add found files to the list of hooks, but removing duplicates,
+        # which can happen when there are identical hooks or duplicate
+        # directories in the INCLUDE_PATH (the latter probably being a TT bug).
+        foreach my $file (@files) {
+            push(@hooks, $file) unless grep($file eq $_, @hooks);
+        }
+    }
+
+    my $output;
+    foreach my $hook (@hooks) {
+        $output .= $self->{_CONTEXT}->process($hook);
+    }
+    return $output;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Bugzilla::Template::Plugin::Hook
+
+=head1 DESCRIPTION
+
+Template Toolkit plugin to process hooks added into templates by extensions.
+
+=head1 SEE ALSO
+
+L<Template::Plugin>,
+L<http://bugzilla.mozilla.org/show_bug.cgi?id=229658>
index 821de1262ce1b08b9384e86d87609e241ff01339..1d62408675d53b0c8277386b3c495c26bc97646b 100755 (executable)
@@ -1046,6 +1046,8 @@ END
             next if($dir =~ /^CVS$/i);
             my $path = File::Spec->catdir($templatedir, $dir, 'custom');
             push(@templatepaths, $path) if(-d $path);
+            $path = File::Spec->catdir($templatedir, $dir, 'extension');
+            push(@templatepaths, $path) if(-d $path);
             $path = File::Spec->catdir($templatedir, $dir, 'default');
             push(@templatepaths, $path) if(-d $path);
         }
@@ -1088,6 +1090,9 @@ END
                # => $datadir/template/`pwd`/template/{en, ...}/{custom,default}
                COMPILE_DIR => "$datadir/template",
 
+               # Initialize templates (f.e. by loading plugins like Hook).
+               PRE_PROCESS => "global/initialize.none.tmpl",
+
                # These don't actually need to do anything here, just exist
                FILTERS =>
                {
index 136a74f069e062f7a18423e5862c9be5fb92a013..3b41282cc5ae5ffd446df36a838502bfefd61e9b 100644 (file)
@@ -86,6 +86,10 @@ foreach my $include_path (@include_paths) {
         # Need to define filters used in the codebase, they don't
         # actually have to function in this test, just be defined.
         # See globals.pl for the actual codebase definitions.
+
+        # Initialize templates (f.e. by loading plugins like Hook).
+        PRE_PROCESS => "global/initialize.none.tmpl",
+
         FILTERS =>
         {
             html_linebreak => sub { return $_; },
index e9056539249ae313c6cbc9ef370102c5622f771a..4403580155fc6b7029cf53c9405fe8a12a6e7084 100644 (file)
@@ -69,6 +69,8 @@ $num_actual_files = 0;
         my $path = File::Spec->catdir('template', $langdir, 'custom');
         my @dirs = ();
         push(@dirs, $path) if(-d $path);
+        $path = File::Spec->catdir('template', $langdir, 'extension');
+        push(@dirs, $path) if(-d $path);
         $path = File::Spec->catdir('template', $langdir, 'default');
         push(@dirs, $path) if(-d $path);
 
diff --git a/template/en/default/global/initialize.none.tmpl b/template/en/default/global/initialize.none.tmpl
new file mode 100644 (file)
index 0000000..93bfbe3
--- /dev/null
@@ -0,0 +1,33 @@
+[%# 1.0@bugzilla.org %]
+[%# The contents of this file are subject to the Mozilla Public
+  # License Version 1.1 (the "License"); you may not use this file
+  # except in compliance with the License. You may obtain a copy of
+  # the License at http://www.mozilla.org/MPL/
+  #
+  # Software distributed under the License is distributed on an "AS
+  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+  # implied. See the License for the specific language governing
+  # rights and limitations under the License.
+  #
+  # The Original Code is the Bugzilla Bug Tracking System.
+  #
+  # The Initial Developer of the Original Code is Netscape Communications
+  # Corporation. Portions created by Netscape are
+  # Copyright (C) 1998 Netscape Communications Corporation. All
+  # Rights Reserved.
+  #
+  # Contributor(s): Myk Melez <myk@mozilla.org>
+  #%]
+
+[%# This template is a place to put directives that should get processed
+  # every time a primary template gets processed.  Primary templates are those
+  # called from Perl code rather than from other templates via the PROCESS
+  # and INCLUDE directives.
+  #
+  # This template gets auto-processed at the beginning of primary templates
+  # via the PRE_PROCESS configuration parameter.  Note that it gets processed
+  # for non-HTML templates too, so don't put HTML-specific stuff in here;
+  # put that into header.html.tmpl instead.
+  #%]
+
+[% USE Hook %]