-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler-js.js
53 lines (50 loc) · 1.51 KB
/
handler-js.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
var Resource = require('./protolus-resource');
var Class = require('Classy');
var JavascriptHandler = new Class({
Extends : Resource.Handler,
initialize : function(options){
this.parent('js');
},
handle : function(options, callback){
options.body += "\n"+' //@sourceURL='+options.location+"\n"
callback(options.body);
},
tagProfile : function(){
return {
name : 'script',
attrs : {
},
target : 'src'
};
}
});
var JavascriptMainHandler = new Class({
Extends : Resource.Handler,
initialize : function(options){
this.parent('js')
},
handle : function(options, callback){
var text = options.body;
var lines = text.split("\n");
lines.push(' //@sourceURL='+options.location.replace('/./', '/'));
text = JSON.stringify(lines).replace( /\\/g, '\\\\').replace(/'/g, "\\'");
options.body = 'Protolus.register(\''+options.name+'\', \''+text+'\')';
callback(options.body);
},
tagProfile : function(){
return {
name : 'script',
attrs : {
},
target : 'src'
};
}
});
var instance = new JavascriptHandler();
Resource.registerHandler('js', instance);
JavascriptHandler.instance = instance;
var instance = new JavascriptMainHandler();
Resource.registerHandler('main', instance);
JavascriptMainHandler.instance = instance;
module.exports = JavascriptHandler;
module.exports.Main = JavascriptMainHandler;