summaryrefslogtreecommitdiffstats
path: root/globals.pl
diff options
context:
space:
mode:
authormyk%mozilla.org <>2002-02-03 18:27:02 +0100
committermyk%mozilla.org <>2002-02-03 18:27:02 +0100
commit0742929eb43ee5e3e67b59a9159ca416cbd0d4be (patch)
tree8a3a47b645da6d0a41e5d7220b71ec0ff1098757 /globals.pl
parentb5aa3e4f8caa39de11efc8b8c28eeaf09f4cc9db (diff)
downloadbugzilla-0742929eb43ee5e3e67b59a9159ca416cbd0d4be.tar.gz
bugzilla-0742929eb43ee5e3e67b59a9159ca416cbd0d4be.tar.xz
Fix for bug 121747: Stops every script before it does anything else if Bugzilla is currently shut down. Also adds global template
instantiation code to globals.pl. Patch by Myk Melez <myk@mozilla.org>. r=gerv,kiko
Diffstat (limited to 'globals.pl')
-rw-r--r--globals.pl92
1 files changed, 92 insertions, 0 deletions
diff --git a/globals.pl b/globals.pl
index 86478b03c..cc05ae345 100644
--- a/globals.pl
+++ b/globals.pl
@@ -53,6 +53,8 @@ sub globals_pl_sillyness {
$zz = @main::prodmaxvotes;
$zz = $main::superusergroupset;
$zz = $main::userid;
+ $zz = $main::template;
+ $zz = $main::vars;
}
#
@@ -1549,4 +1551,94 @@ sub trim {
return $str;
}
+###############################################################################
+# Global Templatization Code
+
+# Use the template toolkit (http://www.template-toolkit.org/) to generate
+# the user interface using templates in the "template/" subdirectory.
+use Template;
+
+# Create the global template object that processes templates and specify
+# configuration parameters that apply to all templates processed in this script.
+$::template = Template->new(
+ {
+ # Colon-separated list of directories containing templates.
+ INCLUDE_PATH => "template/custom:template/default" ,
+
+ # Allow templates to be specified with relative paths.
+ RELATIVE => 1 ,
+
+ # Remove white-space before template directives (PRE_CHOMP) and at the
+ # beginning and end of templates and template blocks (TRIM) for better
+ # looking, more compact content. Use the plus sign at the beginning
+ # of directives to maintain white space (i.e. [%+ DIRECTIVE %]).
+ PRE_CHOMP => 1 ,
+ TRIM => 1 ,
+
+ # Functions for processing text within templates in various ways.
+ FILTERS =>
+ {
+ # Render text in strike-through style.
+ strike => sub { return "<strike>" . $_[0] . "</strike>" } ,
+ } ,
+ }
+);
+
+# Use the Toolkit Template's Stash module to add utility pseudo-methods
+# to template variables.
+use Template::Stash;
+
+# Add "contains***" methods to list variables that search for one or more
+# items in a list and return boolean values representing whether or not
+# one/all/any item(s) were found.
+$Template::Stash::LIST_OPS->{ contains } =
+ sub {
+ my ($list, $item) = @_;
+ return grep($_ eq $item, @$list);
+ };
+
+$Template::Stash::LIST_OPS->{ containsany } =
+ sub {
+ my ($list, $items) = @_;
+ foreach my $item (@$items) {
+ return 1 if grep($_ eq $item, @$list);
+ }
+ return 0;
+ };
+
+# Add a "substr" method to the Template Toolkit's "scalar" object
+# that returns a substring of a string.
+$Template::Stash::SCALAR_OPS->{ substr } =
+ sub {
+ my ($scalar, $offset, $length) = @_;
+ return substr($scalar, $offset, $length);
+ };
+
+# Add a "truncate" method to the Template Toolkit's "scalar" object
+# that truncates a string to a certain length.
+$Template::Stash::SCALAR_OPS->{ truncate } =
+ sub {
+ my ($string, $length, $ellipsis) = @_;
+ $ellipsis ||= "";
+
+ return $string if !$length || length($string) <= $length;
+
+ my $strlen = $length - length($ellipsis);
+ my $newstr = substr($string, 0, $strlen) . $ellipsis;
+ return $newstr;
+ };
+
+# Define the global variables and functions that will be passed to the UI
+# template. Additional values may be added to this hash before templates
+# are processed.
+$::vars =
+ {
+ # Function for retrieving global parameters.
+ 'Param' => \&Param ,
+
+ # Function for processing global parameters that contain references
+ # to other global parameters.
+ 'PerformSubsts' => \&PerformSubsts ,
+ };
+
1;