diff --git a/README.md b/README.md index 6605518..abbc52c 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,8 @@ The following settings can be adjusted: "newlineBetweenSelectors": false, // Use single quotes everywhere "useSingleQuotes": false + // Remove the leading zero for numeric values with a decimal point + "leadingZero": false } ``` @@ -102,7 +104,7 @@ In your keymap file (Preferences >> Key bindings - User), add a custom key bindi ## Issues with ruby, Sass and your PATH -If you installed ruby and sass via a version manager tool like [RVM](https://rvm.io/), [rbenv](https://github.com/sstephenson/rbenv) or via an installer like [ruby installer](http://rubyinstaller.org/), then you're likely to encounter issues with running `sass-convert` from Sublime Text. +If you installed ruby and sass via a version manager tool like [RVM](https://rvm.io/), [rbenv](https://github.com/sstephenson/rbenv) or via an installer like [ruby installer](http://rubyinstaller.org/), then you're likely to encounter issues with running `sass-convert` from Sublime Text. ### Compatibility with RVM/rbenv @@ -128,7 +130,7 @@ Please [create an issue](https://github.com/badsyntax/SassBeautify/issues) if yo ## Thanks -Thanks to the [contributors](https://github.com/badsyntax/SassBeautify/graphs/contributors) and to all the people +Thanks to the [contributors](https://github.com/badsyntax/SassBeautify/graphs/contributors) and to all the people who have tested and reported issues. ## License diff --git a/SassBeautify.py b/SassBeautify.py index d26f30e..3f88349 100644 --- a/SassBeautify.py +++ b/SassBeautify.py @@ -173,11 +173,14 @@ def insert_newline_between_capturing_parentheses(m): content = re.sub(re.compile('(;.*|}.*)(\n +//.*\n.+[{,])$', re.MULTILINE), insert_newline_between_capturing_parentheses, content) return content - + def use_single_quotes(self, content): content = content.replace('"', '\'') return content + def remove_leading_zero(self, content): + return re.sub(r'([\( ]+)0\.(\d*)', r'\1.\2', content) + def check_thread(self, thread, i=0, dir=1): ''' Checks if the thread is still running. @@ -229,10 +232,13 @@ def handle_process(self, returncode, output, error): if self.settings.get('newlineBetweenSelectors', False): output = self.beautify_newlines(output) - + if self.settings.get('useSingleQuotes', False): output = self.use_single_quotes(output) + if self.settings.get('leadingZero', False): + output = self.remove_leading_zero(output) + self.viewport_pos = self.view.viewport_position() self.selection = self.view.sel()[0] diff --git a/SassBeautify.sublime-settings b/SassBeautify.sublime-settings index 026e28d..7e7b33a 100644 --- a/SassBeautify.sublime-settings +++ b/SassBeautify.sublime-settings @@ -5,5 +5,6 @@ "path": false, "beautifyOnSave": false, "inlineComments": false, - "newlineBetweenSelectors": false + "newlineBetweenSelectors": false, + "leadingZero": false } diff --git a/tests/test.py b/tests/test.py index 0fbc156..c363259 100644 --- a/tests/test.py +++ b/tests/test.py @@ -211,3 +211,27 @@ def test_skip_insert_newline_2(self): } """)) + +class test_internal_function_remove_leading_zero(TestCase): + + # check that leading zeros are removed properly + def test_leading_zero(self): + beautified = SassBeautifyCommandInstance.remove_leading_zero(textwrap.dedent("""\ + + .ClassA { + -webkit-transform: scale(0.9); + transition: -webkit-transform 0.1s; + background-color: rgba(67, 67, 67, 0.5); + } + + """)) + + self.assertEqual(beautified, textwrap.dedent("""\ + + .ClassA { + -webkit-transform: scale(.9); + transition: -webkit-transform .1s; + background-color: rgba(67, 67, 67, .5); + } + + """)) \ No newline at end of file