mm_tpl 2.2.4 → 2.2.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.
- package/cache/test.cache.html +18 -13
- package/hook.js +24 -1
- package/index.js +10 -4
- package/package.json +3 -2
- package/template/diy/ad.html +36 -0
- package/test.js +4 -3
package/cache/test.cache.html
CHANGED
|
@@ -5,18 +5,23 @@
|
|
|
5
5
|
<title>超级美眉Art模板引擎</title>
|
|
6
6
|
</head>
|
|
7
7
|
<body>
|
|
8
|
-
<
|
|
9
|
-
<
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
<
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
</
|
|
8
|
+
<h5>系统名称</h5>
|
|
9
|
+
<ul>
|
|
10
|
+
<li>123</li>
|
|
11
|
+
<li>234</li>
|
|
12
|
+
</ul>
|
|
13
|
+
<ul>
|
|
14
|
+
<li>123</li>
|
|
15
|
+
<li>234</li>
|
|
16
|
+
</ul>
|
|
17
|
+
<ul>
|
|
18
|
+
<li>123</li>
|
|
19
|
+
<li>234</li>
|
|
20
|
+
</ul>
|
|
21
|
+
<script type="text/javascript">
|
|
22
|
+
var a_0 =123;
|
|
23
|
+
var a_1 =234;
|
|
24
|
+
</script>系统名称计算
|
|
25
|
+
123123'priceNIHAO'#计算
|
|
21
26
|
</body>
|
|
22
27
|
</html>
|
package/hook.js
CHANGED
|
@@ -20,6 +20,24 @@ Hook.prototype.sort = function(list) {
|
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* 获取别名
|
|
25
|
+
* @param {Function} func 钩子函数
|
|
26
|
+
* @param {String} alias 别名
|
|
27
|
+
*/
|
|
28
|
+
Hook.prototype.getName = function(func, alias) {
|
|
29
|
+
if (!alias) {
|
|
30
|
+
var str = func.toString();
|
|
31
|
+
var name = str.between('function ', "(").trim();
|
|
32
|
+
if (name) {
|
|
33
|
+
alias = name;
|
|
34
|
+
} else {
|
|
35
|
+
alias = (new Date()).toString().md5().substring(0, 8);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return alias;
|
|
39
|
+
}
|
|
40
|
+
|
|
23
41
|
/**
|
|
24
42
|
* 添加函数钩子
|
|
25
43
|
* @param {String} name 钩子名称
|
|
@@ -28,6 +46,7 @@ Hook.prototype.sort = function(list) {
|
|
|
28
46
|
* @param {String} alias 函数别名,用于删除
|
|
29
47
|
*/
|
|
30
48
|
Hook.prototype.addFunc = function(name, func, sort, alias) {
|
|
49
|
+
alias = this.getName(func, alias);
|
|
31
50
|
var obj = {
|
|
32
51
|
func,
|
|
33
52
|
sort,
|
|
@@ -39,6 +58,7 @@ Hook.prototype.addFunc = function(name, func, sort, alias) {
|
|
|
39
58
|
}
|
|
40
59
|
arr.push(obj);
|
|
41
60
|
this.dict_func[name] = this.sort(arr);
|
|
61
|
+
return alias;
|
|
42
62
|
}
|
|
43
63
|
|
|
44
64
|
/**
|
|
@@ -49,6 +69,7 @@ Hook.prototype.addFunc = function(name, func, sort, alias) {
|
|
|
49
69
|
* @param {String} alias 函数别名,用于删除
|
|
50
70
|
*/
|
|
51
71
|
Hook.prototype.addAction = function(name, func, sort, alias) {
|
|
72
|
+
alias = this.getName(func, alias);
|
|
52
73
|
var obj = {
|
|
53
74
|
func,
|
|
54
75
|
sort,
|
|
@@ -60,6 +81,7 @@ Hook.prototype.addAction = function(name, func, sort, alias) {
|
|
|
60
81
|
}
|
|
61
82
|
arr.push(obj);
|
|
62
83
|
this.dict_action[name] = this.sort(arr);
|
|
84
|
+
return alias;
|
|
63
85
|
}
|
|
64
86
|
|
|
65
87
|
/**
|
|
@@ -70,6 +92,7 @@ Hook.prototype.addAction = function(name, func, sort, alias) {
|
|
|
70
92
|
* @param {String} alias 函数别名,用于删除
|
|
71
93
|
*/
|
|
72
94
|
Hook.prototype.addFilter = function(name, func, sort, alias) {
|
|
95
|
+
alias = this.getName(func, alias);
|
|
73
96
|
var obj = {
|
|
74
97
|
func,
|
|
75
98
|
sort,
|
|
@@ -81,9 +104,9 @@ Hook.prototype.addFilter = function(name, func, sort, alias) {
|
|
|
81
104
|
}
|
|
82
105
|
arr.push(obj);
|
|
83
106
|
this.dict_filter[name] = this.sort(arr);
|
|
107
|
+
return alias;
|
|
84
108
|
}
|
|
85
109
|
|
|
86
|
-
|
|
87
110
|
/**
|
|
88
111
|
* 删除函数钩子
|
|
89
112
|
* @param {String} name 钩子名称
|
package/index.js
CHANGED
|
@@ -246,13 +246,19 @@ Tpl.prototype.view = function(file, model, options) {
|
|
|
246
246
|
if (file.replace('./', '').indexOf('.') === -1 && !file.endWith(this.config.extname)) {
|
|
247
247
|
file += this.config.extname;
|
|
248
248
|
}
|
|
249
|
-
var f = file.fullname(this.dir +
|
|
249
|
+
var f = file.fullname(this.dir + 'diy');
|
|
250
250
|
if (!f.hasFile()) {
|
|
251
|
-
f = file.fullname(this.
|
|
251
|
+
f = file.fullname(this.config.default_dir + 'diy');
|
|
252
252
|
if (!f.hasFile()) {
|
|
253
|
-
f = file.fullname(this.
|
|
253
|
+
f = file.fullname(this.dir + this.current_theme);
|
|
254
254
|
if (!f.hasFile()) {
|
|
255
|
-
f = file.fullname(this.
|
|
255
|
+
f = file.fullname(this.dir + this.config.default_theme);
|
|
256
|
+
if (!f.hasFile()) {
|
|
257
|
+
f = file.fullname(this.config.default_dir + this.current_theme);
|
|
258
|
+
if (!f.hasFile()) {
|
|
259
|
+
f = file.fullname(this.config.default_dir + this.config.default_theme);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
256
262
|
}
|
|
257
263
|
}
|
|
258
264
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_tpl",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.6",
|
|
4
4
|
"description": "这是超级美眉模板帮助类模块,用于MVC模式下的视图渲染",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
+
"dev": "nodemon test.js",
|
|
7
8
|
"test": "node test.js"
|
|
8
9
|
},
|
|
9
10
|
"repository": {
|
|
@@ -27,6 +28,6 @@
|
|
|
27
28
|
"homepage": "https://github.com/qiuwenwu/mm_tpl#readme",
|
|
28
29
|
"dependencies": {
|
|
29
30
|
"art-template": "^4.13.2",
|
|
30
|
-
"mm_expand": "^1.5.
|
|
31
|
+
"mm_expand": "^1.5.6"
|
|
31
32
|
}
|
|
32
33
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>${globalBag.name}</title>
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
<h5>${viewBag.name}</h5>
|
|
9
|
+
<ul>
|
|
10
|
+
${loop arr value idx}
|
|
11
|
+
<li>${ value }</li>
|
|
12
|
+
${/loop}
|
|
13
|
+
</ul>
|
|
14
|
+
<ul>
|
|
15
|
+
<!--[ for(var i = 0; i < arr.length; i++) { ]-->
|
|
16
|
+
<li>${ arr[i] }</li>
|
|
17
|
+
<!--[ } ]-->
|
|
18
|
+
</ul>
|
|
19
|
+
<ul>
|
|
20
|
+
<!--{loop arr value idx}-->
|
|
21
|
+
<li>${ value }</li>
|
|
22
|
+
<!--{/loop}-->
|
|
23
|
+
</ul>
|
|
24
|
+
<script type="text/javascript">
|
|
25
|
+
/*[loop arr value idx]*/
|
|
26
|
+
var a_${idx} = ${value};
|
|
27
|
+
/*[/loop]*/
|
|
28
|
+
</script>
|
|
29
|
+
${viewBag.name}
|
|
30
|
+
## "计算" ##
|
|
31
|
+
123123'"""#
|
|
32
|
+
"price" + "NIHAO"
|
|
33
|
+
#"""'
|
|
34
|
+
## "#计算" ##
|
|
35
|
+
</body>
|
|
36
|
+
</html>
|
package/test.js
CHANGED
|
@@ -58,10 +58,10 @@ async function test() {
|
|
|
58
58
|
console.log(m);
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
$.hook.addAction('test', function(m, param) {
|
|
61
|
+
$.hook.addAction('test', function aa(m, param) {
|
|
62
62
|
// console.log(param, m);
|
|
63
63
|
return "<div>你好吗?</div>";
|
|
64
|
-
}, 2
|
|
64
|
+
}, 2);
|
|
65
65
|
|
|
66
66
|
$.hook.addAction('test', function(m, param) {
|
|
67
67
|
return "<div>你好!</div>";
|
|
@@ -72,6 +72,7 @@ async function test() {
|
|
|
72
72
|
return ret.replace("你", "您");
|
|
73
73
|
}, 1, "测试过滤");
|
|
74
74
|
|
|
75
|
+
// $.hook.delAction('test', "aa");
|
|
75
76
|
// $.hook.delAction('test', "测试动作1");
|
|
76
77
|
// $.hook.delFilter('test', "测试过滤");
|
|
77
78
|
|
|
@@ -83,7 +84,7 @@ async function test() {
|
|
|
83
84
|
}, 'article');
|
|
84
85
|
|
|
85
86
|
// 渲染视图(并缓存)
|
|
86
|
-
var body = tpl.view("./
|
|
87
|
+
var body = tpl.view("./ad", {
|
|
87
88
|
arr: [123, 234],
|
|
88
89
|
message: "hello world!"
|
|
89
90
|
}, {
|