mm_tpl 2.3.3 → 2.3.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/index.js +46 -8
- package/package.json +1 -1
- package/template/default/test.html +5 -5
- package/cache/test.cache.html +0 -30
package/index.js
CHANGED
|
@@ -104,7 +104,7 @@ Tpl.prototype.set_config = function(config) {
|
|
|
104
104
|
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
|
-
*
|
|
107
|
+
* 执行函数钩子
|
|
108
108
|
* @param {String} name 名称
|
|
109
109
|
* @param {Object} req 请求参数
|
|
110
110
|
* @param {Object} args 附加参数
|
|
@@ -113,12 +113,27 @@ Tpl.prototype.runFunc = function(name, req, ...args) {
|
|
|
113
113
|
return $.hook.runFunc(name, this.viewBag, req, ...args);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
|
|
116
117
|
/**
|
|
117
|
-
*
|
|
118
|
+
* 初始化之前
|
|
118
119
|
* @param {Object} config 配置参数
|
|
119
120
|
*/
|
|
120
|
-
Tpl.prototype.
|
|
121
|
+
Tpl.prototype.init_before = function(config) {
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 初始化主体
|
|
126
|
+
* @param {Object} config 配置参数
|
|
127
|
+
*/
|
|
128
|
+
Tpl.prototype.init_main = function(config) {
|
|
121
129
|
this.set_config(config);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 初始化之后
|
|
134
|
+
* @param {Object} config 配置参数
|
|
135
|
+
*/
|
|
136
|
+
Tpl.prototype.init_after = function(config) {
|
|
122
137
|
var lt = this.config.change_str;
|
|
123
138
|
for (var i = 0; i < lt.length; i++) {
|
|
124
139
|
var str = lt[i];
|
|
@@ -131,6 +146,16 @@ Tpl.prototype.init = function(config) {
|
|
|
131
146
|
}
|
|
132
147
|
}
|
|
133
148
|
|
|
149
|
+
/**
|
|
150
|
+
* 初始化
|
|
151
|
+
* @param {Object} config 配置参数
|
|
152
|
+
*/
|
|
153
|
+
Tpl.prototype.init = function(config) {
|
|
154
|
+
this.init_before(config);
|
|
155
|
+
this.init_main(config);
|
|
156
|
+
this.init_after(config);
|
|
157
|
+
}
|
|
158
|
+
|
|
134
159
|
/**
|
|
135
160
|
* 转译字符
|
|
136
161
|
* @param {String} body 字符串
|
|
@@ -244,7 +269,6 @@ Tpl.prototype.render_after = function(body, model, options) {
|
|
|
244
269
|
return body;
|
|
245
270
|
};
|
|
246
271
|
|
|
247
|
-
|
|
248
272
|
/**
|
|
249
273
|
* 渲染模板
|
|
250
274
|
* @param {String} body 模板
|
|
@@ -252,8 +276,7 @@ Tpl.prototype.render_after = function(body, model, options) {
|
|
|
252
276
|
* @param {Object} options 配置参数
|
|
253
277
|
* @return {String} view 渲染后的视图
|
|
254
278
|
*/
|
|
255
|
-
Tpl.prototype.
|
|
256
|
-
body = this.change(body);
|
|
279
|
+
Tpl.prototype.render_sub = function(body, model, options) {
|
|
257
280
|
var ret = this.render_before(body, model, options);
|
|
258
281
|
if (!ret) {
|
|
259
282
|
ret = this.render_main(body, model, options);
|
|
@@ -261,10 +284,22 @@ Tpl.prototype.render = function(body, model, options) {
|
|
|
261
284
|
ret = this.render_after(ret, model, options);
|
|
262
285
|
}
|
|
263
286
|
}
|
|
264
|
-
ret = this.change(ret, true);
|
|
265
287
|
return ret;
|
|
266
288
|
};
|
|
267
289
|
|
|
290
|
+
/**
|
|
291
|
+
* 渲染模板
|
|
292
|
+
* @param {String} body 模板
|
|
293
|
+
* @param {Object} model 数据模型
|
|
294
|
+
* @param {Object} options 配置参数
|
|
295
|
+
* @return {String} view 渲染后的视图
|
|
296
|
+
*/
|
|
297
|
+
Tpl.prototype.render = function(body, model, options) {
|
|
298
|
+
body = this.change(body);
|
|
299
|
+
body = this.render_sub(body);
|
|
300
|
+
return this.change(body, true);
|
|
301
|
+
};
|
|
302
|
+
|
|
268
303
|
/**
|
|
269
304
|
* 编译模板并返回渲染函数
|
|
270
305
|
* @param {String} body 模板
|
|
@@ -311,7 +346,10 @@ Tpl.prototype.view = function(file, model, options) {
|
|
|
311
346
|
}
|
|
312
347
|
var body = f.loadText();
|
|
313
348
|
if (body) {
|
|
314
|
-
|
|
349
|
+
body = this.change(body);
|
|
350
|
+
body = this.render_sub(body, model, options);
|
|
351
|
+
body = this.change(body, true);
|
|
352
|
+
return body;
|
|
315
353
|
} else {
|
|
316
354
|
return "";
|
|
317
355
|
}
|
package/package.json
CHANGED
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
<body>
|
|
8
8
|
<h5>${viewBag.name}</h5>
|
|
9
9
|
<ul>
|
|
10
|
-
|
|
11
|
-
<li
|
|
12
|
-
|
|
10
|
+
${loop arr value idx}
|
|
11
|
+
<li>${ value }</li>
|
|
12
|
+
${/loop}
|
|
13
13
|
</ul>
|
|
14
14
|
<ul>
|
|
15
|
-
|
|
15
|
+
<!--[ for(var i = 0; i < arr.length; i++) { ]-->
|
|
16
16
|
<li>${ arr[i] }</li>
|
|
17
|
-
|
|
17
|
+
<!--[ } ]-->
|
|
18
18
|
</ul>
|
|
19
19
|
<ul>
|
|
20
20
|
<!--{loop arr value idx}-->
|
package/cache/test.cache.html
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<title>超级美眉Art模板引擎</title>
|
|
6
|
-
</head>
|
|
7
|
-
<body>
|
|
8
|
-
<h5>系统名称</h5>
|
|
9
|
-
<p>您真的是人才!</p>
|
|
10
|
-
<p>您真的是人才!</p>
|
|
11
|
-
<ul>
|
|
12
|
-
<li>\123</li>
|
|
13
|
-
<li>\234</li>
|
|
14
|
-
</ul>
|
|
15
|
-
<ul>
|
|
16
|
-
<li>123</li>
|
|
17
|
-
<li>234</li>
|
|
18
|
-
</ul>
|
|
19
|
-
<ul>
|
|
20
|
-
<li>\123</li>
|
|
21
|
-
<li>\234</li>
|
|
22
|
-
</ul>
|
|
23
|
-
<script type="text/javascript">
|
|
24
|
-
var a_0 =123;
|
|
25
|
-
var a_1 =234;
|
|
26
|
-
</script>系统名称计算
|
|
27
|
-
123123'priceNIHAO'#计算
|
|
28
|
-
</body>
|
|
29
|
-
</html>
|
|
30
|
-
$
|