UNPKG

834 BJavaScriptView Raw
1var ejs = require('ejs');
2
3/**
4 * ejs 模板渲染
5 *
6 * @param {string} content 文本内容
7 * @param {Object} attrs 属性
8 * @param {string} attrs.data 数据项
9 * @param {Object} scope 作用域
10 * @param {Function} scope.execImport 导入数据
11 * @param {Function} scope.compile 二次编译 jdists 文本
12 */
13module.exports = function processor(content, attrs, scope) {
14 if (!content) {
15 return content;
16 }
17 var render = ejs.compile(content);
18 var data;
19 if (attrs.data) {
20 /*jslint evil: true */
21 data = scope.execImport(attrs.data);
22 if (typeof data === 'string') {
23 data = new Function(
24 'return (' + data + ');'
25 )();
26 }
27 }
28 else {
29 data = null;
30 }
31 if (/^(off|false|no)$/.test(attrs.rework)) {
32 return render(data);
33 } else {
34 return scope.compile(render(data));
35 }
36};
\No newline at end of file