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

Ignoring partial scss files (_*.scss) #830

Open
wants to merge 3 commits 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
21 changes: 21 additions & 0 deletions src/Assetic/Filter/ScssphpFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,21 @@
class ScssphpFilter implements DependencyExtractorInterface
{
private $compass = false;
private $ignorePartials = false;
private $importPaths = array();
private $customFunctions = array();
private $formatter;
private $variables = array();

public function ignorePartial($enable = true)
{
$this->ignorePartials = (Boolean) $enable;
}

public function isPartialIgnored()
{
return $this->ignorePartials;
}

public function enableCompass($enable = true)
{
Expand Down Expand Up @@ -88,6 +99,16 @@ public function registerFunction($name, $callable)

public function filterLoad(AssetInterface $asset)
{
if($this->ignorePartials) {
$path = $asset->getSourceRoot() . '/' . $asset->getSourcePath();
$file = basename($path);

if(strrpos($file, '_', -strlen($file)) !== false) {
$asset->setContent(" ");
return;
}
}

$sc = new Compiler();

if ($this->compass) {
Expand Down
11 changes: 11 additions & 0 deletions tests/Assetic/Test/Filter/ScssphpFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ public function testSetVariables()

$this->assertContains('color: red', $asset->getContent(), 'Variables can be added');
}

public function testIgnorePartials() {
$asset = new FileAsset(__DIR__.'/fixtures/sass/_include.scss');
$asset->load();

$filter = $this->getFilter();
$filter->ignorePartial(true);
$filter->filterLoad($asset);

$this->assertEquals(' ', $asset->getContent(), '->filterLoad() should ignore partial scss files');
}

// private

Expand Down