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.
@@ -6,9 +6,10 @@
6
6
  </head>
7
7
  <body>
8
8
  <div>游戏主题</div>
9
- <div><div class="bar_user"><div>您好吗?</div><div>你好!</div>
9
+ <div><div class="bar_user"><div>您好!</div>
10
10
  <div>用户ID:1</div>
11
11
  <div>当前项目ID:2</div>
12
+ <div>hello world!</div>
12
13
  </div>
13
14
 
14
15
  <div class="bar">导航栏</div>
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",
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.5"
30
+ "mm_expand": "^1.5.6"
31
31
  }
32
32
  }
@@ -2,6 +2,7 @@
2
2
  ${@hook_filter('test', hook_action('test', '好的'), '真的')}
3
3
  <div>用户ID:${viewBag.user_id}</div>
4
4
  <div>当前项目ID:${viewBag.project_id}</div>
5
+ <div>${message}</div>
5
6
  </div>
6
7
 
7
8
  <div class="bar">导航栏</div>
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, "测试动作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,