forked from CodeboxIDE/package-coffeescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (29 loc) · 865 Bytes
/
Copy pathindex.js
File metadata and controls
33 lines (29 loc) · 865 Bytes
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
var coffeeScript = require("coffee-script");
var commands = codebox.require("core/commands");
var File = codebox.require("models/file");
commands.register({
id: "coffeescript.preview",
title: "CoffeeScript: Preview",
context: ["editor"],
shortcuts: [
"ctrl+shift+c"
],
run: function(args, ctx) {
var name = ctx.editor.model.get("name").replace(ctx.editor.model.getExtension(), ".js");
var code, error;
try {
code = coffeeScript.compile(ctx.editor.getContent());
} catch (e) {
error = e;
code = e.toString();
name = "Error at compilation";
}
var f = File.buffer(name, code);
return commands.run("file.open", {
file: f
})
.then(function() {
if (error) throw error;
});
}
});