forked from csscomb/csscomb.chocmixin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.js
55 lines (42 loc) · 1.25 KB
/
init.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*!
* CSScomb mixin for Chocolat
* Copyright(c) 2012 Nicholas Penree <[email protected]>
* MIT Licensed
*/
/**
* Module dependencies.
*/
var spawn = require('child_process').spawn;
/**
* Hook up menu items.
*/
Hooks.addMenuItem('Actions/CSS/Sort via CSScomb', 'control-shift-c', function() {
var output = '', err = '', sel, text, comb, scope;
Recipe.run(function(recipe) {
sel = (!recipe.selection.length)? new Range(0, recipe.length) : recipe.selection;
text = recipe.textInRange(sel);
scope = Document.current().rootScope();
if (!text || [ 'css.source', 'less.source', 'sass.source' ].indexOf(scope) === -1) {
Alert.beep();
return;
}
comb = spawn('php', [ __dirname + '/run.php', text ]);
comb.stdout.on('data', function (data) {
output += data.toString('utf8');
});
comb.stderr.on('data', function (data) {
err += data.toString('utf8');
});
comb.on('exit', function (code) {
if (code !== 0) return undefined;
if (err) {
Alert.show('Unable to sort via CSScomb.', err, [ 'OK' ]);
return;
}
Recipe.run(function(r) {
r.replaceTextInRange(sel, output);
});
});
return undefined;
});
});