-
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
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Ofcourse, good call! Fixed it! |
This comment was marked as off-topic.
This comment was marked as off-topic.
ebb96d6
to
ed7f4c8
Compare
This comment was marked as outdated.
This comment was marked as outdated.
Throwing an exception on file overwriting sounds to me like a good idea. Could you do that too? And in the exception message, we probably could mention that devs can leverage custom naming for the paths. |
1baf508
to
f122676
Compare
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.
Looks good to me, but I would like to hear more thoughts on this new feature as this might bring some BC break in the future if we decided we don't need this feature.
Also, it seems like it would be a nice idea to mention this new feature in the docs as it might be a little-known fact for users.
Sure, I get it! I will add it to the docs later on |
bed0e0d
to
9de97be
Compare
9de97be
to
32a8ca3
Compare
@@ -61,7 +61,7 @@ public function getConfigTreeBuilder(): TreeBuilder | |||
->end() | |||
->validate() | |||
->ifTrue(static function (array $paths): bool { | |||
if (1 === \count($paths)) { | |||
if (1 === \count($paths) || !array_is_list($paths)) { |
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, a when@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?
$rootNode
->children()
->arrayNode('root_sass')
->info('Path to your Sass root file')
->cannotBeEmpty()
->useAttributeAsKey('???') // <--- here?
->scalarPrototype()
->end()
->validate()
...
With or without ->useAttributeAsKey()
, and manually testing it with an extra when@dev
config for example, does not change the array passed to the validate
-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 this root_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
:
symfonycasts_sass:
root_sass:
website: 'assets/website/scss/app.scss'
config/packages/test.yaml
:
symfonycasts_sass:
root_sass:
test: 'assets/website/scss/app.scss'
website: 'assets/test/scss/app.scss'
when@dev:
symfonycasts_sass:
root_sass:
test2: 'assets/website/scss/app.scss'
Running symfony console debug:config SymfonycastsSassBundle
:
Current configuration for "SymfonycastsSassBundle"
==================================================
symfonycasts_sass:
root_sass:
website: assets/test/scss/app.scss
test: assets/website/scss/app.scss
test2: assets/website/scss/app.scss
binary: null
embed_sourcemap: true
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?
src/SassBuilder.php
Outdated
|
||
foreach ($this->sassPaths as $identifier => $configuredSassPath) { | ||
// as the configured paths include the project dir, we need to subtract it to be able to compare the paths | ||
$logicalPath = str_replace($this->projectRootDir.'/assets/', '', $configuredSassPath); |
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.
be careful about windows paths when doing str_replace
.
And also be careful that you don't remove only a prefix. If the project root dir is /app
, things will be if you have a path like /app/assets/sub/app/assets
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.
Good one, I refactored it to make use of substr
. How would I need to address any Windows related problems?
As I have the following setup in my application:
My current
symfonycasts_sass
config:Would result in 1 file;
var/sass/app.output.css
, as allroot_sass
paths with the same filename will be stored under the same css filename, thus overwriting the file.With this PR support is added to be able to influence the name of the converted
css
-file and still be BC with the current config / output.The following
symfonycasts_sass
config:Would result in 2 files
var/sass/admin.output.css
var/sass/website.output.css
The only caveat is, that the following config could result in an unexpected output:
Would result in 2 files
var/sass/app.output.css
(and notvar/sass/20.output.css
)var/sass/website.output.css
As I'm currently 'ignoring' numbered keys as the array of paths gets numbered keys automatically if specific keys aren't used, to be BC.
Todo