diff options
author | Dylan William Hardison <dylan@hardison.net> | 2017-05-17 22:19:36 +0200 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2017-05-17 23:07:31 +0200 |
commit | 3a372a916f3545d37390f692f24f7e1c4d5351b5 (patch) | |
tree | 2e0cd93ee1a897e196e86eedfa1233a37cbb2dae /Bugzilla | |
parent | 38b13ae3f1885faa0da1d0040a0dda87dc786515 (diff) | |
download | bugzilla-3a372a916f3545d37390f692f24f7e1c4d5351b5.tar.gz bugzilla-3a372a916f3545d37390f692f24f7e1c4d5351b5.tar.xz |
Bug 1363803 - Consolidate YUI js and css into one js and one css file
Diffstat (limited to 'Bugzilla')
-rw-r--r-- | Bugzilla/Install/Filesystem.pm | 77 | ||||
-rw-r--r-- | Bugzilla/Template.pm | 17 | ||||
-rw-r--r-- | Bugzilla/Util.pm | 8 |
3 files changed, 89 insertions, 13 deletions
diff --git a/Bugzilla/Install/Filesystem.pm b/Bugzilla/Install/Filesystem.pm index 7cfda8304..79eeca98e 100644 --- a/Bugzilla/Install/Filesystem.pm +++ b/Bugzilla/Install/Filesystem.pm @@ -30,6 +30,8 @@ use File::Find; use File::Path; use File::Basename; use File::Copy qw(move); +use File::Spec; +use Cwd (); use File::Slurp; use IO::File; use POSIX (); @@ -350,6 +352,36 @@ sub FILESYSTEM { "$skinsdir/contrib" => DIR_WS_SERVE, ); + my $yui_all_css = sub { + return join("\n", + map { + my $css = read_file($_); + _css_url_fix($css, $_, "skins/yui.css.list") + } read_file("skins/yui.css.list", { chomp => 1 }) + ); + }; + + my $yui_all_js = sub { + return join("\n", + map { scalar read_file($_) } read_file("js/yui.js.list", { chomp => 1 }) + ); + }; + + my $yui3_all_css = sub { + return join("\n", + map { + my $css = read_file($_); + _css_url_fix($css, $_, "skins/yui3.css.list") + } read_file("skins/yui3.css.list", { chomp => 1 }) + ); + }; + + my $yui3_all_js = sub { + return join("\n", + map { scalar read_file($_) } read_file("js/yui3.js.list", { chomp => 1 }) + ); + }; + # The name of each file, pointing at its default permissions and # default contents. my %create_files = ( @@ -361,6 +393,18 @@ sub FILESYSTEM { # or something else is not running as the webserver or root. "$datadir/mailer.testfile" => { perms => CGI_WRITE, contents => '' }, + "js/yui.js" => { perms => CGI_READ, + overwrite => 1, + contents => $yui_all_js }, + "skins/yui.css" => { perms => CGI_READ, + overwrite => 1, + contents => $yui_all_css }, + "js/yui3.js" => { perms => CGI_READ, + overwrite => 1, + contents => $yui3_all_js }, + "skins/yui3.css" => { perms => CGI_READ, + overwrite => 1, + contents => $yui3_all_css }, ); # Because checksetup controls the creation of index.html separately @@ -520,6 +564,31 @@ sub update_filesystem { _remove_dynamic_assets(); } +sub _css_url_fix { + my ($content, $from, $to) = @_; + my $from_dir = dirname(File::Spec->rel2abs($from, bz_locations()->{libpath})); + my $to_dir = dirname(File::Spec->rel2abs($to, bz_locations()->{libpath})); + + return css_url_rewrite( + $content, + sub { + my ($url) = @_; + if ( $url =~ m{^(?:/|data:)} ) { + return sprintf 'url(%s)', $url; + } + else { + my $new_url = File::Spec->abs2rel( + Cwd::realpath( + File::Spec->rel2abs( $url, $from_dir ) + ), + $to_dir + ); + return sprintf "url(%s)", $new_url; + } + } + ); +} + sub _remove_empty_css_files { my $skinsdir = bz_locations()->{'skinsdir'}; foreach my $css_file (glob("$skinsdir/custom/*.css"), @@ -623,7 +692,13 @@ sub _create_files { print "Creating $file...\n"; my $fh = IO::File->new( $file, O_WRONLY | O_CREAT, $info->{perms} ) or die "unable to write $file: $!"; - print $fh $info->{contents} if exists $info->{contents}; + my $contents = $info->{contents}; + if (defined $contents && ref($contents) eq 'CODE') { + print $fh $contents->(); + } + elsif (defined $contents) { + print $fh $contents; + } $fh->close; } } diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index b08cffbde..29b1d4a13 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -383,28 +383,23 @@ sub mtime_filter { # Set up the skin CSS cascade: # -# 1. standard/global.css -# 2. YUI CSS +# 1. YUI CSS +# 2. standard/global.css # 3. Standard Bugzilla stylesheet set # 4. Third-party "skin" stylesheet set, per user prefs # 5. Inline css passed to global/header.html.tmpl # 6. Custom Bugzilla stylesheet set sub css_files { - my ($style_urls, $yui, $yui_css) = @_; + my ($style_urls, $no_yui) = @_; # global.css belongs on every page my @requested_css = ( 'skins/standard/global.css', @$style_urls ); - my @yui_required_css; - foreach my $yui_name (@$yui) { - next if !$yui_css->{$yui_name}; - push(@yui_required_css, "js/yui/assets/skins/sam/$yui_name.css"); - } - unshift(@requested_css, @yui_required_css); - + unshift @requested_css, "skins/yui.css" unless $no_yui; + my @css_sets = map { _css_link_set($_) } @requested_css; - + my %by_type = (standard => [], skin => [], custom => []); foreach my $set (@css_sets) { foreach my $key (keys %$set) { diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm index ca8187c5f..5337ce940 100644 --- a/Bugzilla/Util.pm +++ b/Bugzilla/Util.pm @@ -18,7 +18,7 @@ use base qw(Exporter); css_class_quote html_light_quote i_am_cgi i_am_webservice correct_urlbase remote_ip validate_ip do_ssl_redirect_if_required use_attachbase - diff_arrays on_main_db + diff_arrays on_main_db css_url_rewrite trim wrap_hard wrap_comment find_wrap_point format_time validate_date validate_time datetime_from time_ago file_mod_time is_7bit_clean @@ -427,6 +427,12 @@ sub diff_arrays { return (\@removed, \@added); } +sub css_url_rewrite { + my ($content, $callback) = @_; + $content =~ s{(?<!=)url\((["']?)([^\)]+?)\1\)}{$callback->($2)}eig; + return $content; +} + sub trim { my ($str) = @_; if ($str) { |