[Rt-commit] rt branch, 4.4/minify-css-js, created. rt-4.2.2-22-g379e193

Wallace Reis wreis at bestpractical.com
Thu Feb 13 16:55:31 EST 2014


The branch, 4.4/minify-css-js has been created
        at  379e193a46f005b15f47812fa2d888622a05d574 (commit)

- Log -----------------------------------------------------------------
commit 65c9afb194dc645f64768d323d0408301e2e66d1
Author: Wallace Reis <wreis at bestpractical.com>
Date:   Fri Feb 7 04:01:38 2014 -0800

    Minify CSS
    
    Saved around 20KB (22% reduction).

diff --git a/lib/RT/Squish/CSS.pm b/lib/RT/Squish/CSS.pm
index 5837379..ec5c8ec 100644
--- a/lib/RT/Squish/CSS.pm
+++ b/lib/RT/Squish/CSS.pm
@@ -64,6 +64,8 @@ use warnings;
 
 package RT::Squish::CSS;
 use base 'RT::Squish', 'CSS::Squish';
+use CSS::Minifier::XS ();
+
 __PACKAGE__->mk_accessors(qw/Style/);
 
 =head2 Squish
@@ -75,12 +77,18 @@ use CSS::Squish to squish css
 sub Squish {
     my $self = shift;
     my $style = $self->Style;
-    return $self->concatenate( "$style/main.css", RT->Config->Get('CSSFiles') );
+    return $self->Filter(
+      $self->concatenate( "$style/main.css", RT->Config->Get('CSSFiles') )
+    );
 }
 
 sub roots {
     map { "$_/css" } RT::Interface::Web->StaticRoots
 }
 
-1;
+sub Filter {
+    my ( $self, $content ) = @_;
+    return CSS::Minifier::XS::minify($content);
+}
 
+1;
diff --git a/sbin/rt-test-dependencies.in b/sbin/rt-test-dependencies.in
index f852cbb..17f305b 100644
--- a/sbin/rt-test-dependencies.in
+++ b/sbin/rt-test-dependencies.in
@@ -182,6 +182,7 @@ CGI::PSGI 0.12
 Class::Accessor 0.34
 Crypt::Eksblowfish
 CSS::Squish 0.06
+CSS::Minifier::XS
 Data::GUID
 Date::Extract 0.02
 Date::Manip
diff --git a/t/web/squish.t b/t/web/squish.t
index 9d1c01b..4633646 100644
--- a/t/web/squish.t
+++ b/t/web/squish.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 use RT;
-use RT::Test tests => 26;
+use RT::Test tests => undef;
 
 RT->Config->Set( DevelMode            => 0 );
 RT->Config->Set( WebDefaultStylesheet => 'aileron' );
@@ -14,9 +14,8 @@ diag "test squished files with devel mode disabled";
 
 $m->follow_link_ok( { url_regex => qr!aileron/squished-([a-f0-9]{32})\.css! },
     'follow squished css' );
-$m->content_like( qr!/\*\* End of .*?.css \*/!, 'squished css' );
-$m->content_lacks( 'counteract the titlebox',
-    'no mobile.css by default' );
+$m->content_like( qr/Copyright\s*\(c\)\s*2008\,\s*Yahoo\!/, 'squished css' );
+$m->content_lacks( 'a#fullsite', 'no mobile.css by default' );
 
 $m->back;
 my ($js_link) =
@@ -36,9 +35,8 @@ RT->AddStyleSheets( 'mobile.css' );
 $m->login;
 $m->follow_link_ok( { url_regex => qr!aileron/squished-([a-f0-9]{32})\.css! },
     'follow squished css' );
-$m->content_like( qr!/\*\* End of .*?.css \*/!, 'squished css' );
-$m->content_contains( 'counteract the titlebox',
-    'has mobile.css' );
+$m->content_like( qr/Copyright\s*\(c\)\s*2008\,\s*Yahoo\!/, 'squished css' );
+$m->content_contains( 'a#fullsite', 'has mobile.css' );
 
 $m->back;
 ($js_link) =
