From: Jakub Pawlowicz Date: Sun, 29 Jun 2014 22:16:46 +0000 (+0100) Subject: Replaces same horizontal & vertical value in border-radius. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=a197e462a780a1777f72d9903e0ab9e6b128bc85;p=clean-css.git Replaces same horizontal & vertical value in border-radius. * border-radius:1em/1em can be turned into border-radius:1em. --- diff --git a/History.md b/History.md index b59842d4..e42ccb7a 100644 --- a/History.md +++ b/History.md @@ -2,6 +2,7 @@ ================== * Adds removing extra spaces around / in border-radius. +* Adds replacing same horizontal & vertical value in border-radius. * Fixed issue [#305](https://github.com/GoalSmashers/clean-css/issues/305) - allows width keywords in border-width. [2.2.4 / 2014-06-27](https://github.com/GoalSmashers/clean-css/compare/v2.2.3...v2.2.4) diff --git a/lib/clean.js b/lib/clean.js index a4145068..d5d41685 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -349,6 +349,16 @@ var minify = function(data, callback) { // replace ' / ' in border-*-radius with '/' replace(/(border-\w+-\w+-radius:\S+)\s+\/\s+/g, '$1/'); + // replace same H/V values in border-radius + replace(/(border-\w+-\w+-radius):([^;\}]+)/g, function (match, property, value) { + var parts = value.split('/'); + + if (parts.length > 1 && parts[0] == parts[1]) + return property + ':' + parts[0]; + else + return match; + }); + replace(function restoreUrls() { data = urlsProcessor.restore(data); }); diff --git a/lib/properties/processable.js b/lib/properties/processable.js index f1f3fc1e..35fa82b4 100644 --- a/lib/properties/processable.js +++ b/lib/properties/processable.js @@ -529,7 +529,8 @@ module.exports = (function () { var result = putTogether.takeCareOfInherit(putTogether.fourUnits)(prop, tokens, isImportant); if (verticalTokens.length > 0) { var verticalResult = putTogether.takeCareOfInherit(putTogether.fourUnits)(prop, verticalTokens, isImportant); - result.value += '/' + verticalResult.value; + if (result.value != verticalResult.value) + result.value += '/' + verticalResult.value; } return result; diff --git a/test/unit-test.js b/test/unit-test.js index 31cdbe51..84fd2a1a 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -778,6 +778,28 @@ vows.describe('clean-units').addBatch({ 'keeps rgba(0,255,0,.5)': 'a{color:rgba(0,255,0,.5)}', 'keeps hsla(120,100%,50%,.5)': 'a{color:hsla(120,100%,50%,.5)}' }), + 'border-radius': cssContext({ + 'border radius H+V 0/0': [ + 'a{border-radius:0 / 0}', + 'a{border-radius:0}' + ], + 'border radius side H+V 0/0': [ + 'a{border-top-left-radius:0 / 0}', + 'a{border-top-left-radius:0}' + ], + 'border radius H+V same values': [ + 'a{border-radius:5px / 5px}', + 'a{border-radius:5px}' + ], + 'border radius side H+V same values': [ + 'a{border-top-left-radius:1em / 1em}', + 'a{border-top-left-radius:1em}' + ], + 'border radius H+V same expanded values': [ + 'a{border-radius:5px 5px 5px 5px / 5px 5px}', + 'a{border-radius:5px}' + ] + }), 'shortening colors': colorShorteningContext(), 'font weights': cssContext({ 'font-weight:normal to 400': [ @@ -1953,8 +1975,8 @@ title']{display:block}", 'a{outline:-webkit-focus-ring-color auto 5px}' ], 'border radius side H+V': [ - 'a{border-top-left-radius:1em / 1em}', - 'a{border-top-left-radius:1em/1em}' + 'a{border-top-left-radius:2em / 1em}', + 'a{border-top-left-radius:2em/1em}' ], 'border radius expanded H+V': [ 'a{border-radius:1em 1em 1em 1em / 2em 2em 2em 2em}',