mm_tpl 2.7.2 → 2.7.4
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/README.md +39 -30
- package/README_EN.md +38 -29
- package/index.js +20 -38
- package/lib/asset.js +8 -4
- package/lib/base.js +84 -0
- package/lib/base_lang.js +200 -0
- package/lib/file.js +258 -0
- package/lib/hook.js +15 -8
- package/lib/lang.js +20 -16
- package/lib/memory.js +1 -3
- package/lib/sqlite.js +1 -3
- package/lib/template.js +14 -10
- package/lib/{engine.js → tpl.js} +121 -98
- package/lib/tpl_rule.js +1 -1
- package/lib/util.js +117 -0
- package/package.json +65 -62
package/lib/tpl_rule.js
CHANGED
|
@@ -73,7 +73,7 @@ var artRule = {
|
|
|
73
73
|
|
|
74
74
|
// 旧版语法升级提示
|
|
75
75
|
var warn = function warn(oldSyntax, newSyntax) {
|
|
76
|
-
|
|
76
|
+
console.warn((options.filename || 'anonymous') + ':' + (match.line + 1) + ':' + (match.start + 1) + '\n' + (
|
|
77
77
|
'Template upgrade: ${' + oldSyntax + '} -> ${' + newSyntax + '}'));
|
|
78
78
|
};
|
|
79
79
|
|
package/lib/util.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
+
const crypto = require('crypto');
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* 模板工具类
|
|
@@ -72,6 +73,122 @@ class TplUtil {
|
|
|
72
73
|
}
|
|
73
74
|
return body;
|
|
74
75
|
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 深度合并对象
|
|
79
|
+
* 目标已有的键:同为对象则递归合并,类型相同则转换后覆盖,类型不同保持原值
|
|
80
|
+
* 目标没有的键:supplement 为 true 时补充,否则跳过
|
|
81
|
+
* @param {Object} target - 被合并的对象
|
|
82
|
+
* @param {Object} source - 用作合并的对象
|
|
83
|
+
* @param {boolean} supplement - 是否补充目标没有的键
|
|
84
|
+
* @returns {Object} 修改后的目标对象
|
|
85
|
+
*/
|
|
86
|
+
static mergeDeep(target, source, supplement) {
|
|
87
|
+
if (!target || !source || typeof (target) !== 'object' || typeof (source) !== 'object') {
|
|
88
|
+
return target;
|
|
89
|
+
}
|
|
90
|
+
for (var key in source) {
|
|
91
|
+
if (Object.prototype.hasOwnProperty.call(target, key)) {
|
|
92
|
+
var target_val = target[key];
|
|
93
|
+
var source_val = source[key];
|
|
94
|
+
if (typeof (target_val) === 'object' && typeof (source_val) === 'object') {
|
|
95
|
+
TplUtil.mergeDeep(target_val, source_val, supplement);
|
|
96
|
+
} else if (typeof (target_val) === typeof (source_val)) {
|
|
97
|
+
target[key] = TplUtil._convertValue(target_val, source_val);
|
|
98
|
+
}
|
|
99
|
+
} else if (supplement) {
|
|
100
|
+
target[key] = source[key];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return target;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 按目标值的类型转换源值
|
|
108
|
+
* @param {any} target_val - 目标值
|
|
109
|
+
* @param {any} source_val - 源值
|
|
110
|
+
* @returns {any} 转换后的值
|
|
111
|
+
* @private
|
|
112
|
+
*/
|
|
113
|
+
static _convertValue(target_val, source_val) {
|
|
114
|
+
var target_type = typeof (target_val);
|
|
115
|
+
if (target_type === 'number') {
|
|
116
|
+
var num = Number(source_val);
|
|
117
|
+
return isNaN(num) ? 0 : num;
|
|
118
|
+
}
|
|
119
|
+
if (target_type === 'boolean') {
|
|
120
|
+
if (source_val === '0' || source_val === 'false' || source_val === 'False') {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
if (source_val === '1' || source_val === 'true' || source_val === 'True') {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
return Boolean(source_val);
|
|
127
|
+
}
|
|
128
|
+
if (target_type === 'string') {
|
|
129
|
+
return String(source_val);
|
|
130
|
+
}
|
|
131
|
+
return source_val;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 深拷贝对象或值
|
|
136
|
+
* 仅处理数组与普通对象,最大递归深度 10,超出时直接返回原值
|
|
137
|
+
* @param {any} source - 源对象或值
|
|
138
|
+
* @param {number} depth - 当前递归深度,内部使用
|
|
139
|
+
* @returns {any} 拷贝后的对象或值
|
|
140
|
+
* @private
|
|
141
|
+
*/
|
|
142
|
+
static cloneDeep(source, depth) {
|
|
143
|
+
var level = depth || 0;
|
|
144
|
+
if (level > 10 || !source || typeof (source) !== 'object') {
|
|
145
|
+
return source;
|
|
146
|
+
}
|
|
147
|
+
if (Array.isArray(source)) {
|
|
148
|
+
var new_arr = [];
|
|
149
|
+
for (var i = 0; i < source.length; i++) {
|
|
150
|
+
new_arr.push(TplUtil.cloneDeep(source[i], level + 1));
|
|
151
|
+
}
|
|
152
|
+
return new_arr;
|
|
153
|
+
}
|
|
154
|
+
var new_obj = {};
|
|
155
|
+
for (var key in source) {
|
|
156
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
157
|
+
new_obj[key] = TplUtil.cloneDeep(source[key], level + 1);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return new_obj;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* 计算字符串的 MD5 值
|
|
165
|
+
* @param {string} str - 原始字符串
|
|
166
|
+
* @returns {string} 十六进制摘要
|
|
167
|
+
*/
|
|
168
|
+
static md5(str) {
|
|
169
|
+
return crypto.createHash('md5').update(str + '').digest('hex');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 取两个标记符之间的子串
|
|
174
|
+
* 任一标记符不存在时返回空字符串
|
|
175
|
+
* @param {string} str - 原始字符串
|
|
176
|
+
* @param {string} left_str - 左侧标记符
|
|
177
|
+
* @param {string} right_str - 右侧标记符
|
|
178
|
+
* @returns {string} 截取后的字符串
|
|
179
|
+
*/
|
|
180
|
+
static between(str, left_str, right_str) {
|
|
181
|
+
var start = (str + '').indexOf(left_str);
|
|
182
|
+
if (start === -1) {
|
|
183
|
+
return '';
|
|
184
|
+
}
|
|
185
|
+
var from = start + left_str.length;
|
|
186
|
+
var end = (str + '').indexOf(right_str, from);
|
|
187
|
+
if (end === -1) {
|
|
188
|
+
return '';
|
|
189
|
+
}
|
|
190
|
+
return (str + '').substring(from, end);
|
|
191
|
+
}
|
|
75
192
|
}
|
|
76
193
|
|
|
77
194
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -1,62 +1,65 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "mm_tpl",
|
|
3
|
-
"version": "2.7.
|
|
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
|
-
"main": "index.js",
|
|
6
|
-
"io": true,
|
|
7
|
-
"priority": 100,
|
|
8
|
-
"scripts": {
|
|
9
|
-
"dev": "nodemon test.js",
|
|
10
|
-
"demo": "node example/demo.js",
|
|
11
|
-
"test": "node test.js",
|
|
12
|
-
"coverage": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage"
|
|
13
|
-
},
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://gitee.com/qiuwenwu91/mm_tpl.git"
|
|
17
|
-
},
|
|
18
|
-
"keywords": [
|
|
19
|
-
"mm_mod",
|
|
20
|
-
"mm_infra",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
},
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "mm_tpl",
|
|
3
|
+
"version": "2.7.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
|
+
"main": "index.js",
|
|
6
|
+
"io": true,
|
|
7
|
+
"priority": 100,
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "nodemon test.js",
|
|
10
|
+
"demo": "node example/demo.js",
|
|
11
|
+
"test": "node test.js",
|
|
12
|
+
"coverage": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://gitee.com/qiuwenwu91/mm_tpl.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"mm_mod",
|
|
20
|
+
"mm_infra",
|
|
21
|
+
"mm_common",
|
|
22
|
+
"mm_web",
|
|
23
|
+
"template",
|
|
24
|
+
"engine",
|
|
25
|
+
"mvc",
|
|
26
|
+
"web",
|
|
27
|
+
"view",
|
|
28
|
+
"render",
|
|
29
|
+
"art-template",
|
|
30
|
+
"hook",
|
|
31
|
+
"theme",
|
|
32
|
+
"cache",
|
|
33
|
+
"nodejs",
|
|
34
|
+
"javascript"
|
|
35
|
+
],
|
|
36
|
+
"layer": "infra",
|
|
37
|
+
"group": "common",
|
|
38
|
+
"author": "邱文武",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://gitee.com/qiuwenwu91/mm_tpl/issues"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://gitee.com/qiuwenwu91/mm_tpl#readme",
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"art-template": "4.13.4",
|
|
46
|
+
"mm_corejs": "^1.1.6"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=12.0.0"
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"index.js",
|
|
53
|
+
"hook.js",
|
|
54
|
+
"tpl_rule.js",
|
|
55
|
+
"lib/",
|
|
56
|
+
"doc/",
|
|
57
|
+
"README.md",
|
|
58
|
+
"README_EN.md",
|
|
59
|
+
"package.json"
|
|
60
|
+
],
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"eslint": "^9.39.5",
|
|
63
|
+
"eslint-plugin-jsdoc": "^65.0.0"
|
|
64
|
+
}
|
|
65
|
+
}
|