mm_tpl 2.4.7 → 2.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +51 -29
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const engine = require('art-template');
|
|
2
2
|
const {
|
|
3
3
|
Base
|
|
4
4
|
} = require('mm_expand');
|
|
@@ -25,26 +25,51 @@ if (!$.hook) {
|
|
|
25
25
|
* @class
|
|
26
26
|
*/
|
|
27
27
|
class Tpl extends Base {
|
|
28
|
+
static config = {
|
|
29
|
+
/**
|
|
30
|
+
* 模板根目录
|
|
31
|
+
*/
|
|
32
|
+
root: $.run_path + '',
|
|
33
|
+
/**
|
|
34
|
+
* 默认模板目录
|
|
35
|
+
*/
|
|
36
|
+
default_dir: "./template/",
|
|
37
|
+
/**
|
|
38
|
+
* 默认主题
|
|
39
|
+
*/
|
|
40
|
+
default_theme: 'default',
|
|
41
|
+
/**
|
|
42
|
+
* 模板文件扩展名
|
|
43
|
+
*/
|
|
44
|
+
extname: ".html",
|
|
45
|
+
/**
|
|
46
|
+
* 模板规则
|
|
47
|
+
*/
|
|
48
|
+
rules: [nativeRule, artRule, htmlRule, jsRule, pyRule, pyRule2],
|
|
49
|
+
/**
|
|
50
|
+
* 缓存根目录
|
|
51
|
+
*/
|
|
52
|
+
cache_root: './cache'.fullname(),
|
|
53
|
+
/**
|
|
54
|
+
* 缓存文件扩展名
|
|
55
|
+
*/
|
|
56
|
+
cache_extname: '.cache.html',
|
|
57
|
+
/**
|
|
58
|
+
* 变换字符串
|
|
59
|
+
*/
|
|
60
|
+
change_str: ['\\#', '\\<', '\\${', '\\*', '\\"""'],
|
|
61
|
+
};
|
|
28
62
|
/**
|
|
29
63
|
* 创建模板实例
|
|
30
64
|
* @param {Object} config - 配置选项
|
|
31
65
|
*/
|
|
32
66
|
constructor(config) {
|
|
33
|
-
super(
|
|
34
|
-
root: $.runPath + '',
|
|
35
|
-
default_dir: "./template/",
|
|
36
|
-
default_theme: 'default',
|
|
37
|
-
extname: ".html",
|
|
38
|
-
rules: [nativeRule, artRule, htmlRule, jsRule, pyRule, pyRule2],
|
|
39
|
-
cache_root: './cache'.fullname(),
|
|
40
|
-
cache_extname: '.cache.html',
|
|
41
|
-
change_str: ["\\#", "\\<", "\\${", "\\/*", '\\"""'],
|
|
42
|
-
}, config));
|
|
67
|
+
super(config);
|
|
43
68
|
|
|
44
69
|
/**
|
|
45
70
|
* 模板引擎
|
|
46
71
|
*/
|
|
47
|
-
this.
|
|
72
|
+
this.engine = engine;
|
|
48
73
|
|
|
49
74
|
/**
|
|
50
75
|
* 视图数据
|
|
@@ -54,7 +79,7 @@ class Tpl extends Base {
|
|
|
54
79
|
/**
|
|
55
80
|
* 模板根目录
|
|
56
81
|
*/
|
|
57
|
-
this.dir =
|
|
82
|
+
this.dir = './template/';
|
|
58
83
|
|
|
59
84
|
/**
|
|
60
85
|
* 当前主题
|
|
@@ -75,28 +100,23 @@ class Tpl extends Base {
|
|
|
75
100
|
/**
|
|
76
101
|
* 初始化
|
|
77
102
|
*/
|
|
78
|
-
this.
|
|
103
|
+
this._init();
|
|
79
104
|
}
|
|
80
105
|
}
|
|
81
106
|
|
|
82
107
|
/**
|
|
83
|
-
*
|
|
84
|
-
* @param {Object} config - 配置参数
|
|
108
|
+
* 初始化模板
|
|
85
109
|
*/
|
|
86
|
-
Tpl.prototype.
|
|
87
|
-
if (config) {
|
|
88
|
-
this.config = Object.assign(this.config, config);
|
|
89
|
-
}
|
|
110
|
+
Tpl.prototype._initTpl = function () {
|
|
90
111
|
var cg = this.config;
|
|
91
112
|
for (var key in cg) {
|
|
92
|
-
|
|
113
|
+
this.engine.defaults[key] = cg[key];
|
|
93
114
|
}
|
|
94
115
|
if (!cg.cache_root.hasDir()) {
|
|
95
116
|
cg.cache_root.addDir()
|
|
96
117
|
}
|
|
97
118
|
};
|
|
98
119
|
|
|
99
|
-
|
|
100
120
|
/**
|
|
101
121
|
* 执行钩子函数
|
|
102
122
|
* @param {string} name - 钩子名称
|
|
@@ -129,7 +149,8 @@ Tpl.prototype._initBefore = function (config) { }
|
|
|
129
149
|
*/
|
|
130
150
|
Tpl.prototype._initMain = function (config) {
|
|
131
151
|
this.setConfig(config);
|
|
132
|
-
|
|
152
|
+
this._initTpl();
|
|
153
|
+
};
|
|
133
154
|
|
|
134
155
|
/**
|
|
135
156
|
* 初始化后处理
|
|
@@ -149,17 +170,17 @@ Tpl.prototype._initAfter = function (config) {
|
|
|
149
170
|
this.regex_out.push(new RegExp(rx_out, "gi"));
|
|
150
171
|
this.str_out.push(str.replace("\\", ""));
|
|
151
172
|
}
|
|
152
|
-
}
|
|
173
|
+
};
|
|
153
174
|
|
|
154
175
|
/**
|
|
155
176
|
* 初始化模板
|
|
156
177
|
* @param {Object} config - 配置参数
|
|
157
178
|
*/
|
|
158
|
-
Tpl.prototype.
|
|
179
|
+
Tpl.prototype._init = function (config) {
|
|
159
180
|
this._initBefore(config);
|
|
160
181
|
this._initMain(config);
|
|
161
182
|
this._initAfter(config);
|
|
162
|
-
}
|
|
183
|
+
};
|
|
163
184
|
|
|
164
185
|
/**
|
|
165
186
|
* 转义字符
|
|
@@ -266,7 +287,7 @@ Tpl.prototype._renderMain = function (body, model, options) {
|
|
|
266
287
|
globalBag: $.globalBag
|
|
267
288
|
}, model);
|
|
268
289
|
this.loadFunc(m);
|
|
269
|
-
ret =
|
|
290
|
+
ret = this.engine.render(body, m, options);
|
|
270
291
|
}
|
|
271
292
|
return ret;
|
|
272
293
|
};
|
|
@@ -332,7 +353,7 @@ Tpl.prototype.render = function (body, model, options) {
|
|
|
332
353
|
* @returns {Function} 渲染函数
|
|
333
354
|
*/
|
|
334
355
|
Tpl.prototype.compile = function (body, options) {
|
|
335
|
-
return
|
|
356
|
+
return this.engine.compile(body, options);
|
|
336
357
|
};
|
|
337
358
|
|
|
338
359
|
/**
|
|
@@ -367,7 +388,8 @@ Tpl.prototype.view = function (file, model, options) {
|
|
|
367
388
|
this.error = {
|
|
368
389
|
code: 10000,
|
|
369
390
|
message: f + "文件不存在!"
|
|
370
|
-
}
|
|
391
|
+
};
|
|
392
|
+
this.log('error', '渲染模板文件失败', this.error);
|
|
371
393
|
}
|
|
372
394
|
else {
|
|
373
395
|
var body = f.loadText();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_tpl",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.9",
|
|
4
4
|
"description": "Super Meimei Template Engine - High-performance template engine based on art-template with MVC pattern, hook system, theme switching and caching mechanism",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"homepage": "https://gitee.com/qiuwenwu91/mm_tpl#readme",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"art-template": "^4.13.4",
|
|
37
|
-
"mm_expand": "^
|
|
37
|
+
"mm_expand": "^2.0.8"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": ">=12.0.0"
|