Allows disabling rounding precision.
authorLukas Böcker <me@superlukas.com>
Wed, 15 Oct 2014 14:10:46 +0000 (16:10 +0200)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 19 Oct 2014 10:32:48 +0000 (11:32 +0100)
* Use `roundingPrecision: -1` or `--rounding-precision \\-1`.

History.md
README.md
bin/cleancss
lib/selectors/optimizers/simple.js
test/binary-test.js
test/integration-test.js
test/selectors/optimizers/simple-test.js

index 0114b1b..765dfb4 100644 (file)
@@ -3,6 +3,7 @@
 
 * Adds more granular control over compatibility settings.
 * Allows `target` option to be a path to a folder instead of a file.
+* Allows disabling rounding precision. By [@superlukas](https://github.com/superlukas).
 * Breaks 2.x compatibility for using CleanCSS as a function.
 * Reworks minification to tokenize first then minify.
   See [changes](https://github.com/jakubpawlowicz/clean-css/compare/b06f37d...dd8c14a).
index f58ed75..7e5908e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -85,7 +85,7 @@ cleancss [options] source-file, [source-file, ...]
 --skip-advanced                 Disable advanced optimizations - selector & property merging,
                                 reduction, etc.
 --skip-aggressive-merging       Disable properties merging based on their order
---rounding-precision [N]        Rounds pixel values to `N` decimal places, defaults to 2
+--rounding-precision [N]        Rounds to `N` decimal places. Defaults to 2. -1 disables rounding.
 -c, --compatibility [ie7|ie8]   Force compatibility mode (see Readme for advanced examples)
 -d, --debug                     Shows debug information (minification time & compression efficiency)
 ```
@@ -146,7 +146,7 @@ CleanCSS constructor accepts a hash as a parameter, i.e.,
 * `rebase` - set to false to skip URL rebasing
 * `relativeTo` - path to __resolve__ relative `@import` rules and URLs
 * `root` - path to __resolve__ absolute `@import` rules and __rebase__ relative URLs
-* `roundingPrecision` - Rounding precision, defaults to 2.
+* `roundingPrecision` - rounding precision; defaults to `2`; `-1` disables rounding
 * `target` - path to a folder or an output file to which __rebase__ all URLs
 
 ### How to use clean-css with build tools?
index b313228..666fae5 100755 (executable)
@@ -25,7 +25,7 @@ commands
   .option('--skip-rebase', 'Disable URLs rebasing')
   .option('--skip-advanced', 'Disable advanced optimizations - selector & property merging, reduction, etc.')
   .option('--skip-aggressive-merging', 'Disable properties merging based on their order')
-  .option('--rounding-precision [n]', 'Rounds pixel values to `N` decimal places, defaults to 2', parseInt)
+  .option('--rounding-precision [n]', 'Rounds to `N` decimal places. Defaults to 2. -1 disables rounding.', parseInt)
   .option('-c, --compatibility [ie7|ie8]', 'Force compatibility mode (see Readme for advanced examples)')
   .option('-t, --timeout [seconds]', 'Per connection timeout when fetching remote @imports (defaults to 5 seconds)')
   .option('-d, --debug', 'Shows debug information (minification time & compression efficiency)');
index ee5370a..511cc56 100644 (file)
@@ -103,7 +103,7 @@ function zeroMinifier(_, value) {
 }
 
 function precisionMinifier(_, value, precisionOptions) {
-  if (value.indexOf('.') === -1)
+  if (precisionOptions.value === -1 || value.indexOf('.') === -1)
     return value;
 
   return value
index 97acbd3..7e572e8 100644 (file)
@@ -311,6 +311,11 @@ exports.commandsSuite = vows.describe('binary commands').addBatch({
       'should keep 0 decimal places': function(error, stdout) {
         assert.equal(stdout, 'div{width:1px}');
       }
+    }),
+    disabled: pipedContext('div{width:0.12345px}', '--rounding-precision \\\\-1', {
+      'should keep all decimal places': function(error, stdout) {
+        assert.equal(stdout, 'div{width:.12345px}');
+      }
     })
   },
   'neighbour merging': {
index e8c119d..708ba77 100644 (file)
@@ -630,6 +630,12 @@ vows.describe('integration tests').addBatch({
       'div{transform:translateY(-418.5051px)}'
     ]
   }, { roundingPrecision: 4 }),
+  'floats disabled rounding': cssContext({
+    'does not round': [
+      'div{transform:translateY(-418.505123px)}',
+      'div{transform:translateY(-418.505123px)}'
+    ]
+  }, { roundingPrecision: -1 }),
   'colors': cssContext({
     'shorten rgb to standard hexadecimal format': [
       'a{ color:rgb(5, 10, 15) }',
index c7364f7..f12ed64 100644 (file)
@@ -334,6 +334,22 @@ vows.describe(SimpleOptimizer)
       ]
     }, { roundingPrecision: 3 })
   )
+  .addBatch(
+    propertyContext('rounding disabled', {
+      'pixels': [
+        'a{transform:translateY(123.31135px)}',
+        ['transform:translateY(123.31135px)']
+      ],
+      'percents': [
+        'a{left:20.1231%}',
+        ['left:20.1231%']
+      ],
+      'ems': [
+        'a{left:1.1231em}',
+        ['left:1.1231em']
+      ]
+    }, { roundingPrecision: -1 })
+  )
   .addBatch(
     propertyContext('units', {
       'pixels': [