-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add support for named converted output files #30
Open
evertharmeling
wants to merge
15
commits into
SymfonyCasts:main
Choose a base branch
from
evertharmeling:path-keys
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fe4376d
Add support for file name for converted files in paths
evertharmeling f1574a7
Fixed PHP CS fixer errors
evertharmeling 3b7ae99
Fixed PHPStan errors
evertharmeling a6808a8
Changed order of method arguments
evertharmeling 3d13b79
Reverted removal of SassBuilder constructor injection to prevent BC-b…
evertharmeling 9c0afd4
Add support for custom filename in compile function
evertharmeling 3c8497e
Fix php-cs-fixer
evertharmeling 04f0769
Added SassCssCompilerTest
evertharmeling c5e3f3a
Fix php-cs-fixer
evertharmeling c095075
Fix testsuite
evertharmeling b942232
Fix php-cs-fixer
evertharmeling 32a8ca3
Fix config validation is keys are used defining the "root_sass" paths
evertharmeling 145df5b
Moved Configuration test to logical namespace path
evertharmeling 669fa0a
Minor cleanup in test
evertharmeling 15a9f6e
Use substr in stead of str_replace
evertharmeling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,120 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the SymfonyCasts SassBundle package. | ||
* Copyright (c) SymfonyCasts <https://symfonycasts.com/> | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfonycasts\SassBundle\Tests\AssetMapper; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\AssetMapper\AssetMapperInterface; | ||
use Symfony\Component\AssetMapper\MappedAsset; | ||
use Symfonycasts\SassBundle\AssetMapper\SassCssCompiler; | ||
use Symfonycasts\SassBundle\SassBuilder; | ||
|
||
final class SassCssCompilerTest extends TestCase | ||
{ | ||
private const CSS_DIR = __DIR__.'/../fixtures/var/sass'; | ||
|
||
protected function setUp(): void | ||
{ | ||
if (!is_dir(self::CSS_DIR)) { | ||
mkdir(self::CSS_DIR, 0777, true); | ||
} | ||
} | ||
|
||
public function testCompileSingleSassPath(): void | ||
{ | ||
$scssFile = __DIR__.'/../fixtures/assets/app.scss'; | ||
$scssPaths = [ | ||
$scssFile, | ||
]; | ||
$cssFile = self::CSS_DIR.'/app.output.css'; | ||
|
||
$compiler = new SassCssCompiler( | ||
$scssPaths, | ||
self::CSS_DIR, | ||
$this->createSassBuilder($scssPaths) | ||
); | ||
|
||
$mappedAsset = new MappedAsset( | ||
'app.scss', | ||
$scssFile, | ||
'app.css' | ||
); | ||
|
||
file_put_contents($cssFile, <<<EOF | ||
p { | ||
color: red; | ||
} | ||
EOF | ||
); | ||
|
||
$compiledContent = $compiler->compile( | ||
file_get_contents($scssFile), | ||
$mappedAsset, | ||
$this->createMock(AssetMapperInterface::class) | ||
); | ||
|
||
$this->assertStringEqualsFile( | ||
$cssFile, | ||
$compiledContent | ||
); | ||
} | ||
|
||
public function testCompileNamedSassPath() | ||
{ | ||
$scssFile = __DIR__.'/../fixtures/assets/admin/app.scss'; | ||
|
||
$scssPaths = [ | ||
'admin' => $scssFile, | ||
]; | ||
$cssFile = self::CSS_DIR.'/admin.output.css'; | ||
|
||
$compiler = new SassCssCompiler( | ||
$scssPaths, | ||
self::CSS_DIR, | ||
$this->createSassBuilder($scssPaths) | ||
); | ||
|
||
$mappedAsset = new MappedAsset( | ||
'admin/app.scss', | ||
$scssFile, | ||
'admin.css' | ||
); | ||
|
||
file_put_contents($cssFile, <<<EOF | ||
p { | ||
color: blue; | ||
} | ||
EOF | ||
); | ||
|
||
$compiledContent = $compiler->compile( | ||
file_get_contents($scssFile), | ||
$mappedAsset, | ||
$this->createMock(AssetMapperInterface::class) | ||
); | ||
|
||
$this->assertStringEqualsFile( | ||
$cssFile, | ||
$compiledContent | ||
); | ||
} | ||
|
||
private function createSassBuilder(array $sassPaths): SassBuilder | ||
{ | ||
return new SassBuilder( | ||
$sassPaths, | ||
self::CSS_DIR, | ||
__DIR__.'/../fixtures', | ||
null, | ||
false | ||
); | ||
} | ||
} |
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
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
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,5 @@ | ||
$color: blue; | ||
|
||
p { | ||
color: $color; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to allow using maps and not just lists, you need to use
->useAttributeAsKey
. Otherwise, merging multiple config files (note that for this matter, awhen@prod
section counts as a separate config for the merging process) together won't preserve keys (and devs using a XML config file would not be able to specify a key)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how I would define that?
With or without
->useAttributeAsKey()
, and manually testing it with an extrawhen@dev
config for example, does not change the array passed to thevalidate
-callback function? And what would be the$name
variable to pass to->useAttributeAsKey()
?Can you point me to an example definition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evertharmeling you would have to define a
when@dev
section (or a separate file) that also configures thisroot_sass
node, so that some merging actually happens (if the value is defined only in 1 place, the merging is bypassed entirely, which will preserve keys even if the node is not configured for that).For the name being passed, this would be the name of the attribute used in an XML config (where it cannot be an array key). In this case,
output
looks like a good option.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing with:
config/packages/symfony_casts.yaml
:config/packages/test.yaml
:Running
symfony console debug:config SymfonycastsSassBundle
:Even replacing an entry with same key
website
seems to work?I'm fine with adding
->useAttributeAsKey('output')
, but can't reproduce it with these examples or am I still overlooking something?