예제 #1
0
파일: Tool.php 프로젝트: ideatic/tinyfier
 /**
  * Compress javascript code
  *
  * Available settings:
  *   'pretty': if TRUE, adds line breaks and indentation to its output code to make the code easier for humans to read
  *   'gclosure': allow to use the external google closure compiler
  *
  * @param string $source
  * @param array  $settings
  *
  * @return string
  */
 public static function process($source, array $settings = array(), &$errors = array(), &$warnings = null)
 {
     if (empty($source)) {
         return $source;
     }
     //Default settings
     $settings = $settings + self::default_settings();
     //Compress using Google Closure compiler
     if ($settings['external_services'] && strlen($source) > $settings['external_services_min_length']) {
         if ($settings['gclosure']) {
             $extra = is_array($settings['gclosure']) ? $settings['gclosure'] : array();
             $compiled = self::_compress_google_closure($source, $settings['level'], $settings['pretty'], $errors, $warnings, $extra);
             if ($compiled !== false) {
                 return $compiled;
             }
         }
     }
     //Compile using JSqueeze
     if ($settings['pretty']) {
         return $source;
     } else {
         try {
             $jz = new \Patchwork\JSqueeze();
             $result = $jz->squeeze($source, true, false, false);
         } catch (Exception $e) {
             $errors[] = $e->getMessage();
             return $source;
         }
         return $result;
     }
 }
예제 #2
0
 public function minify_js($content)
 {
     include_once 'lib/JSqueeze.php';
     $jz = new Patchwork\JSqueeze();
     // Remove broken else statements first
     $content = str_replace('else;', '', $content);
     $content = $jz->squeeze($content, true, false, false);
     return $content;
 }
예제 #3
0
파일: Minify.php 프로젝트: codegyre/robo
 /**
  * Minifies and returns text.
  *
  * @return string|bool
  */
 protected function getMinifiedText()
 {
     switch ($this->type) {
         case 'css':
             if (!class_exists('\\CssMin')) {
                 return Result::errorMissingPackage($this, 'CssMin', 'natxet/CssMin');
             }
             return \CssMin::minify($this->text);
             break;
         case 'js':
             if (!class_exists('\\JSqueeze') && !class_exists('\\Patchwork\\JSqueeze')) {
                 return Result::errorMissingPackage($this, 'Patchwork\\JSqueeze', 'patchwork/jsqueeze');
             }
             if (class_exists('\\JSqueeze')) {
                 $jsqueeze = new \JSqueeze();
             } else {
                 $jsqueeze = new \Patchwork\JSqueeze();
             }
             return $jsqueeze->squeeze($this->text, $this->squeezeOptions['singleLine'], $this->squeezeOptions['keepImportantComments'], $this->squeezeOptions['specialVarRx']);
             break;
     }
     return false;
 }
예제 #4
0
 /**
  * Выполняет преобразование JS файла
  *
  * @param  string $sContent
  * @return string
  */
 protected function CompressJs($sContent)
 {
     $oJSqueeze = new \Patchwork\JSqueeze();
     $sContent = Config::Get('compress.js.use') ? $oJSqueeze->squeeze($sContent, true, false, false) : $sContent;
     /**
      * Добавляем разделитель в конце файла
      * с расчетом на возможное их слияние в будущем
      */
     return rtrim($sContent, ";") . ";" . PHP_EOL;
 }
function minit_jsqueeze($javascript)
{
    require_once 'lib/JSqueeze.php';
    $jz = new Patchwork\JSqueeze();
    return $jz->squeeze($javascript, true, true, false);
}
 /**
  * Выполняет сжатие
  *
  * @return mixed|void
  */
 public function compress()
 {
     $oJSqueeze = new \Patchwork\JSqueeze();
     $this->setContent($oJSqueeze->squeeze($this->getContent(), true, false, false));
 }
예제 #7
0
파일: Minify.php 프로젝트: roland-d/Robo
 /**
  * Minifies and returns text.
  *
  * @return string|bool
  */
 protected function getMinifiedText()
 {
     switch ($this->type) {
         case 'css':
             return \CssMin::minify($this->text);
             break;
         case 'js':
             if (class_exists('\\JSqueeze')) {
                 $jsqueeze = new \JSqueeze();
             } else {
                 $jsqueeze = new \Patchwork\JSqueeze();
             }
             return $jsqueeze->squeeze($this->text, $this->squeezeOptions['singleLine'], $this->squeezeOptions['keepImportantComments'], $this->squeezeOptions['specialVarRx']);
             break;
     }
     return false;
 }
 /**
  * Compressing js file
  * @param type $js text of js
  * @copyright ImageCMS (c) 2013, a.gula <*****@*****.**>
  */
 private function compressJs($js)
 {
     $jz = new \Patchwork\JSqueeze();
     $minifiedJs = $jz->squeeze($js, true, false, false);
     return $minifiedJs;
 }
예제 #9
0
파일: jsqueeze.php 프로젝트: yfix/yf
#!/usr/bin/php
<?php 
$config = ['git_urls' => ['https://github.com/tchwork/jsqueeze.git' => 'jsqueeze/'], 'autoload_config' => ['jsqueeze/src/' => 'Patchwork'], 'example' => function () {
    $js = ' function  hello_world ( i , v ) { return " " ; } ';
    var_dump($js);
    $jz = new \Patchwork\JSqueeze();
    $min = $jz->squeeze($js, true, true, false);
    var_dump($min);
}];
if ($return_config) {
    return $config;
}
require_once __DIR__ . '/_yf_autoloader.php';
new yf_autoloader($config);