total5 0.0.1-1
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/503.html +65 -0
- package/CONTRIBUTING.md +55 -0
- package/LICENSE +211 -0
- package/README.md +32 -0
- package/api.js +289 -0
- package/bin/total5 +984 -0
- package/builders.js +1435 -0
- package/bundles.js +457 -0
- package/cache.js +58 -0
- package/changelog.txt +3 -0
- package/cluster.js +320 -0
- package/cms.js +625 -0
- package/controller.js +1419 -0
- package/cron.js +99 -0
- package/debug.js +539 -0
- package/edit.js +469 -0
- package/error.html +49 -0
- package/filestorage.js +1088 -0
- package/flow-flowstream.js +3152 -0
- package/flow.js +209 -0
- package/flowstream.js +1991 -0
- package/global.js +125 -0
- package/helpers/index.js +32 -0
- package/htmlparser.js +650 -0
- package/http.js +81 -0
- package/image.js +773 -0
- package/images.js +747 -0
- package/index.js +2658 -0
- package/jsonschema.js +691 -0
- package/ldap.js +792 -0
- package/mail.js +936 -0
- package/minificators.js +858 -0
- package/nosql-builder.js +440 -0
- package/nosql-querybuilder.js +316 -0
- package/nosql-reader.js +353 -0
- package/nosql-stream.js +617 -0
- package/nosql.js +763 -0
- package/openclient.js +219 -0
- package/package.json +32 -0
- package/pause.html +67 -0
- package/querybuilder.js +1361 -0
- package/release.js +167 -0
- package/routing.js +905 -0
- package/sourcemap.js +160 -0
- package/tangular.js +409 -0
- package/templates.js +145 -0
- package/templates.json +74 -0
- package/tms.js +384 -0
- package/tmsclient.js +125 -0
- package/todo.txt +7 -0
- package/tools/beta.sh +6 -0
- package/tools/release.sh +6 -0
- package/uibuilder.js +206 -0
- package/utils.js +6374 -0
- package/viewengine.js +880 -0
- package/websocket.js +1939 -0
- package/workers.js +129 -0
package/cms.js
ADDED
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
// Total.js CMS compiler
|
|
2
|
+
// The MIT License
|
|
3
|
+
// Copyright 2021-2023 (c) Peter Širka <petersirka@gmail.com>
|
|
4
|
+
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
const SKIP_CLASSES = { CMS_hidden: 1, CMS_mv: 1, CMS_mh: 1, CMS_expression: 1, CMS_multiple: 1 };
|
|
8
|
+
const VERSION = 1;
|
|
9
|
+
|
|
10
|
+
function clean(html) {
|
|
11
|
+
var index = html.indexOf('>');
|
|
12
|
+
var tag = html.substring(5, index);
|
|
13
|
+
tag = tag.replace(/data-cms=".*?"(\s)?|data-cms-id=".*?"(\s)?/, '').trim();
|
|
14
|
+
return '<div' + (tag ? (' ' + tag) : '') + '>' + html.substring(index + 1);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function expressions_multiple(body) {
|
|
18
|
+
|
|
19
|
+
var index = 0;
|
|
20
|
+
var arr = [];
|
|
21
|
+
|
|
22
|
+
while (true) {
|
|
23
|
+
|
|
24
|
+
index = body.indexOf('CMS_multiple', index + 12);
|
|
25
|
+
|
|
26
|
+
if (index === -1)
|
|
27
|
+
break;
|
|
28
|
+
|
|
29
|
+
var b = body.lastIndexOf('<', index);
|
|
30
|
+
var tag = body.substring(b + 1, body.indexOf(' ', b));
|
|
31
|
+
|
|
32
|
+
var e = body.indexOf('</' + tag + '>', index);
|
|
33
|
+
var size = e + 3 + tag.length;
|
|
34
|
+
var obj = {};
|
|
35
|
+
|
|
36
|
+
obj.id = body.substring(b, body.indexOf('>', b + tag.length)).match(/\s(data-cms-|data-)?id=".*?"/);
|
|
37
|
+
|
|
38
|
+
if (obj.id) {
|
|
39
|
+
obj.id = obj.id[0];
|
|
40
|
+
var qi = obj.id.indexOf('"');
|
|
41
|
+
obj.id = obj.id.substring(qi + 1, obj.id.length - 1).trim();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
obj.html = body.substring(b, size);
|
|
45
|
+
obj.body = obj.html.substring(obj.html.indexOf('>') + 1, obj.html.lastIndexOf('<'));
|
|
46
|
+
obj.expressions = expressions(obj.body);
|
|
47
|
+
obj.replace = '<!--cmsmultiple' + GUID(10) + '-->';
|
|
48
|
+
|
|
49
|
+
arr.push(obj);
|
|
50
|
+
index = e + 3 + tag.length;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return arr;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function expressions(body) {
|
|
57
|
+
|
|
58
|
+
var index = 0;
|
|
59
|
+
var arr = [];
|
|
60
|
+
|
|
61
|
+
while (true) {
|
|
62
|
+
|
|
63
|
+
index = body.indexOf('CMS_expression', index + 10);
|
|
64
|
+
|
|
65
|
+
if (index === -1)
|
|
66
|
+
break;
|
|
67
|
+
|
|
68
|
+
var b = body.lastIndexOf('<', index);
|
|
69
|
+
var tag = body.substring(b + 1, body.indexOf(' ', b));
|
|
70
|
+
|
|
71
|
+
var e = body.indexOf('</' + tag + '>', index);
|
|
72
|
+
var size = e + 3 + tag.length;
|
|
73
|
+
var obj = {};
|
|
74
|
+
obj.replace = obj.html = body.substring(b, size);
|
|
75
|
+
obj.body = obj.html.substring(obj.html.indexOf('>') + 1, obj.html.lastIndexOf('<'));
|
|
76
|
+
obj.text = obj.body.removeTags();
|
|
77
|
+
arr.push(obj);
|
|
78
|
+
index = e + 3 + tag.length;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return arr;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function trash(body) {
|
|
85
|
+
var index = 0;
|
|
86
|
+
var tags = ['CMS_trash', 'CMS_editor'];
|
|
87
|
+
|
|
88
|
+
for (var t of tags) {
|
|
89
|
+
while (true) {
|
|
90
|
+
|
|
91
|
+
index = body.indexOf(t, index + t.length);
|
|
92
|
+
|
|
93
|
+
if (index === -1) {
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
var b = body.lastIndexOf('<', index);
|
|
98
|
+
var tag = body.substring(b + 1, body.indexOf(' ', b));
|
|
99
|
+
var e = body.indexOf('</' + tag + '>', index);
|
|
100
|
+
var size = e + 3 + tag.length;
|
|
101
|
+
body = body.replace(body.substring(b, size), '');
|
|
102
|
+
index = b;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return body;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function layout(body, append) {
|
|
110
|
+
|
|
111
|
+
var index = body.indexOf(' id="CMS"');
|
|
112
|
+
if (index === -1)
|
|
113
|
+
return body;
|
|
114
|
+
|
|
115
|
+
var beg = body.lastIndexOf('<', index);
|
|
116
|
+
if (beg === -1)
|
|
117
|
+
return body;
|
|
118
|
+
|
|
119
|
+
var tag = body.substring(beg + 1, body.indexOf(' ', beg));
|
|
120
|
+
var tagend = '</' + tag + '>';
|
|
121
|
+
var count = 0;
|
|
122
|
+
var end = body.indexOf('>', beg) + 1;
|
|
123
|
+
|
|
124
|
+
tag = '<' + tag;
|
|
125
|
+
|
|
126
|
+
while (true) {
|
|
127
|
+
|
|
128
|
+
var str = body.substring(index, index + tagend.length);
|
|
129
|
+
|
|
130
|
+
if (index >= body.length) {
|
|
131
|
+
beg = body.length;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (str === tagend) {
|
|
136
|
+
if (count) {
|
|
137
|
+
count--;
|
|
138
|
+
index++;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
return body.substring(0, end) + append + body.substring(index);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (str.substring(0, tag.length) === tag)
|
|
145
|
+
count++;
|
|
146
|
+
|
|
147
|
+
index++;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return body;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Cleans CMS markup
|
|
154
|
+
function tidy(body) {
|
|
155
|
+
|
|
156
|
+
var beg;
|
|
157
|
+
var end;
|
|
158
|
+
var index = 0;
|
|
159
|
+
var count = 0;
|
|
160
|
+
var c = 'CMS_unwrap';
|
|
161
|
+
var tag;
|
|
162
|
+
var tagend;
|
|
163
|
+
|
|
164
|
+
body = F.TUtils.minify_html(body);
|
|
165
|
+
|
|
166
|
+
while (true) {
|
|
167
|
+
|
|
168
|
+
beg = body.indexOf(c, beg);
|
|
169
|
+
|
|
170
|
+
if (beg === -1)
|
|
171
|
+
break;
|
|
172
|
+
|
|
173
|
+
index = beg;
|
|
174
|
+
while (true) {
|
|
175
|
+
if (body[--index] === '<' || index <= 0)
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (index === beg || index <= 0)
|
|
180
|
+
return;
|
|
181
|
+
|
|
182
|
+
tag = body.substring(index + 1, body.indexOf('>', index + 1));
|
|
183
|
+
end = index + tag.length + 2;
|
|
184
|
+
tag = tag.substring(0, tag.indexOf(' '));
|
|
185
|
+
tagend = '</' + tag;
|
|
186
|
+
tag = '<' + tag;
|
|
187
|
+
count = 0;
|
|
188
|
+
beg = index;
|
|
189
|
+
index = end;
|
|
190
|
+
|
|
191
|
+
while (true) {
|
|
192
|
+
var str = body.substring(index, index + tagend.length);
|
|
193
|
+
|
|
194
|
+
if (index >= body.length) {
|
|
195
|
+
beg = body.length;
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (str === tagend) {
|
|
200
|
+
|
|
201
|
+
if (count) {
|
|
202
|
+
count--;
|
|
203
|
+
index++;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
body = body.substring(0, beg) + body.substring(end, index) + body.substring(index + 1 + tagend.length);
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (str.substring(0, tag.length) === tag)
|
|
212
|
+
count++;
|
|
213
|
+
|
|
214
|
+
index++;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return body.replace(/(\s)class=".*?"/g, function(text) {
|
|
219
|
+
|
|
220
|
+
var is = text[0] === ' ';
|
|
221
|
+
var arr = text.substring(is ? 8 : 7, text.length - 1).split(' ');
|
|
222
|
+
var builder = '';
|
|
223
|
+
|
|
224
|
+
for (var i = 0; i < arr.length; i++) {
|
|
225
|
+
var cls = arr[i];
|
|
226
|
+
if (cls[0] === 'C' && cls[1] === 'M' && cls[2] === 'S' && !SKIP_CLASSES[cls])
|
|
227
|
+
continue;
|
|
228
|
+
builder += (builder ? ' ' : '') + cls;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return builder ? ((is ? ' ' : '') + 'class="' + builder + '"') : '';
|
|
232
|
+
|
|
233
|
+
}).replace(/<div\s>/g, '<div>');
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
exports.compile = function(html, widgets, used) {
|
|
237
|
+
|
|
238
|
+
var arr = html.match(/data-cms=".*?"/g) || EMPTYARRAY;
|
|
239
|
+
var response = new CMSRender();
|
|
240
|
+
var indexer = 0;
|
|
241
|
+
var index;
|
|
242
|
+
var beg;
|
|
243
|
+
var end;
|
|
244
|
+
|
|
245
|
+
response.css = [];
|
|
246
|
+
response.js = [];
|
|
247
|
+
response.widgets = [];
|
|
248
|
+
response.cache = {};
|
|
249
|
+
response.tangular = [];
|
|
250
|
+
|
|
251
|
+
if (!used) {
|
|
252
|
+
for (var widget of widgets) {
|
|
253
|
+
if (widget.css)
|
|
254
|
+
response.css.push(F.TUtils.minify_css(widget.css));
|
|
255
|
+
if (widget.js)
|
|
256
|
+
response.js.push(F.TUtils.minify_js(widget.js));
|
|
257
|
+
if (widget.ui) {
|
|
258
|
+
widget.ui.css && response.css.push(F.TUtils.minify_css(widget.ui.css));
|
|
259
|
+
widget.ui.js && response.js.push(F.TUtils.minify_js(widget.ui.js));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
for (var attr of arr) {
|
|
265
|
+
|
|
266
|
+
if (html.indexOf(attr) === -1)
|
|
267
|
+
continue;
|
|
268
|
+
|
|
269
|
+
var w = attr.substring(10);
|
|
270
|
+
var index = w.indexOf('__');
|
|
271
|
+
var id = w.substring(0, index);
|
|
272
|
+
|
|
273
|
+
index = html.lastIndexOf('<', html.indexOf(attr));
|
|
274
|
+
beg = '<div';
|
|
275
|
+
end = '</div>';
|
|
276
|
+
|
|
277
|
+
var pos = index + 1;
|
|
278
|
+
var count = 0;
|
|
279
|
+
var counter = 0;
|
|
280
|
+
|
|
281
|
+
while (true) {
|
|
282
|
+
|
|
283
|
+
if (counter++ > 100)
|
|
284
|
+
break;
|
|
285
|
+
|
|
286
|
+
var a = html.indexOf(beg, pos);
|
|
287
|
+
var b = html.indexOf(end, pos);
|
|
288
|
+
|
|
289
|
+
if (a !== -1 && a < b) {
|
|
290
|
+
count++;
|
|
291
|
+
pos = html.indexOf('>', a);
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (a === -1 || b < a) {
|
|
296
|
+
|
|
297
|
+
pos = b + 6;
|
|
298
|
+
|
|
299
|
+
if (count) {
|
|
300
|
+
count--;
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
var widget = widgets instanceof Array ? widgets.findItem('id', id) : widgets[id];
|
|
309
|
+
var body = html.substring(index, pos);
|
|
310
|
+
|
|
311
|
+
// Widget not found
|
|
312
|
+
if (!widget) {
|
|
313
|
+
html = html.replace(body, '');
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (used) {
|
|
318
|
+
|
|
319
|
+
if (widget.css)
|
|
320
|
+
response.css.push(F.TUtils.minify_css(widget.css));
|
|
321
|
+
|
|
322
|
+
if (widget.js)
|
|
323
|
+
response.js.push(F.TUtils.minify_js(widget.js));
|
|
324
|
+
|
|
325
|
+
if (widget.ui) {
|
|
326
|
+
widget.ui.css && response.css.push(F.TUtils.minify_css(widget.ui.css));
|
|
327
|
+
widget.ui.js && response.js.push(F.TUtils.minify_js(widget.ui.js));
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (!widget.render) {
|
|
333
|
+
html = html.replace(body, clean(body));
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
html = html.replace(body, '~WIDGET' + indexer + '~');
|
|
338
|
+
index = body.indexOf('>');
|
|
339
|
+
body = body.substring(0, index + 1) + '~BEG~' + body.substring(index + 1);
|
|
340
|
+
index = body.lastIndexOf('<');
|
|
341
|
+
body = body.substring(0, index) + '~END~' + body.substring(index);
|
|
342
|
+
|
|
343
|
+
index = w.indexOf('__');
|
|
344
|
+
var config = decodeURIComponent(w.substring(index + 2, w.length - 1)).parseJSON(true);
|
|
345
|
+
|
|
346
|
+
var opt = {};
|
|
347
|
+
opt.id = id;
|
|
348
|
+
opt.indexer = indexer;
|
|
349
|
+
opt.body = tidy(clean(body));
|
|
350
|
+
opt.text = body.substring(body.lastIndexOf('~BEG~') + 5, body.lastIndexOf('~END~'));
|
|
351
|
+
opt.config = config || EMPTYOBJECT;
|
|
352
|
+
opt.render = widget.render;
|
|
353
|
+
opt.beg = opt.body.substring(0, opt.body.indexOf('>') + 1);
|
|
354
|
+
opt.end = opt.body.substring(opt.body.lastIndexOf('<'));
|
|
355
|
+
|
|
356
|
+
index = opt.beg.indexOf('data-cms-id="');
|
|
357
|
+
|
|
358
|
+
if (index === -1)
|
|
359
|
+
opt.uid = opt.beg.makeid();
|
|
360
|
+
else
|
|
361
|
+
opt.uid = opt.beg.substring(index + 13, opt.beg.indexOf('"', index + 14));
|
|
362
|
+
|
|
363
|
+
response.widgets.push(opt);
|
|
364
|
+
indexer++;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
index = 0;
|
|
368
|
+
|
|
369
|
+
while (true) {
|
|
370
|
+
|
|
371
|
+
index = html.indexOf(' type="text/navigation"', index);
|
|
372
|
+
|
|
373
|
+
if (index === -1)
|
|
374
|
+
break;
|
|
375
|
+
|
|
376
|
+
var beg = html.lastIndexOf('<script', index);
|
|
377
|
+
var end = html.indexOf('</script>', index);
|
|
378
|
+
var endhead = html.indexOf('>', index);
|
|
379
|
+
var head = html.substring(beg, endhead);
|
|
380
|
+
var name = head.match(/name=".*?"/i)[0];
|
|
381
|
+
var template = html.substring(html.indexOf('>', endhead) + 1, end);
|
|
382
|
+
|
|
383
|
+
name = name.substring(6, name.length - 1);
|
|
384
|
+
html = html.replace(html.substring(beg, end + 9), '~WIDGET#' + response.tangular.length + '~');
|
|
385
|
+
response.tangular.push({ id: HASH(name).toString(36), name: name, type: 'nav', template: Tangular.compile(template) });
|
|
386
|
+
index = beg;
|
|
387
|
+
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
index = 0;
|
|
391
|
+
|
|
392
|
+
while (true) {
|
|
393
|
+
|
|
394
|
+
index = html.indexOf(' type="text/breadcrumb"', index);
|
|
395
|
+
|
|
396
|
+
if (index === -1)
|
|
397
|
+
break;
|
|
398
|
+
|
|
399
|
+
var beg = html.lastIndexOf('<script', index);
|
|
400
|
+
var end = html.indexOf('</script>', index);
|
|
401
|
+
var endhead = html.indexOf('>', index);
|
|
402
|
+
var template = html.substring(html.indexOf('>', endhead) + 1, end);
|
|
403
|
+
html = html.replace(html.substring(beg, end + 9), '~WIDGET#' + response.tangular.length + '~');
|
|
404
|
+
response.tangular.push({ type: 'breadcrumb', template: Tangular.compile(template) });
|
|
405
|
+
index = beg;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
response.html = tidy(trash(layout(html, '~WIDGETLAYOUT~')));
|
|
409
|
+
response.multiple = expressions_multiple(response.html);
|
|
410
|
+
|
|
411
|
+
for (var item of response.multiple)
|
|
412
|
+
response.html = response.html.replace(item.html, item.replace);
|
|
413
|
+
|
|
414
|
+
response.expressions = expressions(response.html);
|
|
415
|
+
response.widgets.reverse();
|
|
416
|
+
|
|
417
|
+
var builder = [];
|
|
418
|
+
var text = [];
|
|
419
|
+
|
|
420
|
+
while (true) {
|
|
421
|
+
|
|
422
|
+
beg = response.html.indexOf('~WIDGET');
|
|
423
|
+
|
|
424
|
+
if (beg !== -1) {
|
|
425
|
+
end = response.html.indexOf('~', beg + 6) + 1;
|
|
426
|
+
var h = response.html.substring(0, beg);
|
|
427
|
+
var windex = response.html.substring(beg + 7, end - 1);
|
|
428
|
+
if (windex[0] === '#') {
|
|
429
|
+
response.html = response.html.substring(end);
|
|
430
|
+
builder.push('text[{0}]+tangular[{1}]'.format(text.push(h) - 1, windex.substring(1)));
|
|
431
|
+
} else if (windex === 'LAYOUT') {
|
|
432
|
+
response.html = response.html.substring(end);
|
|
433
|
+
builder.push('text[{0}]+body'.format(text.push(h) - 1));
|
|
434
|
+
} else {
|
|
435
|
+
indexer = +windex;
|
|
436
|
+
response.html = response.html.substring(end);
|
|
437
|
+
if (h)
|
|
438
|
+
builder.push('text[{0}]+widget[{1}]'.format(text.push(h) - 1, indexer));
|
|
439
|
+
else
|
|
440
|
+
builder.push('widget[{0}]'.format(indexer));
|
|
441
|
+
}
|
|
442
|
+
} else {
|
|
443
|
+
builder.push('text[{0}]'.format(text.push(response.html) - 1));
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
response.js = response.js.length ? response.js.join('\n') : '';
|
|
449
|
+
response.css = response.css.length ? response.css.join('') : '';
|
|
450
|
+
response.toString = new Function('text', 'widget', 'tangular', 'body', 'return ' + builder.join('+'));
|
|
451
|
+
response.text = text;
|
|
452
|
+
|
|
453
|
+
delete response.html;
|
|
454
|
+
return response;
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
function CMSRender() {}
|
|
458
|
+
|
|
459
|
+
CMSRender.prototype.importmeta = function(val) {
|
|
460
|
+
var self = this;
|
|
461
|
+
for (var i = 0; i < self.text.length; i++) {
|
|
462
|
+
var item = self.text[i];
|
|
463
|
+
var index = item.indexOf('</head');
|
|
464
|
+
if (index !== -1) {
|
|
465
|
+
self.text[i] = item.substring(0, index) + val + item.substring(index);
|
|
466
|
+
return self;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return self;
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
CMSRender.prototype.importcss = function(val) {
|
|
473
|
+
|
|
474
|
+
var self = this;
|
|
475
|
+
|
|
476
|
+
if (val == null) {
|
|
477
|
+
if (self.css)
|
|
478
|
+
val = '<style>' + self.css + '</style>';
|
|
479
|
+
else
|
|
480
|
+
return self;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
for (var i = 0; i < self.text.length; i++) {
|
|
484
|
+
var item = self.text[i];
|
|
485
|
+
var index = item.indexOf('</head');
|
|
486
|
+
if (index !== -1) {
|
|
487
|
+
self.text[i] = item.substring(0, index) + val + item.substring(index);
|
|
488
|
+
return self;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
self.text[0] += val;
|
|
493
|
+
return self;
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
CMSRender.prototype.importjs = function(val) {
|
|
497
|
+
var self = this;
|
|
498
|
+
|
|
499
|
+
if (val == null) {
|
|
500
|
+
if (self.js)
|
|
501
|
+
val = '<script>' + self.js + '</script>';
|
|
502
|
+
else
|
|
503
|
+
return self;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
for (var i = 0; i < self.text.length; i++) {
|
|
507
|
+
var item = self.text[i];
|
|
508
|
+
var index = item.indexOf('</body>');
|
|
509
|
+
if (index !== -1) {
|
|
510
|
+
self.text[i] = item.substring(0, index) + val + item.substring(index);
|
|
511
|
+
return self;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
self.text[self.text.length - 1] += val;
|
|
516
|
+
return self;
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
CMSRender.prototype.render = function(meta, layout, callback) {
|
|
520
|
+
var self = this;
|
|
521
|
+
if (callback)
|
|
522
|
+
self._render(meta, layout, callback);
|
|
523
|
+
else
|
|
524
|
+
return new Promise((resolve, reject) => self._render(meta, layout, (err, res) => err ? reject(err) : resolve(res)));
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
CMSRender.prototype._render = function(meta, layout, callback) {
|
|
528
|
+
|
|
529
|
+
// meta.controller {Object}
|
|
530
|
+
// meta.url {String}
|
|
531
|
+
// meta.vars {Object}
|
|
532
|
+
// meta.refs {Object}
|
|
533
|
+
// meta.body {String} targeted for the layout
|
|
534
|
+
// meta.nav {Object Array}
|
|
535
|
+
// meta.breadcrumb {Object Array}
|
|
536
|
+
// meta.widgets {Object Array}
|
|
537
|
+
|
|
538
|
+
if (typeof(layout) === 'function') {
|
|
539
|
+
callback = layout;
|
|
540
|
+
layout = null;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
var self = this;
|
|
544
|
+
var widgets = [];
|
|
545
|
+
var opt = {};
|
|
546
|
+
|
|
547
|
+
for (var key in meta) {
|
|
548
|
+
if (key !== 'widgets')
|
|
549
|
+
opt[key] = meta[key];
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
self.widgets.wait(function(item, next) {
|
|
553
|
+
|
|
554
|
+
opt.id = item.uid;
|
|
555
|
+
opt.widget = item.id;
|
|
556
|
+
opt.version = VERSION;
|
|
557
|
+
opt.config = item.config;
|
|
558
|
+
opt.body = item.body || '';
|
|
559
|
+
opt.html = item.html || '';
|
|
560
|
+
opt.template = item.template;
|
|
561
|
+
opt.cacheid = opt.id;
|
|
562
|
+
|
|
563
|
+
var render = item.render;
|
|
564
|
+
if (meta.widgets) {
|
|
565
|
+
var w = meta.widgets instanceof Array ? meta.widgets.findItem('id', item.id) : meta.widgets[item.id];
|
|
566
|
+
if (w) {
|
|
567
|
+
render = w.render;
|
|
568
|
+
if (w.cache === 'url' && opt.url)
|
|
569
|
+
opt.cacheid += '_' + HASH(opt.url).toString(36);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
if (self.cache[opt.cacheid]) {
|
|
574
|
+
widgets[item.indexer] = self.cache[opt.cacheid];
|
|
575
|
+
next();
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
render(opt, function(response, replace, cache) {
|
|
580
|
+
widgets[item.indexer] = replace === true ? response == null ? '' : (response + '').replace(/~(BEG|END)~/g, '') : (item.beg + (response || '') + item.end);
|
|
581
|
+
if (cache)
|
|
582
|
+
self.cache[opt.cacheid] = widgets[item.indexer];
|
|
583
|
+
next();
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
}, function() {
|
|
587
|
+
|
|
588
|
+
var tangular = [];
|
|
589
|
+
|
|
590
|
+
// opt.inlinecache {Object} user defined cache
|
|
591
|
+
|
|
592
|
+
for (let i = 0; i < self.tangular.length; i++) {
|
|
593
|
+
|
|
594
|
+
let key = i + '';
|
|
595
|
+
let body = opt.inlinecache ? opt.inlinecache[key] : '';
|
|
596
|
+
|
|
597
|
+
if (!body) {
|
|
598
|
+
let item = self.tangular[i];
|
|
599
|
+
switch (item.type) {
|
|
600
|
+
case 'nav':
|
|
601
|
+
body = item.template({ value: opt.navigation ? opt.navigation(item.id) : null });
|
|
602
|
+
break;
|
|
603
|
+
case 'breadcrumb':
|
|
604
|
+
body = item.template({ value: opt.breadcrumb || EMPTYARRAY });
|
|
605
|
+
break;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
if (opt.inlinecache) {
|
|
609
|
+
body = body.replace(/\t|\s{2,}/g, '');
|
|
610
|
+
opt.inlinecache[key] = body;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
tangular.push(body);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
var html = self.toString(self.text, widgets, tangular, meta.body || '');
|
|
618
|
+
if (layout) {
|
|
619
|
+
meta.body = html;
|
|
620
|
+
layout.render(meta, callback);
|
|
621
|
+
} else
|
|
622
|
+
callback.call(self, null, html, self);
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
};
|