Commit 637b35d0 authored by myk%mozilla.org's avatar myk%mozilla.org

Fix for bug 229658: Implements a mechanism for extensions to hook into standard…

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
parent e4bdfbbf
......@@ -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
......
# -*- 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>
......@@ -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 =>
{
......
......@@ -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 $_; },
......
......@@ -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);
......
[%# 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 %]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment