Add support for Google Closure Compiler in javascript minfiy filter
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 6 Nov 2009 22:02:17 +0000 (15:02 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 6 Nov 2009 22:02:17 +0000 (15:02 -0700)
framework/Core/lib/Horde.php
framework/Text_Filter/lib/Horde/Text/Filter/JavascriptMinify.php
framework/Text_Filter/package.xml

index b088f5d..48b6465 100644 (file)
@@ -329,13 +329,24 @@ HTML;
                 : $conf['cachejsparams']['lifetime'];
         }
 
-        if ($conf['cachejsparams']['compress'] == 'yui') {
+        switch ($conf['cachejsparams']['compress']) {
+        case 'closure':
+            $jsmin_params = array(
+                'closure' => $conf['cachejsparams']['closurepath'],
+                'java' => $conf['cachejsparams']['javapath']
+            );
+            break;
+
+        case 'yui':
             $jsmin_params = array(
                 'java' => $conf['cachejsparams']['javapath'],
                 'yui' => $conf['cachejsparams']['yuipath']
             );
-        } else {
+            break;
+
+        default:
             $jsmin_params = array();
+            break;
         }
 
         /* Output prototype.js separately from the other files. */
index 1809e83..5d7b934 100644 (file)
@@ -19,6 +19,7 @@ class Horde_Text_Filter_JavascriptMinify extends Horde_Text_Filter
      * @var array
      */
     protected $_params = array(
+        'closure' => null,
         'java' => null,
         'yui' => null
     );
@@ -32,10 +33,16 @@ class Horde_Text_Filter_JavascriptMinify extends Horde_Text_Filter
      */
     public function postProcess($text)
     {
-        /* Are we using the YUI Compressor? */
-        if (!empty($this->_params['yui']) &&
-            !empty($this->_params['java'])) {
-            return $this->_runYuiCompressor($text);
+        if (!empty($this->_params['java'])) {
+            /* Are we using the YUI Compressor? */
+            if (!empty($this->_params['yui'])) {
+                return $this->_runCompressor($text, $this->_params['yui'], ' --type js');
+            }
+
+            /* Are we using the Google Closure Compiler? */
+            if (!empty($this->_params['closure'])) {
+                return $this->_runCompressor($text, $this->_params['closure']);
+            }
         }
 
         /* Use PHP-based minifier. */
@@ -48,16 +55,18 @@ class Horde_Text_Filter_JavascriptMinify extends Horde_Text_Filter
     }
 
     /**
-     * Passes javascript through YUI Compressor.
+     * Passes javascript through a java compressor (YUI or Closure).
      *
      * @param string $text  The javascript text.
+     * @param string $jar   The JAR location.
+     * @param string $args  Additional command line arguments.
      *
      * @return string  The modified text.
      */
-    protected function _runYuiCompressor($text)
+    protected function _runCompressor($jar, $args = '')
     {
         if (!is_executable($this->_params['java']) ||
-            !file_exists($this->_params['yui'])) {
+            !file_exists($jar)) {
             return $text;
         }
 
@@ -67,7 +76,7 @@ class Horde_Text_Filter_JavascriptMinify extends Horde_Text_Filter
             2 => array('pipe', 'w')
         );
 
-        $process = proc_open(escapeshellcmd($this->_params['java']) . ' -jar ' . escapeshellarg($this->_params['yui']) . ' --type js', $descspec, $pipes);
+        $process = proc_open(escapeshellcmd($this->_params['java']) . ' -jar ' . escapeshellarg($jar) . $args, $descspec, $pipes);
 
         fwrite($pipes[0], $text);
         fclose($pipes[0]);
index 08d66dc..8a9a69b 100644 (file)
@@ -37,7 +37,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
   <api>beta</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Fix dimming signatures when mixed with quoted text (Bug #4299).
+ <notes>* Add support for Google Closure Compiler in javascript minfiy filter.
+ * Fix dimming signatures when mixed with quoted text (Bug #4299).
  * Added javscript minify filter.
  * Add support for using the tidy extension when filtering HTML data.
  * Initial Horde 4 package.