Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update reference to scssphp with BC #897

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"require-dev": {
"leafo/lessphp": "^0.3.7",
"leafo/scssphp": "~0.1",
"scssphp/scssphp": "~1.0",
"meenie/javascript-packer": "^1.1",
"mrclay/minify": "<2.3",
"natxet/cssmin": "3.0.4",
Expand All @@ -36,7 +36,7 @@
"suggest": {
"twig/twig": "Assetic provides the integration with the Twig templating engine",
"leafo/lessphp": "Assetic provides the integration with the lessphp LESS compiler",
"leafo/scssphp": "Assetic provides the integration with the scssphp SCSS compiler",
"scssphp/scssphp": "Assetic provides the integration with the scssphp SCSS compiler",
"ptachoire/cssembed": "Assetic provides the integration with phpcssembed to embed data uris",
"leafo/scssphp-compass": "Assetic provides the integration with the SCSS compass plugin",
"patchwork/jsqueeze": "Assetic provides the integration with the JSqueeze JavaScript compressor"
Expand Down
44 changes: 34 additions & 10 deletions src/Assetic/Filter/ScssphpFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
use Assetic\Asset\AssetInterface;
use Assetic\Factory\AssetFactory;
use Assetic\Util\CssUtils;
use Leafo\ScssPhp\Compiler;

/**
* Loads SCSS files using the PHP implementation of scss, scssphp.
*
* Scss files are mostly compatible, but there are slight differences.
*
* @link http://leafo.net/scssphp/
* @link https://scssphp.github.io/scssphp/
*
* @author Bart van den Burg <[email protected]>
*/
Expand All @@ -46,16 +45,33 @@ public function isCompassEnabled()
public function setFormatter($formatter)
{
$legacyFormatters = array(
'scss_formatter' => 'Leafo\ScssPhp\Formatter\Expanded',
'scss_formatter_nested' => 'Leafo\ScssPhp\Formatter\Nested',
'scss_formatter_compressed' => 'Leafo\ScssPhp\Formatter\Compressed',
'scss_formatter_crunched' => 'Leafo\ScssPhp\Formatter\Crunched',
'scss_formatter' => array(
'leafo' => 'Leafo\ScssPhp\Formatter\Expanded',
'scssphp' => 'ScssPhp\ScssPhp\Formatter\Expanded'
),
'scss_formatter_nested' => array(
'leafo' => 'Leafo\ScssPhp\Formatter\Nested',
'scssphp' => 'ScssPhp\ScssPhp\Formatter\Nested'
),
'scss_formatter_compressed' => array(
'leafo' => 'Leafo\ScssPhp\Formatter\Compressed',
'scssphp' => 'ScssPhp\ScssPhp\Formatter\Compressed'
),
'scss_formatter_crunched' => array(
'leafo' => 'Leafo\ScssPhp\Formatter\Crunched',
'scssphp' => 'ScssPhp\ScssPhp\Formatter\Crunched'
),
);

if (isset($legacyFormatters[$formatter])) {
@trigger_error(sprintf('The scssphp formatter `%s` is deprecated. Use `%s` instead.', $formatter, $legacyFormatters[$formatter]), E_USER_DEPRECATED);
if (class_exists($legacyFormatters[$formatter]['scssphp'])) {
$legacyFormatter = $legacyFormatters[$formatter]['scssphp'];
} else {
$legacyFormatter = $legacyFormatters[$formatter]['leafo'];
}
@trigger_error(sprintf('The scssphp formatter `%s` is deprecated. Use `%s` instead.', $formatter, $legacyFormatter), E_USER_DEPRECATED);

$formatter = $legacyFormatters[$formatter];
$formatter = $legacyFormatter;
}

$this->formatter = $formatter;
Expand Down Expand Up @@ -88,7 +104,7 @@ public function registerFunction($name, $callable)

public function filterLoad(AssetInterface $asset)
{
$sc = new Compiler();
$sc = $this->newCompiler();

if ($this->compass) {
new \scss_compass($sc);
Expand Down Expand Up @@ -123,7 +139,7 @@ public function filterDump(AssetInterface $asset)

public function getChildren(AssetFactory $factory, $content, $loadPath = null)
{
$sc = new Compiler();
$sc = $this->newCompiler();
if ($loadPath !== null) {
$sc->addImportPath($loadPath);
}
Expand All @@ -144,4 +160,12 @@ public function getChildren(AssetFactory $factory, $content, $loadPath = null)

return $children;
}

protected function newCompiler()
{
if (class_exists('ScssPhp\ScssPhp\Compiler')) {
return new \ScssPhp\ScssPhp\Compiler();
}
return new \Leafo\ScssPhp\Compiler();
}
}
13 changes: 10 additions & 3 deletions tests/Assetic/Test/Filter/ScssphpFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ class ScssphpFilterTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Leafo\ScssPhp\Compiler')) {
$this->markTestSkipped('leafo/scssphp is not installed');
if (
!class_exists('Leafo\ScssPhp\Compiler')
&& !class_exists('ScssPhp\ScssPhp\Compiler')
) {
$this->markTestSkipped('scssphp/scssphp is not installed');
}
}

Expand Down Expand Up @@ -131,7 +134,11 @@ public function testSetFormatter()
$actual->load();

$filter = $this->getFilter();
$filter->setFormatter('Leafo\ScssPhp\Formatter\Compressed');
if (class_exists('ScssPhp\ScssPhp\Formatter\Compressed')) {
$filter->setFormatter('ScssPhp\ScssPhp\Formatter\Compressed');
} else {
$filter->setFormatter('Leafo\ScssPhp\Formatter\Compressed');
}
$filter->filterLoad($actual);

$this->assertRegExp(
Expand Down