-
Notifications
You must be signed in to change notification settings - Fork 154
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
Save @import tag #334
Save @import tag #334
Changes from 3 commits
90d1099
b8eb532
8e7a4d3
6f13c0d
3178fed
e444b58
fd11a13
1e88c7a
e85c95a
43d4fe6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -394,7 +394,7 @@ protected function process(\DOMDocument $xmlDocument) | |
$this->removeInvisibleNodes($xPath); | ||
} | ||
|
||
$this->copyCssWithMediaToStyleNode($xmlDocument, $xPath, $cssParts['media']); | ||
$this->copyCssWithMediaToStyleNode($xmlDocument, $xPath, $cssParts['media'], $cssParts['imports']); | ||
} | ||
|
||
/** | ||
|
@@ -911,13 +911,14 @@ private function attributeValueIsImportant($attributeValue) | |
* | ||
* @return void | ||
*/ | ||
private function copyCssWithMediaToStyleNode(\DOMDocument $xmlDocument, \DOMXPath $xPath, $css) | ||
private function copyCssWithMediaToStyleNode(\DOMDocument $xmlDocument, \DOMXPath $xPath, $css, $imports) | ||
{ | ||
if ($css === '') { | ||
if ($css === '' && $imports === '') { | ||
return; | ||
} | ||
|
||
$mediaQueriesRelevantForDocument = []; | ||
!$imports ?: $mediaQueriesRelevantForDocument[] = "\n".$imports."\n"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't use the Elvis operator for commands. (It should only be used for return values or assignments). Please use an IF instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please put spaces around the concatenation dots. |
||
|
||
foreach ($this->extractMediaQueriesFromCss($css) as $mediaQuery) { | ||
foreach ($this->parseCssRules($mediaQuery['css']) as $selector) { | ||
|
@@ -1077,6 +1078,14 @@ function ($matches) use (&$media) { | |
$cssWithoutComments | ||
); | ||
|
||
//Keep @imports | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is a smell that the additional code should go into a separate method. |
||
$imports = ''; | ||
preg_match_all('/^\\s*@import\\s[^;]+;/misU', $css, $importsMatches, PREG_PATTERN_ORDER); | ||
if( !empty($importsMatches[0]) ){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No spaces after the opening parenthesis or before the closing one, please. But there should be a space between the closing parenthesis and the opening curly brace. |
||
$importsArray = $importsMatches[0]; | ||
$imports = implode("\n", array_map('trim', $importsArray)); | ||
} | ||
|
||
// filter the CSS | ||
$search = [ | ||
'import directives' => '/^\\s*@import\\s[^;]+;/misU', | ||
|
@@ -1085,7 +1094,7 @@ function ($matches) use (&$media) { | |
|
||
$cleanedCss = preg_replace($search, '', $cssForAllowedMediaTypes); | ||
|
||
return ['css' => $cleanedCss, 'media' => $media]; | ||
return ['css' => $cleanedCss, 'media' => $media, 'imports' => $imports]; | ||
} | ||
|
||
/** | ||
|
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.
Please add the missing param annotation.