Skip to content

Commit

Permalink
Merge pull request #787 from andrewtch/bs4-fix
Browse files Browse the repository at this point in the history
Added SassUtils for better compatibility with bootstrap 4 (and scss comments overall)
  • Loading branch information
kriswallsmith committed Jan 13, 2016
2 parents 0c52d75 + 291fb39 commit ea1160d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Assetic/Filter/Sass/BaseSassFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Assetic\Factory\AssetFactory;
use Assetic\Filter\BaseProcessFilter;
use Assetic\Filter\DependencyExtractorInterface;
use Assetic\Util\CssUtils;
use Assetic\Util\SassUtils;

abstract class BaseSassFilter extends BaseProcessFilter implements DependencyExtractorInterface
{
Expand Down Expand Up @@ -34,7 +34,7 @@ public function getChildren(AssetFactory $factory, $content, $loadPath = null)
}

$children = array();
foreach (CssUtils::extractImports($content) as $reference) {
foreach (SassUtils::extractImports($content) as $reference) {
if ('.css' === substr($reference, -4)) {
// skip normal css imports
// todo: skip imports with media queries
Expand Down
2 changes: 1 addition & 1 deletion src/Assetic/Util/CssUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static function extractImports($content)
$imports[] = $matches['url'];
});

return array_unique($imports);
return array_unique(array_filter($imports));
}

final private function __construct()
Expand Down
22 changes: 22 additions & 0 deletions src/Assetic/Util/SassUtils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/*
* This file is part of the Assetic package, an OpenSky project.
*
* (c) 2010-2015 OpenSky Project Inc
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Assetic\Util;

/**
* Sass Utils.
*
* @author Kris Wallsmith <[email protected]>
*/
abstract class SassUtils extends CssUtils
{
const REGEX_COMMENTS = '/((?:\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)|\/\/[^\n]+)/';
}
2 changes: 1 addition & 1 deletion tests/Assetic/Test/Filter/ScssphpFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function testCompassExtensionCanBeDisabled()
{
$this->setExpectedExceptionRegExp(
'Exception',
'/Undefined mixin box\-shadow\: failed at `@include box\-shadow\(10px 10px 8px red\);`.*? line:? 4/'
'/^Undefined mixin box-shadow:.*line:* 4$/'
);

$asset = new FileAsset(__DIR__.'/fixtures/sass/main_compass.scss');
Expand Down
36 changes: 36 additions & 0 deletions tests/Assetic/Test/Util/SassUtilsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the Assetic package, an OpenSky project.
*
* (c) 2010-2015 OpenSky Project Inc
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Assetic\Test\Util;

use Assetic\Util\SassUtils;

class SassUtilsTest extends \PHPUnit_Framework_TestCase
{
public function testExtractImports()
{

$content = <<<CSS
// @import 'not_needed.css';
//@import "not_needed.css";
body{} // @import 'nod_needed.css';
@import 'custom.css';
@import "common.css" screen, projection;
body { background: url(../images/bg.gif); }
CSS;

$expected = array('common.css', 'custom.css');
$actual = SassUtils::extractImports($content);

$this->assertEquals($expected, array_intersect($expected, $actual), '::extractImports() returns all expected URLs');
$this->assertEquals(array(), array_diff($actual, $expected), '::extractImports() does not return unexpected URLs');
}
}

0 comments on commit ea1160d

Please sign in to comment.