Skip to content

Commit

Permalink
Add SCSS support (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjjones authored and sindresorhus committed Jun 25, 2016
1 parent 6a0855f commit b472cdb
Show file tree
Hide file tree
Showing 15 changed files with 701 additions and 7 deletions.
17 changes: 14 additions & 3 deletions Autoprefixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@ def get_setting(view, key):
settings = sublime.load_settings('Autoprefixer.sublime-settings')
return settings.get(key)

def get_syntax(view):
return splitext(basename(view.settings().get('syntax')))[0];

def get_extension(view):
file_name = view.file_name();
return file_name and splitext(file_name)[1];

def is_css(view):
return splitext(basename(view.settings().get('syntax')))[0] == 'CSS'
return get_syntax(view) == 'CSS' or get_extension(view) == '.css'

def is_scss(view):
return get_syntax(view) in ('Sass', 'SCSS') or get_extension(view) == '.scss'


class AutoprefixerCommand(sublime_plugin.TextCommand):
Expand All @@ -46,7 +56,8 @@ def prefix(self, data):
try:
return node_bridge(data, BIN_PATH, [json.dumps({
'browsers': get_setting(self.view, 'browsers'),
'cascade': get_setting(self.view, 'cascade')
'cascade': get_setting(self.view, 'cascade'),
'is_css': is_css(self.view)
})])
except Exception as e:
sublime.error_message('Autoprefixer\n%s' % e)
Expand All @@ -61,5 +72,5 @@ def has_selection(self):

class AutoprefixerPreSaveCommand(sublime_plugin.EventListener):
def on_pre_save(self, view):
if get_setting(view, 'prefixOnSave') is True and is_css(view):
if get_setting(view, 'prefixOnSave') is True and (is_css(view) or is_scss(view)):
view.run_command('autoprefixer')
5 changes: 4 additions & 1 deletion autoprefixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ var getStdin = require('get-stdin');
var postcss = require('postcss');
var autoprefixer = require('autoprefixer');
var postcssSafeParser = require('postcss-safe-parser');
var postcssScssParser = require('postcss-scss');

getStdin().then(function (data) {
var opts = JSON.parse(process.argv[2]);

var postcssParser = opts.is_css ? postcssSafeParser : postcssScssParser;

postcss(autoprefixer(opts)).process(data, {
parser: postcssSafeParser
parser: postcssParser
})
.then(function (result) {
process.stdout.write(result.css);
Expand Down
27 changes: 27 additions & 0 deletions node_modules/postcss-scss/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions node_modules/postcss-scss/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions node_modules/postcss-scss/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions node_modules/postcss-scss/lib/scss-parse.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions node_modules/postcss-scss/lib/scss-parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions node_modules/postcss-scss/lib/scss-stringifier.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions node_modules/postcss-scss/lib/scss-stringify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions node_modules/postcss-scss/lib/scss-syntax.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b472cdb

Please sign in to comment.