[Rt-commit] rt branch, no-prototype, updated. rt-3.8.8-190-g9443228

? sunnavy sunnavy at bestpractical.com
Fri Jul 30 04:00:36 EDT 2010


The branch, no-prototype has been updated
       via  9443228340be9f8ee2c64ac9b2fce33a9822f134 (commit)
       via  547a7ec6cb885c17e2d2d26d065feab80497c3b5 (commit)
      from  349075df69fa5fe4d448e73b0c4c5c1df70553eb (commit)

Summary of changes:
 etc/RT_Config.pm.in           |   15 ++++++++++++
 share/html/NoAuth/js/dhandler |   51 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 59 insertions(+), 7 deletions(-)

- Log -----------------------------------------------------------------
commit 547a7ec6cb885c17e2d2d26d065feab80497c3b5
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jul 30 15:15:53 2010 +0800

    we can use jsmin binary now, it's much faster

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index d6205e8..13752f1 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1805,6 +1805,21 @@ C<Set(@Plugins, (qw(Extension::QuickDelete RT::FM)));>
 
 Set(@Plugins, ());
 
+=item C<$JSMinPath>
+
+Path to jsmin binary.
+You can go to http://www.crockford.com/javascript/jsmin.html to get one.
+
+If specified, it'll be used to minify javascript files.
+If fails, RT will then try module L<JavaScript::Minifier>.
+If that still fails, RT will simply concatenate js files.
+
+Example:
+
+C<Set($JSMinPath, '/path/to/jsmin');>
+
+=cut
+
 =back
 
 =head1 Development Configuration
diff --git a/share/html/NoAuth/js/dhandler b/share/html/NoAuth/js/dhandler
index a057fcd..bee8b01 100644
--- a/share/html/NoAuth/js/dhandler
+++ b/share/html/NoAuth/js/dhandler
@@ -55,9 +55,21 @@ my $path;
 if ( $arg =~ m{squished\.js$} ) {
     $path = $m->current_comp->dir_path;
     unless ( $content ) {
-        my $no_minify;
-        eval { require JavaScript::Minifier; };
-        $no_minify = 1 if $@;
+        my $has_jsmin;
+        my $jsmin = RT->Config->Get( 'JSMinPath' );
+
+        if ( $jsmin && -x $jsmin ) {
+            $has_jsmin = 1;
+        }
+
+        my $has_jsmin_module;
+        eval { require JavaScript::Minifier };
+        if ($@) {
+            $RT::Logger->debug("can't load JavaScript::Minifier: $@");
+        }
+        else {
+            $has_jsmin_module = 1;
+        }
 
         require File::Spec;
         my @js =
@@ -65,12 +77,27 @@ if ( $arg =~ m{squished\.js$} ) {
 
         for my $js (@js) {
             my $file = File::Spec->catfile( $path, $js );
-            if ( $no_minify ) {
-                $content .= $m->scomp( $file );
+            my $input = $m->scomp($file);
+
+            if ( $has_jsmin ) {
+                my ( $output, $error );
+                require IPC::Run;
+                IPC::Run::run [ $jsmin ], \$input, \$output, \$error, IPC::Run::timeout(10);
+                if ( $error ) {
+                    $RT::Logger->warning( "failed to jsmin $file: $error" );
+                }
+                else {
+                    $content .= $output;
+                    next;
+                }
             }
-            else {
-                $content .= JavaScript::Minifier::minify( input => $m->scomp($file));
+
+            if ( $has_jsmin_module ) {
+                $content .= JavaScript::Minifier::minify( input => $input );
+                next;
             }
+
+            $content .= $input;
         }
     }
 

commit 9443228340be9f8ee2c64ac9b2fce33a9822f134
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jul 30 16:02:02 2010 +0800

    tweak env for jsmin binary

diff --git a/share/html/NoAuth/js/dhandler b/share/html/NoAuth/js/dhandler
index bee8b01..07ce00d 100644
--- a/share/html/NoAuth/js/dhandler
+++ b/share/html/NoAuth/js/dhandler
@@ -79,12 +79,22 @@ if ( $arg =~ m{squished\.js$} ) {
             my $file = File::Spec->catfile( $path, $js );
             my $input = $m->scomp($file);
 
-            if ( $has_jsmin ) {
+            if ($has_jsmin) {
                 my ( $output, $error );
+
+                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::Run;
-                IPC::Run::run [ $jsmin ], \$input, \$output, \$error, IPC::Run::timeout(10);
-                if ( $error ) {
-                    $RT::Logger->warning( "failed to jsmin $file: $error" );
+                IPC::Run::run( [$jsmin], \$input, \$output, \$error );
+                if ( $? >> 8 ) {
+                    $RT::Logger->warning("failed to jsmin $file: $error ");
                 }
                 else {
                     $content .= $output;

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


More information about the Rt-commit mailing list