forked from owncloud/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use JSqueeze instead of JSMin (owncloud#13052)
The JSMin minifier is non-free. JSqueeze is free, it's also a currently-maintained project following good development practices, and the best-performing minifier we tested. This requires a corresponding 3rdparty commit to drop mrclay/minify and add JSqueeze, and also uses a backport of the latest upstream version of the Assetic JSqueeze filter as the current version in 1.2 does not work with JSqueeze 2.x. The backported filter file can be dropped when our bundled copy of Assetic is updated to a version containing the newer JSqueezeFilter.
- Loading branch information
Showing
2 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
/** | ||
* ownCloud | ||
* | ||
* Copyright (C) 2014 Robin McCorkell <rmccorkell@karoshi.org.uk> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public | ||
* License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
/** | ||
* This file is just a copy of Assetic's JSqueezeFilter following | ||
* https://github.com/kriswallsmith/assetic/pull/698, with the class | ||
* renamed to JSqueeze2Filter, namespace changed, and use statements | ||
* adjusted. It can be dropped as soon as OC's bundled Assetic is updated | ||
* to a version containing the JSqueezeFilter that works with JSqueeze 2.x. | ||
*/ | ||
|
||
namespace OC\Assetic; | ||
|
||
use Assetic\Filter\FilterInterface; | ||
use Assetic\Asset\AssetInterface; | ||
|
||
/** | ||
* JSqueeze filter. | ||
* | ||
* @link https://github.com/nicolas-grekas/JSqueeze | ||
* @author Nicolas Grekas <p@tchwork.com> | ||
*/ | ||
class JSqueeze2Filter implements FilterInterface | ||
{ | ||
private $singleLine = true; | ||
private $keepImportantComments = true; | ||
private $className; | ||
private $specialVarRx = false; | ||
private $defaultRx; | ||
|
||
function __construct() { | ||
// JSqueeze is namespaced since 2.x, this works with both 1.x and 2.x | ||
if (class_exists('\\Patchwork\\JSqueeze')) { | ||
$this->className = '\\Patchwork\\JSqueeze'; | ||
$this->defaultRx = \Patchwork\JSqueeze::SPECIAL_VAR_PACKER; | ||
} else { | ||
$this->className = '\\JSqueeze'; | ||
$this->defaultRx = \JSqueeze::SPECIAL_VAR_RX; | ||
} | ||
} | ||
|
||
public function setSingleLine($bool) | ||
{ | ||
$this->singleLine = (bool) $bool; | ||
} | ||
|
||
// call setSpecialVarRx(true) to enable global var/method/property | ||
// renaming with the default regex (for 1.x or 2.x) | ||
public function setSpecialVarRx($specialVarRx) | ||
{ | ||
if (true === $specialVarRx) { | ||
$this->specialVarRx = $this->defaultRx; | ||
} else { | ||
$this->specialVarRx = $specialVarRx; | ||
} | ||
} | ||
|
||
public function keepImportantComments($bool) | ||
{ | ||
$this->keepImportantComments = (bool) $bool; | ||
} | ||
|
||
public function filterLoad(AssetInterface $asset) | ||
{ | ||
} | ||
|
||
public function filterDump(AssetInterface $asset) | ||
{ | ||
$parser = new $this->className(); | ||
$asset->setContent($parser->squeeze( | ||
$asset->getContent(), | ||
$this->singleLine, | ||
$this->keepImportantComments, | ||
$this->specialVarRx | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters