summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormyk%mozilla.org <>2004-01-12 02:12:13 +0100
committermyk%mozilla.org <>2004-01-12 02:12:13 +0100
commit637b35d05add84f71adcf7d0d3cb060b1c3e7349 (patch)
tree68ac02c31b34b0883a71c20a473a88946302be09
parente4bdfbbf265b93bbb9efa5d987ddb1d9167df28d (diff)
downloadbugzilla-637b35d05add84f71adcf7d0d3cb060b1c3e7349.tar.gz
bugzilla-637b35d05add84f71adcf7d0d3cb060b1c3e7349.tar.xz
Fix for bug 229658: Implements a mechanism for extensions to hook into standard Bugzilla templates so they can extend the Bugzilla UI without having to modify the standard templates themselves, making it easier to develop and use Bugzilla extensions.
r=bbaetz, gerv a=myk
-rw-r--r--Bugzilla/Template.pm5
-rw-r--r--Bugzilla/Template/Plugin/Hook.pm83
-rwxr-xr-xchecksetup.pl5
-rw-r--r--t/004template.t4
-rw-r--r--t/Support/Templates.pm2
-rw-r--r--template/en/default/global/initialize.none.tmpl33
6 files changed, 132 insertions, 0 deletions
diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm
index d981c7a59..d370627d3 100644
--- a/Bugzilla/Template.pm
+++ b/Bugzilla/Template.pm
@@ -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
index 000000000..b189c5d26
--- /dev/null
+++ b/Bugzilla/Template/Plugin/Hook.pm
@@ -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>
diff --git a/checksetup.pl b/checksetup.pl
index 821de1262..1d6240867 100755
--- a/checksetup.pl
+++ b/checksetup.pl
@@ -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 =>
{
diff --git a/t/004template.t b/t/004template.t
index 136a74f06..3b41282cc 100644
--- a/t/004template.t
+++ b/t/004template.t
@@ -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 $_; },
diff --git a/t/Support/Templates.pm b/t/Support/Templates.pm
index e90565392..440358015 100644
--- a/t/Support/Templates.pm
+++ b/t/Support/Templates.pm
@@ -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
index 000000000..93bfbe36f
--- /dev/null
+++ b/template/en/default/global/initialize.none.tmpl
@@ -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 %]