mm_tpl 2.1.7 → 2.1.9
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/hook.js +7 -5
- package/index.js +4 -7
- package/package.json +1 -1
- package/template/game/bar.html +1 -1
- package/test.js +5 -3
package/hook.js
CHANGED
|
@@ -88,16 +88,17 @@ Hook.prototype.delFilter = function(name, alias = "") {
|
|
|
88
88
|
/**
|
|
89
89
|
* 运行动作钩子
|
|
90
90
|
* @param {String} name 钩子名称
|
|
91
|
-
* @param {Object}
|
|
91
|
+
* @param {Object} model 模型
|
|
92
92
|
* @param {Object} args 附加参数
|
|
93
93
|
*/
|
|
94
|
-
Hook.prototype.runAction = function(name,
|
|
94
|
+
Hook.prototype.runAction = function(name, model, ...args) {
|
|
95
|
+
var ret = "";
|
|
95
96
|
var dict = this.dict_action;
|
|
96
97
|
var list = dict[name];
|
|
97
98
|
if (list) {
|
|
98
99
|
for (var i = 0; i < list.length; i++) {
|
|
99
100
|
var o = list[i];
|
|
100
|
-
ret += o.func(
|
|
101
|
+
ret += o.func(model, ...args);
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
return ret;
|
|
@@ -107,15 +108,16 @@ Hook.prototype.runAction = function(name, ret, ...args) {
|
|
|
107
108
|
* 运行过滤钩子
|
|
108
109
|
* @param {String} name 钩子名称
|
|
109
110
|
* @param {Object} ret 结果
|
|
111
|
+
* @param {Object} model 模型
|
|
110
112
|
* @param {Object} args 附加参数
|
|
111
113
|
*/
|
|
112
|
-
Hook.prototype.runFilter = function(name, ret, ...args) {
|
|
114
|
+
Hook.prototype.runFilter = function(name, ret, model, ...args) {
|
|
113
115
|
var dict = this.dict_filter;
|
|
114
116
|
var list = dict[name];
|
|
115
117
|
if (list) {
|
|
116
118
|
for (var i = 0; i < list.length; i++) {
|
|
117
119
|
var o = list[i];
|
|
118
|
-
ret = o.func(ret, ...args);
|
|
120
|
+
ret = o.func(ret, model, ...args);
|
|
119
121
|
}
|
|
120
122
|
}
|
|
121
123
|
return ret;
|
package/index.js
CHANGED
|
@@ -140,17 +140,14 @@ Tpl.prototype.loadFunc = function(m) {
|
|
|
140
140
|
m.render = function(body, model, options) {
|
|
141
141
|
return _this.render(body, model, options);
|
|
142
142
|
}
|
|
143
|
-
m.hook_action = function(name,
|
|
144
|
-
|
|
145
|
-
content = "";
|
|
146
|
-
}
|
|
147
|
-
return $.hook.runAction(name, content, ...args);
|
|
143
|
+
m.hook_action = function(name, ...args) {
|
|
144
|
+
return $.hook.runAction(name, m, ...args);
|
|
148
145
|
}
|
|
149
146
|
m.hook_filter = function(name, content, ...args) {
|
|
150
147
|
if (!content) {
|
|
151
148
|
content = "";
|
|
152
149
|
}
|
|
153
|
-
return $.hook.runFilter(name, content, ...args);
|
|
150
|
+
return $.hook.runFilter(name, content, m, ...args);
|
|
154
151
|
}
|
|
155
152
|
return m;
|
|
156
153
|
}
|
|
@@ -242,7 +239,7 @@ Tpl.prototype.view = function(file, model, options) {
|
|
|
242
239
|
if (!f.hasFile()) {
|
|
243
240
|
f = file.fullname(this.dir + this.config.defualt_theme);
|
|
244
241
|
if (!f.hasFile()) {
|
|
245
|
-
f = file.fullname(this.config.defualt_dir + this.
|
|
242
|
+
f = file.fullname(this.config.defualt_dir + this.current_theme);
|
|
246
243
|
if (!f.hasFile()) {
|
|
247
244
|
f = file.fullname(this.config.defualt_dir + this.config.defualt_theme);
|
|
248
245
|
}
|
package/package.json
CHANGED
package/template/game/bar.html
CHANGED
package/test.js
CHANGED
|
@@ -47,15 +47,17 @@ async function test() {
|
|
|
47
47
|
tpl.current_theme = "game";
|
|
48
48
|
tpl.dir = "";
|
|
49
49
|
|
|
50
|
-
$.hook.addAction('test', (
|
|
50
|
+
$.hook.addAction('test', function(m, param) {
|
|
51
|
+
// console.log(param, m);
|
|
51
52
|
return "<div>你好吗?</div>";
|
|
52
53
|
}, 2, "测试动作2");
|
|
53
54
|
|
|
54
|
-
$.hook.addAction('test', (
|
|
55
|
+
$.hook.addAction('test', function(m, param) {
|
|
55
56
|
return "<div>你好!</div>";
|
|
56
57
|
}, 1, "测试动作1");
|
|
57
58
|
|
|
58
|
-
$.hook.addFilter('test', (ret)
|
|
59
|
+
$.hook.addFilter('test', function(ret, m, param) {
|
|
60
|
+
// console.log(ret, param, m);
|
|
59
61
|
return ret.replace("你", "您");
|
|
60
62
|
}, 1, "测试过滤");
|
|
61
63
|
|