mm_tpl 2.5.3 → 2.5.5
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 +19 -8
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -33,7 +33,7 @@ class Tpl extends Base {
|
|
|
33
33
|
/**
|
|
34
34
|
* 默认模板目录
|
|
35
35
|
*/
|
|
36
|
-
default_dir: "./template/",
|
|
36
|
+
default_dir: "./static/template/",
|
|
37
37
|
/**
|
|
38
38
|
* 默认主题
|
|
39
39
|
*/
|
|
@@ -79,7 +79,7 @@ class Tpl extends Base {
|
|
|
79
79
|
/**
|
|
80
80
|
* 模板根目录
|
|
81
81
|
*/
|
|
82
|
-
this.dir = './template/';
|
|
82
|
+
this.dir = './static/template/';
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* 当前主题
|
|
@@ -357,13 +357,14 @@ Tpl.prototype.compile = function (body, options) {
|
|
|
357
357
|
};
|
|
358
358
|
|
|
359
359
|
/**
|
|
360
|
-
*
|
|
360
|
+
* 获取模板文件
|
|
361
361
|
* @param {string} file - 模板文件路径
|
|
362
|
-
* @
|
|
363
|
-
* @param {Object} options - 配置参数
|
|
364
|
-
* @returns {string} 渲染结果
|
|
362
|
+
* @returns {string} 模板文件路径
|
|
365
363
|
*/
|
|
366
|
-
Tpl.prototype.
|
|
364
|
+
Tpl.prototype.getFile = function (file) {
|
|
365
|
+
if (typeof (file) !== 'string') {
|
|
366
|
+
throw new Error('模板文件路径必须是字符串');
|
|
367
|
+
}
|
|
367
368
|
if (file.replace('./', '').indexOf('.') === -1 && !file.endsWith(this.config.extname)) {
|
|
368
369
|
file += this.config.extname;
|
|
369
370
|
}
|
|
@@ -383,13 +384,23 @@ Tpl.prototype.view = function (file, model, options) {
|
|
|
383
384
|
}
|
|
384
385
|
}
|
|
385
386
|
}
|
|
387
|
+
return f;
|
|
388
|
+
};
|
|
386
389
|
|
|
390
|
+
/**
|
|
391
|
+
* 渲染模板文件
|
|
392
|
+
* @param {string} file - 模板文件路径
|
|
393
|
+
* @param {Object} model - 数据模型
|
|
394
|
+
* @param {Object} options - 配置参数
|
|
395
|
+
* @returns {string} 渲染结果
|
|
396
|
+
*/
|
|
397
|
+
Tpl.prototype.view = function (file, model, options) {
|
|
398
|
+
var f = this.getFile(file);
|
|
387
399
|
if (!f.hasFile()) {
|
|
388
400
|
this.error = {
|
|
389
401
|
code: 10000,
|
|
390
402
|
message: f + "文件不存在!"
|
|
391
403
|
};
|
|
392
|
-
this.log('error', '渲染模板文件失败', this.error);
|
|
393
404
|
}
|
|
394
405
|
else {
|
|
395
406
|
var body = f.loadText();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_tpl",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.5",
|
|
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": "^2.
|
|
37
|
+
"mm_expand": "^2.3.1"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": ">=12.0.0"
|