Skip to content

Commit

Permalink
Added experimental support for beautifying CSS files. This feature wi…
Browse files Browse the repository at this point in the history
…ll remain undocumented and could break sometime in the future. Refs #27
  • Loading branch information
badsyntax committed Dec 13, 2013
1 parent beedb42 commit 9595a99
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 40 deletions.
25 changes: 18 additions & 7 deletions SassBeautify.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ class SassBeautifyCommand(sublime_plugin.TextCommand):
Our main SassBeautify ST text command.
'''

def run(self, edit, action='beautify', type=None):
def run(self, edit, action='beautify', convert_from_type=None):

self.action = action
self.type = type
self.convert_from_type = convert_from_type
self.settings = sublime.load_settings('SassBeautify.sublime-settings')

if self.check_file() != False:
Expand All @@ -93,7 +93,7 @@ def check_file(self):
return False

# Check the file has the correct extension before beautifying.
if self.get_ext() not in ['sass', 'scss']:
if self.get_type() not in ['sass', 'scss']:
sublime.error_message('Not a valid Sass file.')
return False

Expand Down Expand Up @@ -163,15 +163,15 @@ def get_cmd(self):
'''
Generate the sass command we'll use to beauitfy the sass.
'''
ext = self.get_ext()
filetype = self.get_type()

cmd = [
'sass-convert',
'--unix-newlines',
'--stdin',
'--indent', str(self.settings.get('indent')),
'--from', ext if self.action == 'beautify' else self.type,
'--to', ext
'--from', filetype if self.action == 'beautify' else self.convert_from_type,
'--to', filetype
]

# Convert underscores to dashes.
Expand All @@ -180,7 +180,7 @@ def get_cmd(self):

# Output the old-style ':prop val' property syntax.
# Only meaningful when generating Sass.
if self.settings.get('old') == True and ext == 'sass':
if self.settings.get('old') == True and filetype == 'sass':
cmd.append('--old')

return cmd
Expand All @@ -204,6 +204,17 @@ def get_ext(self):
(basename, ext) = os.path.splitext(self.view.file_name())
return ext.strip('.')

def get_type(self):
'''
Returns the file type.
'''
filetype = self.get_ext();
# Added experimental CSS support with issue #27.
# If this is a CSS file, then we're to treat it exactly like a SCSS file.
if self.action == 'beautify' and filetype == 'css':
filetype = 'scss'
return filetype

def get_text(self):
'''
Get the sass text from the Sublime view.
Expand Down
66 changes: 33 additions & 33 deletions SassBeautify.sublime-commands
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
[
{
"caption": "SassBeautify",
"command": "sass_beautify",
"args": {
"action": "beautify"
}
},
{
"caption": "SassBeautify: Convert from CSS to current type",
"command": "sass_beautify",
"args": {
"action": "convert",
"type": "css"
}
},
{
"caption": "SassBeautify: Convert from SCSS to current type",
"command": "sass_beautify",
"args": {
"action": "convert",
"type": "scss"
}
},
{
"caption": "SassBeautify: Convert from SASS to current type",
"command": "sass_beautify",
"args": {
"action": "convert",
"type": "sass"
}
}
]
[
{
"caption": "SassBeautify",
"command": "sass_beautify",
"args": {
"action": "beautify"
}
},
{
"caption": "SassBeautify: Convert from CSS to current type",
"command": "sass_beautify",
"args": {
"action": "convert",
"convert_from_type": "css"
}
},
{
"caption": "SassBeautify: Convert from SCSS to current type",
"command": "sass_beautify",
"args": {
"action": "convert",
"convert_from_type": "scss"
}
},
{
"caption": "SassBeautify: Convert from SASS to current type",
"command": "sass_beautify",
"args": {
"action": "convert",
"convert_from_type": "sass"
}
}
]

0 comments on commit 9595a99

Please sign in to comment.