Added collapsing (margin|padding|border-width) with 2 values into one, e.g. padding...
authorGoalSmashers <jakub@goalsmashers.com>
Sat, 17 Nov 2012 23:03:09 +0000 (23:03 +0000)
committerGoalSmashers <jakub@goalsmashers.com>
Sat, 17 Nov 2012 23:03:09 +0000 (23:03 +0000)
lib/clean.js
test/data/big-min.css
test/unit-test.js

index f010cf7..a4a1ddd 100644 (file)
@@ -159,7 +159,7 @@ var CleanCSS = {
     replace(/:0 0 0 0([^\.])/g, ':0$1');
     replace(/([: ,=\-])0\.(\d)/g, '$1.$2');
 
-    // same values into one
+    // 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;
@@ -167,6 +167,14 @@ var CleanCSS = {
         return match;
     });
 
+    // same 2 values into one
+    replace(/(padding|margin|border\-width):([\d\w\.%]+) ([\d\w\.%]+)([;}])/g, function(match, property, size1, size2, suffix) {
+      if (size1 === size2)
+        return property + ":" + size1 + suffix;
+      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)');
 
index 7e4793a..71d7f7f 100644 (file)
@@ -511,7 +511,7 @@ article .liste_carre_999{margin-top:5px}
 .fleuve .twit .texte_twit .nom,.article .twit .texte_twit .nom{display:block;color:#41c8f5;font-weight:700}
 .fleuve .grid_3.titre_video{font-weight:700}
 .fleuve section article{margin-bottom:0}
-.saisie{background-color:#f8f9fb;border:1px solid #b9c0c5;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;padding:3px 3px;font-size:1.2rem;color:#747b83;outline:0}
+.saisie{background-color:#f8f9fb;border:1px solid #b9c0c5;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;padding:3px;font-size:1.2rem;color:#747b83;outline:0}
 .saisie:focus{border-color:#8b9299}
 .radio_ou_checkbox,input[type="radio"],input[type="checkbox"]{cursor:pointer}
 input[type="radio"],input[type="checkbox"]{vertical-align:bottom;margin-bottom:.2rem}
index 193dec1..ed18a27 100644 (file)
@@ -265,18 +265,30 @@ vows.describe('clean-units').addBatch({
     ]
   }),
   'shorthands': cssContext({
-    'padding - same values': [
+    'padding - same values': [
       'div{padding:1px 1px 1px 1px}',
       'div{padding:1px}'
     ],
-    'margin - same values': [
+    'margin - same values': [
       'div{margin:1% 1% 1% 1%}',
       'div{margin:1%}'
     ],
-    'border-width - same values': [
+    'border-width - same values': [
       'div{border-width:1em 1em 1em 1em}',
       'div{border-width:1em}'
     ],
+    'padding - same 2 values': [
+      'div{padding:1px 1px}',
+      'div{padding:1px}'
+    ],
+    'margin - same 2 values': [
+      'div{margin:5% 5%}',
+      'div{margin:5%}'
+    ],
+    'border-width - same 2 values': [
+      'div{border-width:.5em .5em}',
+      'div{border-width:.5em}'
+    ],
     'different units': 'div{padding:1px 1em 1% 1rem}',
     'fractions': [
       'div{margin:.1em .1em .1em .1em}',