-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
85 lines (63 loc) · 1.38 KB
/
index.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
if (typeof include === 'undefined' )
throw new Error('<atma-mask-optimize> should be loaded by the `atma` module.');
// `io.File` extension
if (global.io && io.File) {
io.File.middleware['mask'] = {
read: function(file, config){
if (config == null) {
config = global.app
&& app.current
&& app.current.tasks
&& app.current.tasks[0]
;
}
if (config == null || config.minify != true)
return;
if (typeof file.content !== 'string')
file.content = file.content.toString();
file.content = mask.stringify(file.content);
}
};
io
.File
.registerExtensions(obj_setProperty({}, 'mask', [ 'mask:read' ]))
;
}
// Http
var HttpHandler = Class({
Base: Class.Deferred,
process: function(req, res, config){
var url = req.url,
uri = new net.Uri(config.base).combine(url),
source
;
source = mask.stringify(io.File.read(uri, config));
this.resolve(source, 200, 'text/x-mask');
}
});
include.exports = {
register: function(rootConfig){
rootConfig.$extend({
server: {
handlers: {
'(.mask)': HttpHandler
}
}
});
}
};
function obj_setProperty(obj, prop, value){
obj[prop] = value;
return obj;
}
function obj_extend(target){
var imax = arguments.length,
i = 1,
obj;
for(; i < imax; i++){
obj = arguments[0];
for(var key in obj)
target[key] = obj[key]
}
return target;
}