Skip to content

Commit

Permalink
Fix to issue 28, extending across multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
richthegeek committed Jul 30, 2012
1 parent 5ae6504 commit 03af9f2
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 23 deletions.
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Version 201207301030 - Fix to issue 28, extending from included files
Version 201207271000 - Fixed scale-color function (attrib: Steve Jones)
Version 201207262300 - Various issue fixes, better testing framework
Version 201206291700 - Fixed some tests, minor changes to string and import handling
Expand Down
3 changes: 3 additions & 0 deletions test.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ function test_files($files, $dir = '.') {

$diff = exec('diff -ibwB /tmp/scss_test_0 /tmp/scss_test_1', $out);
if (count($out)) {
if (isset($_GET['full'])) {
$out[] = $result;
}
return implode("\n", $out);
} else {
return TRUE;
Expand Down
4 changes: 1 addition & 3 deletions tests/extend.sass
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.error
border: 1px #f00
background-color: #fdd
@import extend_included.scss;

.seriousError
@extend .error
Expand Down
4 changes: 4 additions & 0 deletions tests/extend_included.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.error {
border: 1px #f00;
background-color: #fdd;
}
26 changes: 9 additions & 17 deletions tests/nested-media.css
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
.sidebar {
width: 300px;
}
width: 300px; }
@media screen and (max-width: 1024px) {
.sidebar {
width: 500px;
}
.sidebar .subclass {
height: 100px;
}
.sidebar .subclass .subsubclass {
height: 200px;
}
}
width: 500px; }
.sidebar .subclass {
height: 100px; }
.sidebar .subclass .subsubclass {
height: 200px; } }
@media screen and (max-width:1024px) {
.subclass {
height: 100px
}
.subclass .subsubclass {
height: 200px
}
}
height: 100px; }
.subclass .subsubclass {
height: 200px; } }
2 changes: 1 addition & 1 deletion tree/SassExtendNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct($token) {
* @return array An empty array
*/
public function parse($context) {
# Richard Lyon, 25/10/2011 - resolve selectors in relation to variables
# resolve selectors in relation to variables
# allows extend inside nested loops.
$this->root->extend($this->value, $this->parent->resolveSelectors($context));
return array();
Expand Down
1 change: 1 addition & 0 deletions tree/SassImportNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function parse($context) {
$tree->children = array();
} else {
$tree = new SassRootNode($this->parser);
$tree->extend_parent = $this->parent;
}

foreach ($files as $subfile) {
Expand Down
11 changes: 11 additions & 0 deletions tree/SassRootNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class SassRootNode extends SassNode {
*/
public $extenders = array();

/**
* Extend_parent - for resolving extends across imported files.
*/
public $extend_parent = null;

/**
* Root SassNode constructor.
* @param SassParser Sass parser
Expand Down Expand Up @@ -81,11 +86,17 @@ public function render() {
}

public function extend($extendee, $selectors) {
if ($this->extend_parent && method_exists($this->extend_parent, 'extend')) {
return $this->extend_parent->extend($extendee, $selectors);
}
$this->extenders[$extendee] = (isset($this->extenders[$extendee])
? array_merge($this->extenders[$extendee], $selectors) : $selectors);
}

public function getExtenders() {
if ($this->extend_parent && method_exists($this->extend_parent, 'getExtenders')) {
return $this->extend_parent->getExtenders();
}
return $this->extenders;
}

Expand Down
4 changes: 2 additions & 2 deletions tree/SassRuleNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function render() {
else {
$properties[] = $child->render();
}
} // foreach
}

return $this->renderer->renderRule($this, $properties, $rules);
}
Expand All @@ -117,7 +117,7 @@ public function render() {
* $selector a selector or selector sequence that is to be extended
*/
public function extend() {
foreach ($this->root->extenders as $extendee=>$extenders) {
foreach ($this->root->getExtenders() as $extendee => $extenders) {
if ($this->isPsuedo($extendee)) {
$extendee = explode(':', $extendee);
$pattern = preg_quote($extendee[0]).'((\.[-\w]+)*):'.preg_quote($extendee[1]);
Expand Down

0 comments on commit 03af9f2

Please sign in to comment.