private function CSSCompression_Setup::nested in Advanced CSS/JS Aggregation 7
Same name and namespace in other branches
- 6 advagg_css_compress/css-compressor-3.x/src/lib/Setup.inc \CSSCompression_Setup::nested()
Run nested elements through a separate instance of compression
Parameters
(array) css: Reference to the original css array:
(bool) organize: Whether or not to organize the subsection (only true for media sections):
1 call to CSSCompression_Setup::nested()
- CSSCompression_Setup::setup in advagg_css_compress/
css-compressor-3.x/ src/ lib/ Setup.inc - Setup selector and details arrays for compression methods
File
- advagg_css_compress/
css-compressor-3.x/ src/ lib/ Setup.inc, line 156
Class
- CSSCompression_Setup
- CSS Compressor [VERSION] [DATE] Corey Hart @ http://www.codenothing.com
Code
private function nested(&$css = array(), $organize = false) {
$options = $this->options;
$left = 0;
$right = 0;
$row = '';
$independent = '';
$content = '';
$spacing = '';
$newline = $this->options['readability'] > CSSCompression::READ_NONE ? "\n" : '';
// Find the end of the nested section
while (count($css) && ($left < 1 || $left > $right)) {
$row = trim(array_shift($css));
if ($row == '') {
continue;
}
else {
if ($row == '{') {
$left++;
}
else {
if ($row == '}') {
$right++;
}
else {
if (count($css) && substr($row, 0, 1) != '@' && substr($css[0], 0, 1) == '@' && substr($row, -1) == ';') {
$independent .= $row;
continue;
}
}
}
}
$content .= $row;
}
// Ensure copy of instance exists
if (!$this->instance) {
$this->instance = new CSSCompression();
}
// Fresh start
$this->instance
->reset();
// Compress the nested section independently after removing the wrapping braces
// Also make sure to only organize media sections
if ($options['organize'] == true && $organize == false) {
$options['organize'] = false;
}
// Independent sections should be prepended to the next compressed section
$content = ($independent == '' ? '' : $independent . $newline) . $this->instance
->compress(substr($content, 1, -1), $options);
// Formatting for anything higher then 0 readability
if ($newline == "\n") {
$content = "\n\t" . str_replace("\n", "\n\t", $content) . "\n";
$spacing = $this->options['readability'] > CSSCompression::READ_MIN ? ' ' : '';
}
// Stash the compressed nested script
return "{$spacing}{" . $content . "}{$newline}";
}