Skip to content

Commit

Permalink
Make JSqueeze filter work with 1.x and 2.x (namespaced)
Browse files Browse the repository at this point in the history
Also disables the global var renaming behaviour by default
for both 1.x and 2.x (this seems like the safest choice) but
allows setSpecialVarRx(true) to enable it with the default
regex.
  • Loading branch information
AdamWill committed Jan 2, 2015
1 parent bdd814c commit aefe16d
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/Assetic/Filter/JSqueezeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,21 @@ class JSqueezeFilter implements FilterInterface
{
private $singleLine = true;
private $keepImportantComments = true;
private $specialVarRx = \JSqueeze::SPECIAL_VAR_RX;
private $className;
private $specialVarRx = false;
private $defaultRx;

function __construct() {
// JSqueeze is namespaced since 2.x, this works with both 1.x and 2.x
// Upstream default for special var is false in 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)
{
Expand All @@ -32,7 +46,11 @@ public function setSingleLine($bool)

public function setSpecialVarRx($specialVarRx)
{
$this->specialVarRx = $specialVarRx;
if (true === $specialVarRx) {
$this->specialVarRx = $this->defaultRx;
} else {
$this->specialVarRx = $specialVarRx;
}
}

public function keepImportantComments($bool)
Expand All @@ -46,7 +64,7 @@ public function filterLoad(AssetInterface $asset)

public function filterDump(AssetInterface $asset)
{
$parser = new \JSqueeze();
$parser = new $this->className();
$asset->setContent($parser->squeeze(
$asset->getContent(),
$this->singleLine,
Expand Down

0 comments on commit aefe16d

Please sign in to comment.