예제 #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
파일: index.php 프로젝트: chaoyanjie/HiBlog
<?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()));
 }