Skip to content

Commit

Permalink
make plugin actually use scss formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
goodevil_git committed Feb 25, 2017
1 parent 426fcc9 commit 3c20fa0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
17 changes: 9 additions & 8 deletions CodeFormatter.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,17 @@
"eol": "\n" // EOL symbol
},

"codeformatter_scss_options":
{
"codeformatter_scss_options":
{
"syntaxes": "scss", // Indentation size
"format_on_save": false, // Format on save. Either a boolean (true/false) or a string regexp tested on filename. Example : "^((?!.min.|vendor).)*$"
"indent_size": 2, // Indentation size
"indent_char": " ", // Indentation character
"indent_with_tabs": false, // Indent with one tab (overrides indent_size and indent_char options)
"selector_separator_newline": true, // Add new lines after selector separators
"end_with_newline": true // Add new line of end in file
},
"indent_size": 2, // Indentation size
"indent_char": " ", // Indentation character
"indent_with_tabs": false, // Indent with one tab (overrides indent_size and indent_char options)
"selector_separator_newline": true, // Add new lines after selector separators
"newline_between_rules": true, // Add new line between rules
"end_with_newline": true // Add new line of end in file
},

"codeformatter_html_options":
{
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ Language specific options:
"indent_char": " ", // Indentation character
"indent_with_tabs": false, // Indent with one tab (overrides indent_size and indent_char options)
"selector_separator_newline": true, // Add new lines after selector separators
"newline_between_rules": true, // Add new line between rules
"end_with_newline": true // Add new line of end in file
}
```
Expand Down
10 changes: 8 additions & 2 deletions codeformatter/lib/scssbeautifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ def __init__(self):
self.indent_char = ' '
self.selector_separator_newline = True
self.end_with_newline = True
self.newline_between_rules = True

def __repr__(self):
return \
"""indent_size = %d
indent_char = [%s]
separate_selectors_newline = [%s]
end_with_newline = [%s]
newline_between_rules = [%s]
""" % (self.indent_size, self.indent_char,
self.separate_selectors, self.end_with_newline)
self.separate_selectors, self.end_with_newline, self.newline_between_rules)


def default_options():
Expand Down Expand Up @@ -259,13 +261,18 @@ def beautify(self):
if self.peek() == '}':
self.next()
printer.push(" {}")
printer.newLine()
if self.opts.newline_between_rules:
printer.newLine(True)
else:
printer.indent()
printer.openBracket()
elif self.ch == '}':
printer.outdent()
printer.closeBracket()
insideRule = False
if self.opts.newline_between_rules:
printer.newLine(True)
elif self.ch == ":":
self.eatWhitespace()
addWhitespace = not self.nextIsPseudoClass()
Expand Down Expand Up @@ -330,4 +337,3 @@ def beautify(self):
sweet_code = sweet_code[:-1]

return sweet_code

11 changes: 8 additions & 3 deletions codeformatter/scssformatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sublime
import subprocess

import cssbeautifier
import scssbeautifier

class ScssFormatter:
def __init__(self, formatter):
Expand All @@ -22,7 +22,7 @@ def format(self, text):

stderr = ""
stdout = ""
options = cssbeautifier.default_options()
options = scssbeautifier.default_options()

if ("indent_size" in self.opts and self.opts["indent_size"]):
options.indent_size = self.opts["indent_size"]
Expand Down Expand Up @@ -50,11 +50,16 @@ def format(self, text):
else:
options.end_with_newline = False

if ("newline_between_rules" in self.opts and self.opts["newline_between_rules"]):
options.newline_between_rules = True
else:
options.newline_between_rules = False




try:
stdout = cssbeautifier.beautify(text, options)
stdout = scssbeautifier.beautify(text, options)
except Exception as e:
stderr = str(e)

Expand Down
1 change: 1 addition & 0 deletions messages/install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ Language specific options:
"indent_char": " ", // Indentation character
"indent_with_tabs": false, // Indent with one tab (overrides indent_size and indent_char options)
"selector_separator_newline": true, // Add new lines after selector separators
"newline_between_rules": true, // Add new line between rules
"end_with_newline": true // Add new line of end in file
}
```
Expand Down

0 comments on commit 3c20fa0

Please sign in to comment.