示例#1
0
 public function jsMin($jsText = "")
 {
     if ($this->shouldMinify) {
         $jsText = \JSMin\JSMin::minify($jsText);
     }
     return $jsText;
 }
示例#2
0
 /**
  * @dataProvider exceptionProvider
  */
 public function testExpections($input, $label, $expClass, $expMessage)
 {
     $eClass = $eMsg = '';
     try {
         JSMin::minify($input);
     } catch (\Exception $e) {
         $eClass = get_class($e);
         $eMsg = $e->getMessage();
     }
     $this->assertTrue($eClass === $expClass && $eMsg === $expMessage, 'JSMin : throw on ' . $label);
 }
示例#3
0
function test_JSMin_exception($js, $label, $expClass, $expMessage)
{
    $eClass = $eMsg = '';
    try {
        JSMin::minify($js);
    } catch (Exception $e) {
        $eClass = get_class($e);
        $eMsg = $e->getMessage();
    }
    $passed = assertTrue($eClass === $expClass && $eMsg === $expMessage, 'JSMin : throw on ' . $label);
    if (!$passed && isset($e) && __FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
        echo "\n  ---", $e, "\n\n";
    }
}
示例#4
0
文件: helper.php 项目: lautr3k/Straw
 /**
  * JS Minifier.
  *
  * @static
  * @method minify_js
  * @param  {String} $data
  * @return {String}
  */
 public static function minify_js($data)
 {
     // Run the minifier
     $data = \JSMin\JSMin::minify($data);
     // Replace all new line chars
     $data = str_replace("\n", ' ', $data);
     // Force removing first block of comments
     return self::remove_first_comment_block($data);
 }
示例#5
0
 /**
  * Minifies passed JS source if $this->minify == true
  * @access 	public
  * @param 	string 	source
  * @return 	string 	minified source
  */
 protected function minify_js($source)
 {
     if ($this->minify == true) {
         return JSMin::minify($source);
     } else {
         return "\n\n/** " . $this->file_path . " **/\n\n;" . $source;
     }
 }
示例#6
0
<?php

require __DIR__ . '/../vendor/autoload.php';
function h($txt)
{
    return htmlspecialchars($txt, ENT_QUOTES, 'UTF-8');
}
$tpl = array();
if (isset($_POST['textIn'])) {
    $textIn = str_replace("\r\n", "\n", $_POST['textIn']);
    $tpl['inBytes'] = strlen($textIn);
    $startTime = microtime(true);
    try {
        $tpl['output'] = \JSMin\JSMin::minify($textIn);
    } catch (Exception $e) {
        $tpl['exceptionMsg'] = getExceptionMsg($e, $textIn);
        $tpl['output'] = $textIn;
        sendPage($tpl);
    }
    $tpl['time'] = microtime(true) - $startTime;
    $tpl['outBytes'] = strlen($tpl['output']);
}
sendPage($tpl);
/**
 * @param Exception $e
 * @param string $input
 * @return string HTML
 */
function getExceptionMsg(Exception $e, $input)
{
    $msg = "<p>" . h($e->getMessage()) . "</p>";
示例#7
0
文件: jsmin.php 项目: poef/ariadne
 public static function compile($string)
 {
     return \JSMin\JSMin::minify($string);
 }
示例#8
0
 public function filterDump(AssetInterface $asset)
 {
     $asset->setContent(JSMin::minify($asset->getContent()));
 }