From: GoalSmashers Date: Sat, 17 Nov 2012 22:50:23 +0000 (+0000) Subject: Added shortening same values in (padding|margin|border-width) - margin:1px 1px 1px... X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=cd15751966f7e582986996ebe7625a31ae8bab18;p=clean-css.git Added shortening same values in (padding|margin|border-width) - margin:1px 1px 1px 1px => margin:1px --- diff --git a/lib/clean.js b/lib/clean.js index 42560c1d..f010cf7e 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -159,6 +159,14 @@ var CleanCSS = { replace(/:0 0 0 0([^\.])/g, ':0$1'); replace(/([: ,=\-])0\.(\d)/g, '$1.$2'); + // same values into one + replace(/(padding|margin|border\-width):([\d\w\.%]+) ([\d\w\.%]+) ([\d\w\.%]+) ([\d\w\.%]+)/g, function(match, property, size1, size2, size3, size4) { + if (size1 === size2 && size1 === size3 && size1 === size4) + return property + ":" + size1; + else + return match; + }); + // restore rect(...) zeros syntax for 4 zeros replace(/rect\(\s?0(\s|,)0[ ,]0[ ,]0\s?\)/g, 'rect(0$10$10$10)'); diff --git a/test/unit-test.js b/test/unit-test.js index 2e062851..193dec1b 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -264,6 +264,25 @@ vows.describe('clean-units').addBatch({ 'div{clip:rect(0 0 0 10px)}' ] }), + 'shorthands': cssContext({ + 'padding - same values': [ + 'div{padding:1px 1px 1px 1px}', + 'div{padding:1px}' + ], + 'margin - same values': [ + 'div{margin:1% 1% 1% 1%}', + 'div{margin:1%}' + ], + 'border-width - same values': [ + 'div{border-width:1em 1em 1em 1em}', + 'div{border-width:1em}' + ], + 'different units': 'div{padding:1px 1em 1% 1rem}', + 'fractions': [ + 'div{margin:.1em .1em .1em .1em}', + 'div{margin:.1em}' + ] + }), 'floats': cssContext({ 'strips zero in fractions': [ 'a{ margin-bottom: 0.5em}',