From: Lukas Böcker Date: Wed, 15 Oct 2014 14:10:46 +0000 (+0200) Subject: Allows disabling rounding precision. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=47b9e658784eb3cfa7b590c07e96b7481a65c9f6;p=clean-css.git Allows disabling rounding precision. * Use `roundingPrecision: -1` or `--rounding-precision \\-1`. --- diff --git a/History.md b/History.md index 0114b1bc..765dfb42 100644 --- a/History.md +++ b/History.md @@ -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). diff --git a/README.md b/README.md index f58ed753..7e5908e6 100644 --- 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? diff --git a/bin/cleancss b/bin/cleancss index b3132284..666fae54 100755 --- a/bin/cleancss +++ b/bin/cleancss @@ -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)'); diff --git a/lib/selectors/optimizers/simple.js b/lib/selectors/optimizers/simple.js index ee5370a6..511cc56f 100644 --- a/lib/selectors/optimizers/simple.js +++ b/lib/selectors/optimizers/simple.js @@ -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 diff --git a/test/binary-test.js b/test/binary-test.js index 97acbd3e..7e572e84 100644 --- a/test/binary-test.js +++ b/test/binary-test.js @@ -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': { diff --git a/test/integration-test.js b/test/integration-test.js index e8c119df..708ba77f 100644 --- a/test/integration-test.js +++ b/test/integration-test.js @@ -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) }', diff --git a/test/selectors/optimizers/simple-test.js b/test/selectors/optimizers/simple-test.js index c7364f76..f12ed648 100644 --- a/test/selectors/optimizers/simple-test.js +++ b/test/selectors/optimizers/simple-test.js @@ -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': [