From 7f661f1e157a59022041a453195b75c5406e321d Mon Sep 17 00:00:00 2001 From: GoalSmashers Date: Mon, 28 Jan 2013 17:41:18 +0100 Subject: [PATCH] Fixes #52 - stripping fraction zeros if not needed. --- lib/clean.js | 5 +++++ test/data/big-min.css | 4 ++-- test/unit-test.js | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/clean.js b/lib/clean.js index c0035f11..e0a3e1de 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -193,6 +193,11 @@ 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'); + // fraction zeros removal + replace(/\.([1-9]*)0+(\D)/g, function(match, nonZeroPart, suffix) { + return (nonZeroPart ? '.' : '') + nonZeroPart + suffix; + }); + // restore 0% in hsl/hsla replace(/(hsl|hsla)\(([^\)]+)\)/g, function(match, colorFunction, colorDef) { var tokens = colorDef.split(','); diff --git a/test/data/big-min.css b/test/data/big-min.css index dbf18681..55876d0c 100644 --- a/test/data/big-min.css +++ b/test/data/big-min.css @@ -187,7 +187,7 @@ body{font-size:1.3rem;font-size:13px;line-height:140%;font-family:arial,sans-ser a{color:#036;text-decoration:none;cursor:pointer} a:hover,a:focus,a:active,.lien_focus,.flashy{color:#129af0} .bg_fonce a{color:#129af0;opacity:.85} -.bg_fonce a:hover,.bg_fonce a:focus{opacity:1.0} +.bg_fonce a:hover,.bg_fonce a:focus{opacity:1} .obf{cursor:pointer;color:#036} .lien_interne,.lien_interne:hover{color:#000} p{margin:0} @@ -754,7 +754,7 @@ img[height="97"]+.ico29x29{bottom:6%;left:3.5%} .conteneur_carrousel .repere:hover,.conteneur_carrousel .repere.actif{background-position:-11px -24px;cursor:pointer} .conteneur_carrousel img{display:block;border:0} .portfolio_appel_revolutionnaire.conteneur_carrousel .navigation .reperes,.portfolio_appel_revolutionnaire .portfolio_data_container h2{display:none} -.portfolio_appel_revolutionnaire .portfolio_data_container{position:absolute;left:0;right:0;bottom:0;background:#000;background:rgba(0,0,0,.8);color:#fff;text-shadow:0 1px 0 #000;padding:16px;-ms-filter:"alpha(Opacity=0)";opacity:.0;-webkit-transition:opacity 1s;-moz-transition:opacity 1s;-o-transition:opacity 1s;transition:opacity 1s} +.portfolio_appel_revolutionnaire .portfolio_data_container{position:absolute;left:0;right:0;bottom:0;background:#000;background:rgba(0,0,0,.8);color:#fff;text-shadow:0 1px 0 #000;padding:16px;-ms-filter:"alpha(Opacity=0)";opacity:0;-webkit-transition:opacity 1s;-moz-transition:opacity 1s;-o-transition:opacity 1s;transition:opacity 1s} .portfolio_appel_revolutionnaire .elt.shown .portfolio_data_container{-ms-filter:"alpha(Opacity=80)";opacity:.8} .portfolio_appel_revolutionnaire .portfolio_data_container .credits{opacity:.5;padding-left:4px} .portfolio_appel_revolutionnaire .carrousel .elt{width:644px;height:322px} diff --git a/test/unit-test.js b/test/unit-test.js index f8747661..edd77d6d 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -390,6 +390,27 @@ vows.describe('clean-units').addBatch({ 'not strips zero in fractions of numbers greater than zero': [ 'a{ margin-bottom: 20.5em}', 'a{margin-bottom:20.5em}' + ], + 'strip fraction zero #1': [ + 'a{opacity:1.0}', + 'a{opacity:1}' + ], + 'strip fraction zero #2': [ + 'a{opacity:15.000%}', + 'a{opacity:15%}' + ], + 'strip fraction zero #3': [ + 'a{padding:15.55000em}', + 'a{padding:15.55em}' + ], + 'strip fraction zero #4': 'a{padding:15.101em}', + 'strip fraction zero #5': [ + 'a{border-width:0.20em 20.30em}', + 'a{border-width:.2em 20.3em}' + ], + 'strip fraction zeros': [ + 'div{margin:1.000em 2.00em 3.100em 4.01em}', + 'div{margin:1em 2em 3.1em 4.01em}' ] }), 'colors': cssContext({ -- 2.34.1