mm_tpl 2.2.4 → 2.2.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/cache/test.cache.html +1 -1
- package/hook.js +24 -1
- package/package.json +2 -2
- package/test.js +4 -3
package/cache/test.cache.html
CHANGED
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_tpl",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.5",
|
|
4
4
|
"description": "这是超级美眉模板帮助类模块,用于MVC模式下的视图渲染",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -27,6 +27,6 @@
|
|
|
27
27
|
"homepage": "https://github.com/qiuwenwu/mm_tpl#readme",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"art-template": "^4.13.2",
|
|
30
|
-
"mm_expand": "^1.5.
|
|
30
|
+
"mm_expand": "^1.5.6"
|
|
31
31
|
}
|
|
32
32
|
}
|
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>";
|
|
@@ -71,7 +71,8 @@ async function test() {
|
|
|
71
71
|
// console.log(ret, param, m);
|
|
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
|
|