Fixes #517 - turning off color optimizations.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 4 May 2015 09:20:35 +0000 (10:20 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 4 May 2015 09:20:35 +0000 (10:20 +0100)
With `-properties.colors` / `properties: { colors: false }` switch
it's possible to turn off all color optimizations now.

History.md
README.md
lib/selectors/optimizers/simple.js
lib/utils/compatibility.js
test/selectors/optimizers/simple-test.js
test/utils/compatibility-test.js

index c749921..9f0ab96 100644 (file)
@@ -9,6 +9,7 @@
 * Moves URL rebasing & rewriting into lib/urls.
 * Fixed issue [#436](https://github.com/jakubpawlowicz/clean-css/issues/436) - refactors URI rewriting.
 * Fixed issue [#448](https://github.com/jakubpawlowicz/clean-css/issues/448) - rebasing no protocol URIs.
+* Fixed issue [#517](https://github.com/jakubpawlowicz/clean-css/issues/517) - turning off color optimizations.
 * Fixed issue [#542](https://github.com/jakubpawlowicz/clean-css/issues/542) - space after closing brace in IE.
 
 [3.2.7 / 2015-05-03](https://github.com/jakubpawlowicz/clean-css/compare/v3.2.6...v3.2.7)
index 4fddbc6..e554206 100644 (file)
--- a/README.md
+++ b/README.md
@@ -306,6 +306,7 @@ Since clean-css 3 a fine grained control is available over
 with the following options available:
 
 * `'[+-]colors.opacity'` - - turn on (+) / off (-) `rgba()` / `hsla()` declarations removal
+* `'[+-]properties.colors'` - turn on / off any color optimizations
 * `'[+-]properties.iePrefixHack'` - turn on / off IE prefix hack removal
 * `'[+-]properties.ieSuffixHack'` - turn on / off IE suffix hack removal
 * `'[+-]properties.backgroundSizeMerging'` - turn on / off background-size merging into shorthand
index 428c9a5..d73a1f2 100644 (file)
@@ -259,7 +259,8 @@ function optimizeBody(properties, options) {
         value = zeroDegMinifier(name, value);
         value = unitMinifier(name, value, options.unitsRegexp);
       }
-      value = colorMininifier(name, value, options.compatibility);
+      if (options.compatibility.properties.colors)
+        value = colorMininifier(name, value, options.compatibility);
 
       property[j][0] = value;
     }
index 3ac5a5c..ff1823a 100644 (file)
@@ -7,6 +7,7 @@ var DEFAULTS = {
     },
     properties: {
       backgroundSizeMerging: false, // background-size to shorthand
+      colors: true, // any kind of color transformations, like `#ff00ff` to `#f0f` or `#fff` into `red`
       iePrefixHack: false, // underscore / asterisk prefix hacks on IE
       ieSuffixHack: false, // \9 suffix hacks on IE
       merging: true, // merging properties into one
@@ -29,6 +30,7 @@ var DEFAULTS = {
     },
     properties: {
       backgroundSizeMerging: false,
+      colors: true,
       iePrefixHack: true,
       ieSuffixHack: true,
       merging: false,
@@ -51,6 +53,7 @@ var DEFAULTS = {
     },
     properties: {
       backgroundSizeMerging: false,
+      colors: true,
       iePrefixHack: true,
       ieSuffixHack: true,
       merging: false,
index c6314f4..a972598 100644 (file)
@@ -260,6 +260,22 @@ vows.describe(SimpleOptimizer)
       ]
     }, { compatibility: 'ie8' })
   )
+  .addBatch(
+    propertyContext('colors - no optimizations', {
+      'long hex into short': [
+        'a{color:#ff00ff}',
+        [['color', '#ff00ff']]
+      ],
+      'short hex into name': [
+        'a{color:#f00}',
+        [['color', '#f00']]
+      ],
+      'name into hex': [
+        'a{color:white}',
+        [['color', 'white']]
+      ]
+    }, { compatibility: { properties: { colors: false } } })
+  )
   .addBatch(
     propertyContext('@filter', {
       'spaces after comma': [
index b4c87f2..36201bb 100644 (file)
@@ -9,6 +9,7 @@ vows.describe(Compatibility)
         return new Compatibility({}).toOptions();
       },
       'gets default options': function(options) {
+        assert.isTrue(options.properties.colors);
         assert.isFalse(options.properties.iePrefixHack);
         assert.isFalse(options.properties.ieSuffixHack);
         assert.isFalse(options.selectors.adjacentSpace);
@@ -55,6 +56,7 @@ vows.describe(Compatibility)
         return new Compatibility('ie8').toOptions();
       },
       'gets template options': function(options) {
+        assert.isTrue(options.properties.colors);
         assert.isTrue(options.properties.iePrefixHack);
         assert.isTrue(options.properties.ieSuffixHack);
         assert.isFalse(options.selectors.adjacentSpace);
@@ -74,6 +76,7 @@ vows.describe(Compatibility)
         return new Compatibility('ie7').toOptions();
       },
       'gets template options': function(options) {
+        assert.isTrue(options.properties.colors);
         assert.isTrue(options.properties.iePrefixHack);
         assert.isTrue(options.properties.ieSuffixHack);
         assert.isTrue(options.selectors.ie7Hack);