Fixed converting #f00 to red in borders and gradients.
authorJakub Pawlowicz <jakub@goalsmashers.com>
Sun, 25 Sep 2011 10:33:22 +0000 (12:33 +0200)
committerJakub Pawlowicz <jakub@goalsmashers.com>
Sun, 25 Sep 2011 10:33:22 +0000 (12:33 +0200)
lib/clean.js
test/unit-test.js

index 39ae837..88a13ad 100644 (file)
@@ -93,7 +93,7 @@ var CleanCSS = {
       if (CleanCSS.colors[colorName]) return property + ':' + CleanCSS.colors[colorName];
       else return match;
     })
-    replace(/color:#f00/g, 'color:red') // replace #f00 with red as it's shorter
+    replace(/([: ,\(])#f00/g, '$1red') // replace #f00 with red as it's shorter
     replace(/font\-weight:(\w+)/g, function(match, weight) { // replace font weight with numerical value
       if (weight == 'normal') return 'font-weight:400';
       else if (weight == 'bold') return 'font-weight:700';
index 659a23a..1145e31 100644 (file)
@@ -211,10 +211,22 @@ vows.describe('clean-units').addBatch({
       'a{color:white;border-color:black;background-color:fuchsia}p{background:yellow}',
       'a{color:#fff;border-color:#000;background-color:#f0f}p{background:#ff0}'
     ],
-    'hex value to color name': [
+    'hex value to color name if shorter': [
       'p{color:#f00}',
       'p{color:red}'
     ],
+    'hex value to color name in borders': [
+      'p{border:1px solid #f00}',
+      'p{border:1px solid red}'
+    ],
+    'hex value to color name in gradients': [
+      'p{background:-moz-linear-gradient(-90deg,#000,#f00)}',
+      'p{background:-moz-linear-gradient(-90deg,#000,red)}'
+    ],
+    'hex value to color name in gradients #2': [
+      'p{background:-webkit-gradient(linear, left top, left bottom, from(#000), to(#f00))}',
+      'p{background:-webkit-gradient(linear,left top,left bottom,from(#000),to(red))}'
+    ],
     'border color': [
       'p{border:1px solid #f94311}',
       'p{border:1px solid #f94311}'