Fixed #32 - hsl/hsla colors processing.
authorGoalSmashers <jakub@goalsmashers.com>
Thu, 29 Nov 2012 22:26:31 +0000 (22:26 +0000)
committerGoalSmashers <jakub@goalsmashers.com>
Thu, 29 Nov 2012 22:26:31 +0000 (22:26 +0000)
lib/clean.js
test/unit-test.js

index d9bb4fd..3188753 100644 (file)
@@ -144,6 +144,14 @@ var CleanCSS = {
     replace(/(\s|:|,)0(px|em|ex|cm|mm|in|pt|pc|%)/g, '$1' + '0');
     replace(/rect\(0(px|em|ex|cm|mm|in|pt|pc|%)/g, 'rect(0');
 
+    // restore 0% in hsl/hsla
+    replace(/(hsl|hsla)\(([^\)]+)\)/g, function(match, colorFunction, colorDef) {
+      var tokens = colorDef.split(',');
+      if (tokens[1] == "0") tokens[1] = '0%';
+      if (tokens[2] == "0") tokens[2] = '0%';
+      return colorFunction + "(" + tokens.join(',') + ")";
+    });
+
     // none to 0
     replace(/(border|border-top|border-right|border-bottom|border-left|outline):none/g, '$1:0');
 
index b08cb65..1ba9cea 100644 (file)
@@ -304,7 +304,11 @@ vows.describe('clean-units').addBatch({
       'p{border:1px solid #f94311}'
     ],
     'colors and colons': 'a{background-image:linear-gradient(top,red,#e6e6e6)}',
-    'colors and parentheses': 'a{background-image:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#e6e6e6))}'
+    'colors and parentheses': 'a{background-image:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#e6e6e6))}',
+    'hsl percents': 'a{color:hsl(1,0%,0%)}',
+    'hsla percents': 'a{color:hsl(1,0%,0%)}',
+    'hsl one percent': 'a{color:hsl(80,100%,0%)}',
+    'hsla custom ': 'a{color:hsl(80,30%,50%,.5)}',
   }),
   'font weights': cssContext({
     'font-weight:normal to 400': [