summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Template.pm
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2017-06-23 20:34:55 +0200
committerGitHub <noreply@github.com>2017-06-23 20:34:55 +0200
commit8630521c3151c652143673b80fb7f1cc501687a7 (patch)
tree47bf47da68d4a519884c91e0cd0f808b899ee2b1 /Bugzilla/Template.pm
parentdf042aa77951fa69ea59c1ced9feded43ba3ae6c (diff)
downloadbugzilla-8630521c3151c652143673b80fb7f1cc501687a7.tar.gz
bugzilla-8630521c3151c652143673b80fb7f1cc501687a7.tar.xz
Bug 1361890 - Fix problems with current js and css concatenation
Diffstat (limited to 'Bugzilla/Template.pm')
-rw-r--r--Bugzilla/Template.pm153
1 files changed, 19 insertions, 134 deletions
diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm
index 5bef599d4..d72feea67 100644
--- a/Bugzilla/Template.pm
+++ b/Bugzilla/Template.pm
@@ -401,7 +401,13 @@ sub css_files {
unshift @requested_css, "skins/yui.css" unless $no_yui;
- my @css_sets = map { _css_link_set($_) } @requested_css;
+ my @css_sets = map { _css_link_set($_) } sort {
+ my $first_a = $a =~ m!js/jquery!;
+ my $first_b = $b =~ m!js/jquery!;
+ return -1 if $first_a && !$first_b;
+ return 1 if !$first_a && $first_b;
+ return 0;
+ } @requested_css;
my %by_type = (standard => [], skin => [], custom => []);
foreach my $set (@css_sets) {
@@ -410,18 +416,13 @@ sub css_files {
}
}
- # build unified
- $by_type{unified_standard_skin} = _concatenate_css($by_type{standard},
- $by_type{skin});
- $by_type{unified_custom} = _concatenate_css($by_type{custom});
-
return \%by_type;
}
sub _css_link_set {
my ($file_name) = @_;
- my %set = (standard => mtime_filter($file_name));
+ my %set = (standard => $file_name);
# We use (?:^|/) to allow Extensions to use the skins system if they want.
if ($file_name !~ m{(?:^|/)skins/standard/}) {
@@ -432,127 +433,19 @@ sub _css_link_set {
my $cgi_path = bz_locations()->{'cgi_path'};
my $skin_file_name = $file_name;
$skin_file_name =~ s{(?:^|/)skins/standard/}{skins/contrib/$skin/};
- if (my $mtime = _mtime("$cgi_path/$skin_file_name")) {
- $set{skin} = mtime_filter($skin_file_name, $mtime);
+ if (-f "$cgi_path/$skin_file_name") {
+ $set{skin} = $skin_file_name;
}
my $custom_file_name = $file_name;
$custom_file_name =~ s{(?:^|/)skins/standard/}{skins/custom/};
- if (my $custom_mtime = _mtime("$cgi_path/$custom_file_name")) {
- $set{custom} = mtime_filter($custom_file_name, $custom_mtime);
+ if (-f "$cgi_path/$custom_file_name") {
+ $set{custom} = $custom_file_name;
}
return \%set;
}
-sub _concatenate_css {
- my @sources = map { @$_ } @_;
- return unless @sources;
-
- my %files =
- map {
- (my $file = $_) =~ s/(^[^\?]+)\?.+/$1/;
- $_ => $file;
- } @sources;
-
- my $cgi_path = bz_locations()->{cgi_path};
- my $skins_path = bz_locations()->{assetsdir};
-
- # build minified files
- my @minified;
- foreach my $source (@sources) {
- next unless -e "$cgi_path/$files{$source}";
- my $file = $skins_path . '/' . md5_hex($source) . '.css';
- if (!-e $file) {
- my $content = read_file("$cgi_path/$files{$source}");
-
- # minify
- $content =~ s{/\*.*?\*/}{}sg; # comments
- $content =~ s{(^\s+|\s+$)}{}mg; # leading/trailing whitespace
- $content =~ s{\n}{}g; # single line
-
- # rewrite urls
- $content =~ s{url\(([^\)]+)\)}{_css_url_rewrite($source, $1)}eig;
-
- write_file($file, "/* $files{$source} */\n" . $content . "\n");
- }
- push @minified, $file;
- }
-
- # concat files
- my $file = $skins_path . '/' . md5_hex(join(' ', @sources)) . '.css';
- if (!-e $file) {
- my $content = '';
- foreach my $source (@minified) {
- $content .= read_file($source);
- }
- write_file($file, $content);
- }
-
- $file =~ s/^\Q$cgi_path\E\///o;
- return mtime_filter($file);
-}
-
-sub _css_url_rewrite {
- my ($source, $url) = @_;
- # rewrite relative urls as the unified stylesheet lives in a different
- # directory from the source
- $url =~ s/(^['"]|['"]$)//g;
- if (substr($url, 0, 1) eq '/' || substr($url, 0, 5) eq 'data:') {
- return 'url(' . $url . ')';
- }
- return 'url(../../' . dirname($source) . '/' . $url . ')';
-}
-
-sub _concatenate_js {
- return @_ unless CONCATENATE_ASSETS;
- my ($sources) = @_;
- return [] unless $sources;
- $sources = ref($sources) ? $sources : [ $sources ];
-
- my %files =
- map {
- (my $file = $_) =~ s/(^[^\?]+)\?.+/$1/;
- $_ => $file;
- } @$sources;
-
- my $cgi_path = bz_locations()->{cgi_path};
- my $skins_path = bz_locations()->{assetsdir};
-
- # build minified files
- my @minified;
- foreach my $source (@$sources) {
- next unless -e "$cgi_path/$files{$source}";
- my $file = $skins_path . '/' . md5_hex($source) . '.js';
- if (!-e $file) {
- my $content = read_file("$cgi_path/$files{$source}");
-
- # minimal minification
- $content =~ s#/\*.*?\*/##sg; # block comments
- $content =~ s#(^ +| +$)##gm; # leading/trailing spaces
- $content =~ s#^//.+$##gm; # single line comments
- $content =~ s#\n{2,}#\n#g; # blank lines
- $content =~ s#(^\s+|\s+$)##g; # whitespace at the start/end of file
-
- write_file($file, "/* $files{$source} */\n" . $content . "\n");
- }
- push @minified, $file;
- }
-
- # concat files
- my $file = $skins_path . '/' . md5_hex(join(' ', @$sources)) . '.js';
- if (!-e $file) {
- my $content = '';
- foreach my $source (@minified) {
- $content .= read_file($source);
- }
- write_file($file, $content);
- }
-
- $file =~ s/^\Q$cgi_path\E\///o;
- return [ $file ];
-}
-
# YUI dependency resolution
sub yui_resolve_deps {
my ($yui, $yui_deps) = @_;
@@ -900,7 +793,7 @@ sub create {
html_light => \&Bugzilla::Util::html_light_quote,
email => \&Bugzilla::Util::email_filter,
-
+
mtime => \&mtime_filter,
# iCalendar contentline filter
@@ -983,19 +876,12 @@ sub create {
# Function for retrieving global parameters.
'Param' => sub { return Bugzilla->params->{$_[0]}; },
- 'bugzilla_version' => sub {
- my $version = Bugzilla->VERSION;
- if (my @ver = $version =~ /^(\d{4})(\d{2})(\d{2})\.(\d+)$/s) {
- if ($ver[3] eq '1') {
- return join('.', @ver[0,1,2]);
- }
- else {
- return join('.', @ver);
- }
- }
- else {
- return $version;
- }
+ asset_file => sub {
+ return Bugzilla->asset_manager->asset_file($_[0]);
+ },
+
+ asset_files => sub {
+ return Bugzilla->asset_manager->asset_files(@{ $_[0] });
},
json_encode => sub {
@@ -1091,7 +977,6 @@ sub create {
'css_files' => \&css_files,
yui_resolve_deps => \&yui_resolve_deps,
- concatenate_js => \&_concatenate_js,
# Whether or not keywords are enabled, in this Bugzilla.
'use_keywords' => sub { return Bugzilla::Keyword->any_exist; },