@@ -76,3 +74,4 @@ $m->content_contains('not-by-default.js', "found extra javascript resource");
 $m->content_contains('nottherebutwedontcare.css', "found extra css resource");
 $m->content_contains('jquery_noconflict.js', "found a default js resource");
 
+done_testing;

commit 379e193a46f005b15f47812fa2d888622a05d574
Author: Wallace Reis <wreis at bestpractical.com>
Date:   Fri Feb 7 08:48:54 2014 -0800

    Minify JS
    
    ...and remove the dep on jsmin.

diff --git a/.gitignore b/.gitignore
index 88c9700..1727608 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,9 +42,6 @@
 /config.status
 /config.log
 /config.pld
-/jsmin.c
-/jsmin
-/bin/jsmin
 /nytprof.out*
 /.prove
 *~
diff --git a/Makefile.in b/Makefile.in
index ad2b310..608a320 100755
--- a/Makefile.in
+++ b/Makefile.in
@@ -534,44 +534,3 @@ vessel-import: build-snapshot
      --log-level=info \
      --skip cpan-capitalization,cpan-mod_perl,cpan-Encode,cpan-PPI,cpan-Test-Exception-LessClever,cpan-Test-Manifest,cpan-Test-Object,cpan-Test-Pod,cpan-Test-Requires,cpan-Test-SubCalls,cpan-Test-cpan-Tester,cpan-Test-Warn --skip-all-recommends
 	mv $(VESSEL)/scripts/RT/build  $(VESSEL)/scripts/RT/build.pl
