Permalink
Browse files

Fixed vendor prefixes

  • Loading branch information...
1 parent dbe9d2a commit 125e098ed33f4f707bdbd4a17cdb00e75cbb7e74 @oscarotero committed Jul 9, 2012
Showing with 20 additions and 11 deletions.
  1. +12 −4 Stylecow/Css.php
  2. +8 −7 Stylecow/Plugins/VendorPrefixes.php
View
@@ -244,19 +244,27 @@ public function executeRecursive ($callback, $contextData = null) {
/**
* Removes all properties and children with a vendor that don't match with the specified.
*
- * @param string $vendor The vendor to filter (all vendors that don't match with this will be removed)
+ * @param string $keep The vendor to keep (null to keep the first vendor found, empty string to don't keep any vendor.)
*/
- public function filterVendor ($vendor) {
+ public function resolveVendors ($keep = null) {
+ if (($keep === null) && !empty($this->selector->vendor)) {
+ $keep = $this->selector->vendor;
+ }
+
if ($this->properties) {
foreach ($this->properties as $k => $property) {
- if (!empty($property->vendor) && ($property->vendor !== $vendor)) {
+ if (($keep !== null) && !empty($property->vendor) && ($property->vendor !== $keep)) {
unset($this->properties[$k]);
}
}
}
foreach ($this as $child) {
- $child->filterVendor($vendor);
+ if (($keep !== null) && !empty($child->selector->vendor) && ($child->selector->vendor !== $keep)) {
+ $child->removeFromParent();
+ } else {
+ $child->resolveVendors($keep);
+ }
}
}
@@ -204,14 +204,14 @@ static public function apply (Css $css) {
foreach (VendorPrefixes::$values[$property->name] as $value => $vendors) {
if (strpos($property->value, $value) !== false) {
foreach ($vendors as $vendor) {
- $newValue = preg_replace('/([^\w-])('.preg_quote($value, '/').')\(/', '\\1-'.$vendor.'-'.$value.'(', $property->value);
+ $newValue = preg_replace('/(^|[^\w-])('.preg_quote($value, '/').')([^\w]|$)/', '\\1-'.$vendor.'-'.$value.'\\3', $property->value);
if (!$code->hasProperty($property->name, $newValue)) {
$newProperty = clone $property;
$newProperty->value = $newValue;
$newProperty->vendor = $vendor;
- $code->addProperty($newProperty, $property->getPositionInParent() + 1);
+ $code->addProperty($newProperty, $property->getPositionInParent() - 1);
}
}
}
@@ -229,7 +229,7 @@ static public function apply (Css $css) {
$newProperty->value = $newValue;
$newProperty->vendor = $vendor;
- $code->addProperty($newProperty, $property->getPositionInParent() + 1);
+ $code->addProperty($newProperty, $property->getPositionInParent() - 1);
}
}
}
@@ -250,9 +250,8 @@ static public function apply (Css $css) {
$newCode = clone $code;
$newCode->selector->set(str_replace($selector, $vendor_selector, $code->selector->get()));
$newCode->selector->vendor = $vendor;
- $newCode->filterVendor($vendor);
- $code->parent->addChild($newCode, $code->getPositionInParent() + 1);
+ $code->parent->addChild($newCode, $code->getPositionInParent() - 1);
}
}
});
@@ -268,11 +267,13 @@ static public function apply (Css $css) {
$newCode = clone $code;
$newCode->selector->vendor = $vendor;
$newCode->selector->type = $type;
- $newCode->filterVendor($vendor);
- $code->parent->addChild($newCode, $code->getPositionInParent() + 1);
+ $code->parent->addChild($newCode, $code->getPositionInParent() - 1);
}
});
+
+ //Resolve and simplify the vendors
+ $css->resolveVendors();
}

0 comments on commit 125e098

Please sign in to comment.