mm_tpl 2.2.3 → 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 +2 -1
- package/hook.js +24 -1
- package/index.js +2 -2
- package/package.json +2 -2
- package/template/game/bar.html +1 -0
- package/test.js +6 -4
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/index.js
CHANGED
|
@@ -146,10 +146,10 @@ Tpl.prototype.render_before = function(body, model, options) {
|
|
|
146
146
|
Tpl.prototype.loadFunc = function(m) {
|
|
147
147
|
var _this = this;
|
|
148
148
|
m.view = function(file, model, options) {
|
|
149
|
-
return _this.view(file, model, options);
|
|
149
|
+
return _this.view(file, Object.assign({}, m, model), options);
|
|
150
150
|
}
|
|
151
151
|
m.render = function(body, model, options) {
|
|
152
|
-
return _this.render(body, model, options);
|
|
152
|
+
return _this.render(body, Object.assign({}, m, model), options);
|
|
153
153
|
}
|
|
154
154
|
m.hook_action = function(name, ...args) {
|
|
155
155
|
return $.hook.runAction(name, m, ...args);
|
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/template/game/bar.html
CHANGED
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
|
|
|
@@ -84,7 +85,8 @@ async function test() {
|
|
|
84
85
|
|
|
85
86
|
// 渲染视图(并缓存)
|
|
86
87
|
var body = tpl.view("./test", {
|
|
87
|
-
arr: [123, 234]
|
|
88
|
+
arr: [123, 234],
|
|
89
|
+
message: "hello world!"
|
|
88
90
|
}, {
|
|
89
91
|
// 是否读取缓存文件, 如果为false, 但有cache_filename, 表示只保存缓存,但不读取
|
|
90
92
|
cache: false,
|