1 | var jade = require('jade');
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | module.exports = function processor(content, attrs, scope) {
|
13 | if (!content) {
|
14 | return content;
|
15 | }
|
16 | var match = content.match(/^[^\n\S]+/);
|
17 | var space;
|
18 | if (match) {
|
19 | space = match[0].length;
|
20 |
|
21 | var regex = new Function('return (/^[^\\n\\S]{' + space + '}/gm)')();
|
22 | content = content.replace(regex, '');
|
23 | space = match[0];
|
24 | }
|
25 | render = jade.compile(content, {
|
26 | pretty: true
|
27 | });
|
28 | var data;
|
29 | if (attrs.data) {
|
30 |
|
31 | data = scope.execImport(attrs.data);
|
32 | if (typeof data === 'string') {
|
33 | data = new Function(
|
34 | 'return (' + data + ');'
|
35 | )();
|
36 | }
|
37 | }
|
38 | else {
|
39 | data = null;
|
40 | }
|
41 | content = render(data);
|
42 | if (space) {
|
43 | content = content.replace(/^/gm, space);
|
44 | }
|
45 | return content;
|
46 | }; |
\ | No newline at end of file |