mm_tpl 2.5.4 → 2.5.6

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.
Files changed (2) hide show
  1. package/index.js +17 -6
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -357,13 +357,14 @@ Tpl.prototype.compile = function (body, options) {
357
357
  };
358
358
 
359
359
  /**
360
- * 渲染模板文件
360
+ * 获取模板文件
361
361
  * @param {string} file - 模板文件路径
362
- * @param {Object} model - 数据模型
363
- * @param {Object} options - 配置参数
364
- * @returns {string} 渲染结果
362
+ * @returns {string} 模板文件路径
365
363
  */
366
- Tpl.prototype.view = function (file, model, options) {
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.4",
3
+ "version": "2.5.6",
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.2.9"
37
+ "mm_expand": "^2.3.3"
38
38
  },
39
39
  "engines": {
40
40
  "node": ">=12.0.0"