0.x.js
3.4 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Generated by CoffeeScript 1.12.1
(function() {
var Adapter, Stylus, flatten, nodefn, sourcemaps,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Adapter = require('../../adapter_base');
sourcemaps = require('../../sourcemaps');
nodefn = require('when/node/function');
flatten = require('lodash.flatten');
Stylus = (function(superClass) {
extend(Stylus, superClass);
function Stylus() {
return Stylus.__super__.constructor.apply(this, arguments);
}
Stylus.prototype.name = 'stylus';
Stylus.prototype.extensions = ['styl'];
Stylus.prototype.output = 'css';
Stylus.prototype._render = function(str, options) {
var base, defines, i, imports, includes, j, k, l, len, len1, len2, m, obj, plugins, rawDefines, sets, v;
sets = {};
defines = {};
rawDefines = {};
includes = [];
imports = [];
plugins = [];
if (options.sourcemap === true) {
options.sourcemap = {
comment: false
};
}
for (k in options) {
v = options[k];
switch (k) {
case 'define':
Object.assign(defines, v);
break;
case 'rawDefine':
Object.assign(rawDefines, v);
break;
case 'include':
includes.push(v);
break;
case 'import':
imports.push(v);
break;
case 'use':
plugins.push(v);
break;
case 'url':
if (typeof v === 'string') {
obj = {};
obj[v] = this.engine.url();
Object.assign(defines, obj);
} else {
obj = {};
obj[v.name] = this.engine.url({
limit: v.limit != null ? v.limit : 30000,
paths: v.paths || []
});
Object.assign(defines, obj);
}
break;
default:
sets[k] = v;
}
}
includes = flatten(includes);
imports = flatten(imports);
plugins = flatten(plugins);
base = this.engine(str);
for (k in sets) {
v = sets[k];
base.set(k, v);
}
for (k in defines) {
v = defines[k];
base.define(k, v);
}
for (k in rawDefines) {
v = rawDefines[k];
base.define(k, v, true);
}
for (j = 0, len = includes.length; j < len; j++) {
i = includes[j];
base.include(i);
}
for (l = 0, len1 = imports.length; l < len1; l++) {
i = imports[l];
base["import"](i);
}
for (m = 0, len2 = plugins.length; m < len2; m++) {
i = plugins[m];
base.use(i);
}
return nodefn.call(base.render.bind(base)).then(function(res) {
return obj = {
result: res
};
}).then(function(obj) {
if (base.sourcemap) {
return sourcemaps.inline_sources(base.sourcemap).then(function(map) {
obj.sourcemap = map;
return obj;
});
} else {
return obj;
}
});
};
return Stylus;
})(Adapter);
module.exports = Stylus;
}).call(this);