-
-JSMIN_URL = http://download.bestpractical.com/mirror/jsmin-2013-03-29.c
-JSMIN_SHA = 67dc8d73a8878f88cdaeb1a86775872eae5c3077
-
-jsmin: jsmin-checkcc jsmin-fetch jsmin-verify jsmin-confirm jsmin-build jsmin-install
-	@echo ""
-	@echo "To configure RT to use jsmin, add the following line to $(DESTDIR)$(RT_ETC_PATH)/RT_SiteConfig.pm:"
-	@echo ""
-	@echo "    Set(\$$JSMinPath, '$(DESTDIR)$(RT_BIN_PATH)/jsmin');"
-	@echo ""
-
-jsmin-checkcc:
-	@[ -n "$(CC)" ] || (echo "You don't appear to have a C compiler, please set CC and re-run configure" && exit 1)
-
-jsmin-confirm:
-	@echo "jsmin is distributed under a slightly unusual license and can't be shipped"
-	@echo "with RT.  Before configuring RT to use jsmin, please read jsmin's license"
-	@echo "below:"
-	@echo ""
-	@$(PERL) -pe 'print && exit if /^\*\// or /^#include/' jsmin.c
-	@echo ""
-	@echo "Press Enter to accept the license, or Ctrl-C to stop now."
-	@$(PERL) -e '<STDIN>'
-
-jsmin-fetch:
-	@echo ""
-	@echo "Downloading jsmin.c from $(JSMIN_URL)"
-	@echo ""
-	@$(PERL) -MLWP::Simple -e 'exit not is_success(getstore("$(JSMIN_URL)", "jsmin.c"))' \
-		|| (echo "Failed to download $(JSMIN_URL)" && exit 1)
-
-jsmin-verify:
-	@$(PERL) -MDigest::SHA -e \
-		'exit not Digest::SHA->new(1)->addfile("jsmin.c")->hexdigest eq "$(JSMIN_SHA)"' \
-		|| (echo "Verification of jsmin.c failed! Possible man in the middle?" && exit 1)
-
-jsmin-build:
-	$(CC) -o jsmin jsmin.c
-
-jsmin-install:
-	$(INSTALL) -o $(BIN_OWNER) -g $(RTGROUP) -m 0755 "jsmin" "$(DESTDIR)$(RT_BIN_PATH)/"
diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 309601d..ef98f18 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -949,16 +949,7 @@ Set(@JSFiles, qw//);
 
 =item C<$JSMinPath>
 
-Path to the jsmin binary; if specified, it will be used to minify
-C<JSFiles>.  The default, and the fallback if the binary cannot be
-found, is to simply concatenate the files.
-
-jsmin can be installed by running 'make jsmin' from the RT install
-directory, or from http://www.crockford.com/javascript/jsmin.html
-
-=cut
-
-# Set($JSMinPath, "/path/to/jsmin");
+DEPRECATED: JS files are now minified by the RT app.
 
 =item C<@CSSFiles>
 
diff --git a/lib/RT/Squish/JS.pm b/lib/RT/Squish/JS.pm
index 0c3bd3d..82b3f26 100644
--- a/lib/RT/Squish/JS.pm
+++ b/lib/RT/Squish/JS.pm
@@ -64,6 +64,7 @@ use warnings;
 
 package RT::Squish::JS;
 use base 'RT::Squish';
+use JavaScript::Minifier::XS ();
 
 =head2 Squish
 
@@ -91,38 +92,8 @@ sub Squish {
 }
 
 sub Filter {
-    my $self    = shift;
-    my $content = shift;
-
-    my $minified;
-    my $jsmin = RT->Config->Get('JSMinPath');
-    if ( $jsmin && -x $jsmin ) {
-        my $input = $content;
-        my ( $output, $error );
-
-        # If we're running under fastcgi, STDOUT and STDERR are tied
-        # filehandles, which cause IPC::Run3 to flip out.  Construct
-        # temporary, not-tied replacements for it to see instead.
-        my $stdout = IO::Handle->new;
-        $stdout->fdopen( 1, 'w' );
-        local *STDOUT = $stdout;
-        my $stderr = IO::Handle->new;
-        $stderr->fdopen( 2, 'w' );
-        local *STDERR = $stderr;
-
-        local $SIG{'CHLD'} = 'DEFAULT';
-        require IPC::Run3;
-        IPC::Run3::run3( [$jsmin], \$input, \$output, \$error );
-        if ( $? >> 8 ) {
-            $RT::Logger->warning("failed to jsmin: $error ");
-        }
-        else {
-            $content  = $output;
-            $minified = 1;
-        }
-    }
-
-    return $content;
+    my ( $self, $content ) = @_;
+    return JavaScript::Minifier::XS::minify($content);
 }
 
 1;
diff --git a/sbin/rt-test-dependencies.in b/sbin/rt-test-dependencies.in
index 17f305b..3c82afc 100644
--- a/sbin/rt-test-dependencies.in
+++ b/sbin/rt-test-dependencies.in
@@ -247,6 +247,7 @@ Time::ParseDate
 Tree::Simple 1.04
 UNIVERSAL::require
 XML::RSS 1.05
+JavaScript::Minifier::XS
 .
 
 $deps{'MAILGATE'} = [ text_to_hash( << '.') ];
diff --git a/t/web/passthrough-jsmin b/t/web/passthrough-jsmin
deleted file mode 100755
index 41b0196..0000000
--- a/t/web/passthrough-jsmin
+++ /dev/null
@@ -1,4 +0,0 @@
-
-echo "// passthrough-jsmin added this";
-
-exec cat;
diff --git a/t/web/squish.t b/t/web/squish.t
index 4633646..3dd5b42 100644
--- a/t/web/squish.t
+++ b/t/web/squish.t
@@ -47,14 +47,11 @@ $m->content_contains('jQuery.noConflict', "found default js content");
 RT::Test->stop_server;
 
 
-diag "Test with a trivial jsmin which is a pass-through";
-RT->Config->Set( 'JSMinPath' => RT::Test::get_abs_relocatable_dir("passthrough-jsmin"));
 ( $url, $m ) = RT::Test->started_ok;
 $m->login;
 ($js_link) =
   $m->content =~ m!src="([^"]+?squished-([a-f0-9]{32})\.js)"!;
 $m->get_ok( $url . $js_link, 'follow squished js' );
-$m->content_contains( 'passthrough-jsmin added this', "has passthrough-added content" );
 $m->content_contains( 'function just_testing', "has not-by-default.js" );
 $m->content_contains('jQuery.noConflict', "found default js content");
 RT::Test->stop_server;

-----------------------------------------------------------------------


More information about the rt-commit mailing list