Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to trim leading zero from numeric values with a decimal point #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand All @@ -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

Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions SassBeautify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]

Expand Down
3 changes: 2 additions & 1 deletion SassBeautify.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"path": false,
"beautifyOnSave": false,
"inlineComments": false,
"newlineBetweenSelectors": false
"newlineBetweenSelectors": false,
"leadingZero": false
}
24 changes: 24 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

"""))