total5 0.0.13-7 → 0.0.13-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/builders.js +77 -58
- package/changelog.txt +12 -0
- package/filestorage.js +7 -7
- package/global.js +25 -0
- package/htmlparser.js +97 -97
- package/markdown.js +11 -0
- package/package.json +1 -1
- package/querybuilder.js +23 -16
- package/routing.js +15 -11
- package/utils.js +78 -43
- package/viewengine.js +38 -12
package/builders.js
CHANGED
|
@@ -136,7 +136,6 @@ Options.prototype.promisify = function(fn, a, b, c) {
|
|
|
136
136
|
|
|
137
137
|
var callback = function(err, response) {
|
|
138
138
|
if (err)
|
|
139
|
-
|
|
140
139
|
$.invalid(err);
|
|
141
140
|
else
|
|
142
141
|
resolve(response);
|
|
@@ -352,13 +351,18 @@ ErrorBuilder.prototype = {
|
|
|
352
351
|
}
|
|
353
352
|
};
|
|
354
353
|
|
|
354
|
+
ErrorBuilder.prototype.throw = function() {
|
|
355
|
+
this.$throw = true;
|
|
356
|
+
return this;
|
|
357
|
+
};
|
|
358
|
+
|
|
355
359
|
ErrorBuilder.prototype.reject = function(language) {
|
|
356
|
-
|
|
357
|
-
return new Error(self.toString(language, ''));
|
|
360
|
+
return new Error(this.toString(language, ''));
|
|
358
361
|
};
|
|
359
362
|
|
|
360
363
|
ErrorBuilder.prototype.push = function(err, path, index) {
|
|
361
|
-
|
|
364
|
+
|
|
365
|
+
let self = this;
|
|
362
366
|
|
|
363
367
|
if (!err)
|
|
364
368
|
err = 401;
|
|
@@ -368,24 +372,36 @@ ErrorBuilder.prototype.push = function(err, path, index) {
|
|
|
368
372
|
self.items.push({ error: F.TUtils.httpstatus(err) });
|
|
369
373
|
} else
|
|
370
374
|
self.items.push({ error: err.toString(), path: path, index: index });
|
|
375
|
+
|
|
376
|
+
if (self.$throw) {
|
|
377
|
+
let errors = self.output();
|
|
378
|
+
throw new Error(errors[0].error);
|
|
379
|
+
}
|
|
380
|
+
|
|
371
381
|
return self;
|
|
372
382
|
};
|
|
373
383
|
|
|
374
384
|
ErrorBuilder.prototype.push2 = function(name, path, index) {
|
|
375
|
-
|
|
385
|
+
let self = this;
|
|
376
386
|
self.items.push({ name: self.prefix + name, error: '@', path: path, index: index });
|
|
387
|
+
|
|
388
|
+
if (self.$throw) {
|
|
389
|
+
let errors = self.output();
|
|
390
|
+
throw new Error(errors[0].error);
|
|
391
|
+
}
|
|
392
|
+
|
|
377
393
|
return self;
|
|
378
394
|
};
|
|
379
395
|
|
|
380
396
|
ErrorBuilder.assign = function(arr) {
|
|
381
|
-
|
|
397
|
+
let builder = new ErrorBuilder();
|
|
382
398
|
if (arr instanceof Array) {
|
|
383
|
-
for (
|
|
399
|
+
for (let i = 0; i < arr.length; i++) {
|
|
384
400
|
if (arr[i].error)
|
|
385
401
|
builder.items.push(arr[i]);
|
|
386
402
|
}
|
|
387
403
|
} else {
|
|
388
|
-
|
|
404
|
+
let type = typeof(arr);
|
|
389
405
|
if (type === 'number' || type === 'string')
|
|
390
406
|
builder.push(arr);
|
|
391
407
|
else if (arr instanceof Error)
|
|
@@ -395,7 +411,7 @@ ErrorBuilder.assign = function(arr) {
|
|
|
395
411
|
};
|
|
396
412
|
|
|
397
413
|
ErrorBuilder.prototype.replace = function(search, value) {
|
|
398
|
-
|
|
414
|
+
let self = this;
|
|
399
415
|
if (!self.replacer)
|
|
400
416
|
self.replacer = {};
|
|
401
417
|
self.replacer[search] = value;
|
|
@@ -404,16 +420,30 @@ ErrorBuilder.prototype.replace = function(search, value) {
|
|
|
404
420
|
|
|
405
421
|
ErrorBuilder.prototype.output = function(language = 'default') {
|
|
406
422
|
|
|
407
|
-
|
|
408
|
-
|
|
423
|
+
let self = this;
|
|
424
|
+
let output = [];
|
|
409
425
|
|
|
410
426
|
for (let m of self.items) {
|
|
411
427
|
|
|
412
428
|
let err = m.error;
|
|
413
429
|
|
|
414
|
-
if (err == '@')
|
|
415
|
-
|
|
416
|
-
|
|
430
|
+
if (err == '@') {
|
|
431
|
+
|
|
432
|
+
let key = err === '@' ? m.name : err.substring(1);
|
|
433
|
+
let is = false;
|
|
434
|
+
|
|
435
|
+
if (self.dictionary) {
|
|
436
|
+
let tmp = self.dictionary[key];
|
|
437
|
+
if (tmp) {
|
|
438
|
+
err = tmp[0] === '@(' ? F.translate(language, tmp) : tmp;
|
|
439
|
+
is = true;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (!is)
|
|
444
|
+
err = F.resource(language, (err === '@' ? key : ('T' + key).hash(true).toString(36))) || 'The field "' + key + '" is invalid';
|
|
445
|
+
|
|
446
|
+
} else if (err[0] === '@')
|
|
417
447
|
err = F.translate(language, err);
|
|
418
448
|
|
|
419
449
|
if (self.replacer) {
|
|
@@ -546,6 +576,12 @@ RESTP.debug = function() {
|
|
|
546
576
|
return this;
|
|
547
577
|
};
|
|
548
578
|
|
|
579
|
+
RESTP.base64 = function() {
|
|
580
|
+
var self = this;
|
|
581
|
+
self.$base64 = true;;
|
|
582
|
+
return self;
|
|
583
|
+
};
|
|
584
|
+
|
|
549
585
|
RESTP.unixsocket = function(socket, path) {
|
|
550
586
|
var self = this;
|
|
551
587
|
self.options.unixsocket = { socket: socket, path: path };
|
|
@@ -624,11 +660,6 @@ RESTP.auth = function(user, password) {
|
|
|
624
660
|
return this;
|
|
625
661
|
};
|
|
626
662
|
|
|
627
|
-
RESTP.convert = function(convert) {
|
|
628
|
-
this.$convert = convert;
|
|
629
|
-
return this;
|
|
630
|
-
};
|
|
631
|
-
|
|
632
663
|
RESTP.nodnscache = function() {
|
|
633
664
|
this.options.resolve = false;
|
|
634
665
|
return this;
|
|
@@ -741,14 +772,11 @@ RESTP.accept = function(ext) {
|
|
|
741
772
|
return this;
|
|
742
773
|
};
|
|
743
774
|
|
|
744
|
-
RESTP.xml = function(data
|
|
775
|
+
RESTP.xml = function(data) {
|
|
745
776
|
|
|
746
777
|
if (this.options.method === 'GET')
|
|
747
778
|
this.options.method = 'POST';
|
|
748
779
|
|
|
749
|
-
if (replace)
|
|
750
|
-
this.$replace = true;
|
|
751
|
-
|
|
752
780
|
this.options.type = 'xml';
|
|
753
781
|
data && this.raw(data, this.options.type);
|
|
754
782
|
return this;
|
|
@@ -843,24 +871,6 @@ RESTP.cache = function(expire) {
|
|
|
843
871
|
return this;
|
|
844
872
|
};
|
|
845
873
|
|
|
846
|
-
RESTP.set = function(name, value) {
|
|
847
|
-
if (!this.options.body)
|
|
848
|
-
this.options.body = {};
|
|
849
|
-
if (typeof(name) !== 'object') {
|
|
850
|
-
this.options.body[name] = value;
|
|
851
|
-
} else {
|
|
852
|
-
for (var key in name)
|
|
853
|
-
this.options.body[key] = name[key];
|
|
854
|
-
}
|
|
855
|
-
return this;
|
|
856
|
-
};
|
|
857
|
-
|
|
858
|
-
RESTP.rem = function(name) {
|
|
859
|
-
if (this.options.body && this.options.body[name])
|
|
860
|
-
this.options.body[name] = undefined;
|
|
861
|
-
return this;
|
|
862
|
-
};
|
|
863
|
-
|
|
864
874
|
RESTP.progress = function(fn) {
|
|
865
875
|
this.options.onprogress = fn;
|
|
866
876
|
return this;
|
|
@@ -873,6 +883,12 @@ RESTP.stream = function(callback) {
|
|
|
873
883
|
return self;
|
|
874
884
|
};
|
|
875
885
|
|
|
886
|
+
RESTP.convert = function(schema) {
|
|
887
|
+
let self = this;
|
|
888
|
+
self.$jsonschema = schema.toJSONSchema();
|
|
889
|
+
return self;
|
|
890
|
+
};
|
|
891
|
+
|
|
876
892
|
function streamresponse(builder, callback) {
|
|
877
893
|
builder.exec(callback);
|
|
878
894
|
}
|
|
@@ -953,7 +969,7 @@ RESTP.exec = function(callback) {
|
|
|
953
969
|
|
|
954
970
|
function restbuilder_callback(err, response) {
|
|
955
971
|
|
|
956
|
-
|
|
972
|
+
let self = response.builder;
|
|
957
973
|
|
|
958
974
|
if (self.options.custom) {
|
|
959
975
|
if (self.$resolve) {
|
|
@@ -972,30 +988,33 @@ function restbuilder_callback(err, response) {
|
|
|
972
988
|
return;
|
|
973
989
|
}
|
|
974
990
|
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
991
|
+
let callback = self.$callback;
|
|
992
|
+
let key = self.$cachekey;
|
|
993
|
+
let type = err ? '' : response.headers['content-type'] || '';
|
|
994
|
+
let output = new RESTBuilderResponse();
|
|
979
995
|
|
|
980
996
|
if (self.options.cook && self.options.cookies)
|
|
981
997
|
output.cookies = self.options.cookies;
|
|
982
998
|
|
|
983
999
|
if (type) {
|
|
984
|
-
|
|
1000
|
+
let index = type.lastIndexOf(';');
|
|
985
1001
|
if (index !== -1)
|
|
986
1002
|
type = type.substring(0, index).trim();
|
|
987
1003
|
}
|
|
988
1004
|
|
|
989
|
-
|
|
990
|
-
|
|
1005
|
+
let ishead = response.status === 204;
|
|
1006
|
+
|
|
1007
|
+
if (ishead)
|
|
991
1008
|
output.value = response.status < 400;
|
|
992
|
-
|
|
1009
|
+
else if (self.$plain || self.$noparse)
|
|
993
1010
|
output.value = response.body;
|
|
994
|
-
|
|
1011
|
+
else if (self.$base64)
|
|
1012
|
+
output.value = response.body instanceof Buffer ? response.body.toString('base64') : Buffer.from(response.body, 'utf8').toString('base64');
|
|
1013
|
+
else {
|
|
995
1014
|
switch (type.toLowerCase()) {
|
|
996
1015
|
case 'text/xml':
|
|
997
1016
|
case 'application/xml':
|
|
998
|
-
output.value = response.body ? response.body.
|
|
1017
|
+
output.value = response.body ? response.body.parseXML2() : null;
|
|
999
1018
|
break;
|
|
1000
1019
|
case 'application/x-www-form-urlencoded':
|
|
1001
1020
|
output.value = response.body ? DEF.parsers.urlencoded(response.body) : {};
|
|
@@ -1026,7 +1045,7 @@ function restbuilder_callback(err, response) {
|
|
|
1026
1045
|
if (self.$debug)
|
|
1027
1046
|
console.log('--DEBUG-- RESTBuilder: ' + response.status + ' ' + self.options.method + ' ' + QUERIFY(self.options.url || (self.options.unixsocket + self.options.path), self.options.query), '|', 'Error:', err, '|', 'Response:', response.body);
|
|
1028
1047
|
|
|
1029
|
-
|
|
1048
|
+
let val = output.value;
|
|
1030
1049
|
|
|
1031
1050
|
if (!err && output.status >= 400) {
|
|
1032
1051
|
err = output.status;
|
|
@@ -1085,22 +1104,22 @@ function RESTBuilderResponse() {}
|
|
|
1085
1104
|
|
|
1086
1105
|
RESTBuilderResponse.prototype.cookie = function(name) {
|
|
1087
1106
|
|
|
1088
|
-
|
|
1107
|
+
let self = this;
|
|
1089
1108
|
if (self.cookies)
|
|
1090
1109
|
return F.TUtils.decodeURIComponent(self.cookies[name] || '');
|
|
1091
1110
|
|
|
1092
1111
|
self.cookies = {};
|
|
1093
1112
|
|
|
1094
|
-
|
|
1113
|
+
let cookies = self.headers['set-cookie'];
|
|
1095
1114
|
if (!cookies)
|
|
1096
1115
|
return '';
|
|
1097
1116
|
|
|
1098
1117
|
if (typeof(cookies) === 'string')
|
|
1099
1118
|
cookies = [cookies];
|
|
1100
1119
|
|
|
1101
|
-
for (
|
|
1102
|
-
|
|
1103
|
-
|
|
1120
|
+
for (let i = 0; i < cookies.length; i++) {
|
|
1121
|
+
let line = cookies[i].split(';', 1)[0];
|
|
1122
|
+
let index = line.indexOf('=');
|
|
1104
1123
|
if (index !== -1)
|
|
1105
1124
|
self.cookies[line.substring(0, index)] = line.substring(index + 1);
|
|
1106
1125
|
}
|
package/changelog.txt
CHANGED
|
@@ -12,6 +12,18 @@
|
|
|
12
12
|
- extended `Total.readfile(path, [type])` by adding a new type `datauri`
|
|
13
13
|
- fixed returing collections from the `HTMLParser.find()` method
|
|
14
14
|
- added `extend:String` option in `NEWACTION()` method
|
|
15
|
+
- added `FILECACHE(id, expire, callback, maker, encoding)` method
|
|
16
|
+
- fixed linking errors with the resource files
|
|
17
|
+
- added `RESTBuilder.?.base64()` method which returns the response in BASE64 format
|
|
18
|
+
- added support for custom errors in the Total.js Inline JSON Schemas, example: `id:UID // Invalid identifier, ...`
|
|
19
|
+
- added `ErrorBuilder.throw()` method which throws an error when an error is pushed
|
|
20
|
+
- fixed `HTMLParser.?.find()` method (fixed results)
|
|
21
|
+
- extended `QueryBuilder.gridfilter()` by adding `=EXACT_VALUE` or `=EXACT_VALUE1,EXACT_VALUE2`
|
|
22
|
+
- IMPORTANT: updated `RESTBuilder` XML response, now it returns `HTMLParser` output
|
|
23
|
+
- fixed removing of multiple spaces in the `String.toName()` method
|
|
24
|
+
- fixed a problem with case-sensitive characters in the route parameters
|
|
25
|
+
- fixed markdown parser
|
|
26
|
+
- added missing ViewEngine `@{meta(...)}` method
|
|
15
27
|
|
|
16
28
|
========================
|
|
17
29
|
0.0.12
|
package/filestorage.js
CHANGED
|
@@ -113,7 +113,7 @@ FP.save = FP.insert = function(id, name, filename, custom, callback, expire, hea
|
|
|
113
113
|
|
|
114
114
|
FP._save = function(id, name, filename, callback, custom, expire, headers) {
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
let self = this;
|
|
117
117
|
|
|
118
118
|
if (self.pause) {
|
|
119
119
|
setTimeout(self.retrysave, 500, id, name, filename, callback, custom, expire, headers);
|
|
@@ -125,17 +125,17 @@ FP._save = function(id, name, filename, callback, custom, expire, headers) {
|
|
|
125
125
|
name = F.TUtils.getName(name);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
let directory = self.makedirectory(id);
|
|
129
|
+
let filenameto = F.Path.join(directory, id + '.file');
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
let index = name.lastIndexOf('/');
|
|
132
132
|
if (index !== -1)
|
|
133
133
|
name = name.substring(index + 1);
|
|
134
134
|
|
|
135
135
|
if (self.cache[directory]) {
|
|
136
|
+
// Check URL address
|
|
136
137
|
if (typeof(filename) === 'string' && filename[0] === 'h' && filename[1] === 't' && filename[7] === '/') {
|
|
137
|
-
|
|
138
|
-
var opt = {};
|
|
138
|
+
let opt = {};
|
|
139
139
|
opt.url = filename;
|
|
140
140
|
opt.custom = true;
|
|
141
141
|
opt.headers = headers;
|
|
@@ -164,7 +164,7 @@ FP._save = function(id, name, filename, callback, custom, expire, headers) {
|
|
|
164
164
|
self.cache[directory] = 1;
|
|
165
165
|
if (typeof(filename) === 'string' && filename[0] === 'h' && filename[1] === 't' && filename[7] === '/') {
|
|
166
166
|
// URL address
|
|
167
|
-
|
|
167
|
+
let opt = {};
|
|
168
168
|
opt.url = filename;
|
|
169
169
|
opt.custom = true;
|
|
170
170
|
opt.headers = headers;
|
package/global.js
CHANGED
|
@@ -322,4 +322,29 @@ global.TotalAPI = function(name, model, callback) {
|
|
|
322
322
|
let obj = API('TAPI', name, model);
|
|
323
323
|
callback && obj.callback(callback);
|
|
324
324
|
return obj;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
global.FILECACHE = function(id, expire, callback, maker, encoding = 'json') {
|
|
328
|
+
|
|
329
|
+
let filename = PATH.temp('filecache_' + (id + '').hash(true).toString(36) + '.cache');
|
|
330
|
+
let isjson = encoding === 'json';
|
|
331
|
+
|
|
332
|
+
F.Fs.lstat(filename, function(err, stat) {
|
|
333
|
+
let time = stat ? stat.mtime > stat.ctime ? stat.mtime : stat.ctime : null;
|
|
334
|
+
if (err || time.add(expire) < NOW) {
|
|
335
|
+
maker(function(err, response, load) {
|
|
336
|
+
if (!err)
|
|
337
|
+
F.Fs.writeFile(filename, isjson ? response instanceof String ? response : JSON.stringify(response) : response, NOOP);
|
|
338
|
+
if (load || load == null)
|
|
339
|
+
callback(err, response);
|
|
340
|
+
}, id);
|
|
341
|
+
} else {
|
|
342
|
+
F.Fs.readFile(filename, isjson ? 'utf8' : encoding, function(err, response) {
|
|
343
|
+
if (err)
|
|
344
|
+
callback(err);
|
|
345
|
+
else
|
|
346
|
+
callback(null, isjson ? response.parseJSON(true) : response);
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
});
|
|
325
350
|
};
|
package/htmlparser.js
CHANGED
|
@@ -19,7 +19,7 @@ HTMLElement.prototype = {
|
|
|
19
19
|
|
|
20
20
|
function parseRule(selector, output) {
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
let rule = {};
|
|
23
23
|
|
|
24
24
|
rule.attrs = [];
|
|
25
25
|
rule.output = output || [];
|
|
@@ -28,7 +28,7 @@ function parseRule(selector, output) {
|
|
|
28
28
|
// div div[name="Peter Sirka"]
|
|
29
29
|
// div > div[name="Peter Sirka"]
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
let cache = [];
|
|
32
32
|
|
|
33
33
|
selector = selector.replace(/\[.*?\]/gi, text => '[' + (cache.push(text) - 1) + ']').replace(/(\s)?>(\s)?/, '>').replace(/\s{2}/g, '').trim();
|
|
34
34
|
|
|
@@ -37,9 +37,9 @@ function parseRule(selector, output) {
|
|
|
37
37
|
if (rule.notravelse)
|
|
38
38
|
selector = selector.substring(1);
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
let m = selector.match(/>|\s/);
|
|
41
41
|
if (m) {
|
|
42
|
-
|
|
42
|
+
let nested = selector.substring(m.index).trim().replace(/\[\d+\]/g, text => cache[+text.substring(1, text.length - 1)]);
|
|
43
43
|
rule.nested = parseRule(nested, rule.output);
|
|
44
44
|
selector = selector.substring(0, m.index).trim();
|
|
45
45
|
}
|
|
@@ -47,20 +47,20 @@ function parseRule(selector, output) {
|
|
|
47
47
|
selector = selector.replace(/\[\d+\]/, text => cache[+text.substring(1, text.length - 1)]);
|
|
48
48
|
|
|
49
49
|
// attribute search
|
|
50
|
-
match = selector.match(/\[.*?\]/i);
|
|
50
|
+
let match = selector.match(/\[.*?\]/i);
|
|
51
51
|
if (match) {
|
|
52
|
-
for (
|
|
53
|
-
|
|
52
|
+
for (let m of match) {
|
|
53
|
+
let index = m.indexOf('=');
|
|
54
54
|
rule.attrs.push({ id: m.substring(1, index).trim(), value: m.substring(index + 2, m.length - 2).trim() });
|
|
55
55
|
}
|
|
56
56
|
selector = selector.replace(match, '');
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// #id or .class
|
|
60
|
-
|
|
60
|
+
match = selector.match(/[#|.][a-z-_0-9]+/i);
|
|
61
61
|
if (match) {
|
|
62
|
-
for (
|
|
63
|
-
|
|
62
|
+
for (let m of match) {
|
|
63
|
+
let val = m.substring(1);
|
|
64
64
|
rule.attrs.push({ id: m[0] === '#' ? 'id' : 'class', value: val });
|
|
65
65
|
}
|
|
66
66
|
selector = selector.replace(match, '');
|
|
@@ -84,12 +84,12 @@ function parseRule(selector, output) {
|
|
|
84
84
|
|
|
85
85
|
HTMLElement.prototype.browse = function(fn, reverse) {
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
let self = this;
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
for (
|
|
89
|
+
let browse = function(children) {
|
|
90
|
+
for (let node of children) {
|
|
91
91
|
if (node && node.tagName) {
|
|
92
|
-
|
|
92
|
+
let a = fn(node);
|
|
93
93
|
if (a !== true)
|
|
94
94
|
browse(reverse ? [node.parentNode] : node.children);
|
|
95
95
|
}
|
|
@@ -106,49 +106,49 @@ HTMLElement.prototype.browse = function(fn, reverse) {
|
|
|
106
106
|
function extendarr(output) {
|
|
107
107
|
|
|
108
108
|
output.aclass = function(cls) {
|
|
109
|
-
for (
|
|
109
|
+
for (let item of this)
|
|
110
110
|
item.aclass(cls);
|
|
111
111
|
return this;
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
output.rclass = function(cls) {
|
|
115
|
-
for (
|
|
115
|
+
for (let item of this)
|
|
116
116
|
item.rclass(cls);
|
|
117
117
|
return this;
|
|
118
118
|
};
|
|
119
119
|
|
|
120
120
|
output.tclass = function(cls, value) {
|
|
121
|
-
for (
|
|
121
|
+
for (let item of this)
|
|
122
122
|
item.tclass(cls, value);
|
|
123
123
|
return this;
|
|
124
124
|
};
|
|
125
125
|
|
|
126
126
|
output.attr = function(key, value) {
|
|
127
|
-
for (
|
|
127
|
+
for (let item of this)
|
|
128
128
|
item.attr(key, value);
|
|
129
129
|
return this;
|
|
130
130
|
};
|
|
131
131
|
|
|
132
132
|
output.attrd = function(key, value) {
|
|
133
|
-
for (
|
|
133
|
+
for (let item of this)
|
|
134
134
|
item.attrd(key, value);
|
|
135
135
|
return this;
|
|
136
136
|
};
|
|
137
137
|
|
|
138
138
|
output.find = function(selector) {
|
|
139
|
-
|
|
140
|
-
for (
|
|
141
|
-
|
|
139
|
+
let arr = [];
|
|
140
|
+
for (let item of this) {
|
|
141
|
+
let result = item.find(selector);
|
|
142
142
|
if (result.length)
|
|
143
|
-
arr.push(result);
|
|
143
|
+
arr.push.apply(arr, result);
|
|
144
144
|
}
|
|
145
145
|
extendarr(arr);
|
|
146
146
|
return arr;
|
|
147
147
|
};
|
|
148
148
|
|
|
149
149
|
output.toString = output.html = function(formatted) {
|
|
150
|
-
|
|
151
|
-
for (
|
|
150
|
+
let builder = [];
|
|
151
|
+
for (let item of this)
|
|
152
152
|
builder.push(item.toString(formatted));
|
|
153
153
|
return builder.join(formatted ? '\n' : '');
|
|
154
154
|
};
|
|
@@ -163,7 +163,7 @@ function extendarr(output) {
|
|
|
163
163
|
function compare(rule, node) {
|
|
164
164
|
|
|
165
165
|
if (rule.prefix === '*') {
|
|
166
|
-
|
|
166
|
+
let tagName = node.tagName;
|
|
167
167
|
if (node.prefix)
|
|
168
168
|
tagName = tagName.substring(node.prefix.length);
|
|
169
169
|
if (tagName !== rule.tagName)
|
|
@@ -176,10 +176,10 @@ function compare(rule, node) {
|
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
if (rule.attrs.length) {
|
|
179
|
-
for (
|
|
179
|
+
for (let attr of rule.attrs) {
|
|
180
180
|
switch (attr.id) {
|
|
181
181
|
case 'class':
|
|
182
|
-
|
|
182
|
+
let tmp = node.attrs[attr.id];
|
|
183
183
|
if (tmp) {
|
|
184
184
|
tmp = tmp.split(' ');
|
|
185
185
|
if (!tmp.includes(attr.value))
|
|
@@ -270,7 +270,7 @@ HTMLElement.prototype.attrd = function(name, value) {
|
|
|
270
270
|
|
|
271
271
|
HTMLElement.prototype.parsecache = function() {
|
|
272
272
|
|
|
273
|
-
|
|
273
|
+
let self = this;
|
|
274
274
|
if (self.cache)
|
|
275
275
|
return self;
|
|
276
276
|
|
|
@@ -278,20 +278,20 @@ HTMLElement.prototype.parsecache = function() {
|
|
|
278
278
|
self.cache.css = {};
|
|
279
279
|
self.cache.cls = {};
|
|
280
280
|
|
|
281
|
-
|
|
282
|
-
|
|
281
|
+
let tmp = self.attrs.class;
|
|
282
|
+
let arr;
|
|
283
283
|
|
|
284
284
|
if (tmp) {
|
|
285
285
|
arr = tmp.split(' ');
|
|
286
|
-
for (
|
|
286
|
+
for (let c of arr)
|
|
287
287
|
self.cache.cls[c] = 1;
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
|
|
290
|
+
tmp = self.attrs.style;
|
|
291
291
|
if (tmp) {
|
|
292
292
|
arr = tmp.split(';');
|
|
293
|
-
for (
|
|
294
|
-
|
|
293
|
+
for (let c of arr) {
|
|
294
|
+
let a = c.split(':');
|
|
295
295
|
self.cache.css[a[0]] = a[1];
|
|
296
296
|
}
|
|
297
297
|
}
|
|
@@ -300,12 +300,12 @@ HTMLElement.prototype.parsecache = function() {
|
|
|
300
300
|
};
|
|
301
301
|
|
|
302
302
|
HTMLElement.prototype.stringifycache = function() {
|
|
303
|
-
|
|
303
|
+
let self = this;
|
|
304
304
|
self.attrs.class = Object.keys(self.cache.cls).join(' ');
|
|
305
305
|
|
|
306
|
-
|
|
306
|
+
let tmp = [];
|
|
307
307
|
|
|
308
|
-
for (
|
|
308
|
+
for (let key in self.cache.css)
|
|
309
309
|
self.cache.css[key] && tmp.push(key + ':' + self.cache.css[key]);
|
|
310
310
|
|
|
311
311
|
if (tmp.length)
|
|
@@ -318,7 +318,7 @@ HTMLElement.prototype.stringifycache = function() {
|
|
|
318
318
|
|
|
319
319
|
HTMLElement.prototype.attr = function(name, value) {
|
|
320
320
|
|
|
321
|
-
|
|
321
|
+
let self = this;
|
|
322
322
|
|
|
323
323
|
if (value === undefined)
|
|
324
324
|
return self.attrs[name];
|
|
@@ -332,10 +332,10 @@ HTMLElement.prototype.attr = function(name, value) {
|
|
|
332
332
|
};
|
|
333
333
|
|
|
334
334
|
HTMLElement.prototype.aclass = function(cls) {
|
|
335
|
-
|
|
335
|
+
let self = this;
|
|
336
336
|
self.parsecache();
|
|
337
|
-
|
|
338
|
-
for (
|
|
337
|
+
let arr = cls.split(/\s|,/);
|
|
338
|
+
for (let m of arr)
|
|
339
339
|
self.cache.cls[m] = 1;
|
|
340
340
|
self.stringifycache();
|
|
341
341
|
return self;
|
|
@@ -343,16 +343,16 @@ HTMLElement.prototype.aclass = function(cls) {
|
|
|
343
343
|
};
|
|
344
344
|
|
|
345
345
|
HTMLElement.prototype.hclass = function(cls) {
|
|
346
|
-
|
|
346
|
+
let self = this;
|
|
347
347
|
self.parsecache();
|
|
348
348
|
return self.cache.cls[cls] === 1;
|
|
349
349
|
};
|
|
350
350
|
|
|
351
351
|
HTMLElement.prototype.tclass = function(cls, value) {
|
|
352
|
-
|
|
352
|
+
let self = this;
|
|
353
353
|
self.parsecache();
|
|
354
|
-
|
|
355
|
-
for (
|
|
354
|
+
let arr = cls.split(/\s|,/);
|
|
355
|
+
for (let m of arr) {
|
|
356
356
|
if (self.cache.cls[m]) {
|
|
357
357
|
if (!value)
|
|
358
358
|
delete self.cache.cls[m];
|
|
@@ -366,11 +366,11 @@ HTMLElement.prototype.tclass = function(cls, value) {
|
|
|
366
366
|
};
|
|
367
367
|
|
|
368
368
|
HTMLElement.prototype.rclass = function(cls) {
|
|
369
|
-
|
|
369
|
+
let self = this;
|
|
370
370
|
self.parsecache();
|
|
371
371
|
|
|
372
|
-
|
|
373
|
-
for (
|
|
372
|
+
let arr = cls.split(/\s|,/);
|
|
373
|
+
for (let m of arr)
|
|
374
374
|
delete self.cache.cls[m];
|
|
375
375
|
|
|
376
376
|
self.stringifycache();
|
|
@@ -378,10 +378,10 @@ HTMLElement.prototype.rclass = function(cls) {
|
|
|
378
378
|
};
|
|
379
379
|
|
|
380
380
|
HTMLElement.prototype.css = function(key, value) {
|
|
381
|
-
|
|
381
|
+
let self = this;
|
|
382
382
|
self.parsecache();
|
|
383
383
|
if (typeof(key) === 'object') {
|
|
384
|
-
for (
|
|
384
|
+
for (let k of Object.keys(key)) {
|
|
385
385
|
value = key[k];
|
|
386
386
|
if (value)
|
|
387
387
|
self.cache.css[k] = value;
|
|
@@ -399,9 +399,9 @@ HTMLElement.prototype.css = function(key, value) {
|
|
|
399
399
|
};
|
|
400
400
|
|
|
401
401
|
HTMLElement.prototype.remove = function() {
|
|
402
|
-
|
|
402
|
+
let self = this;
|
|
403
403
|
if (self.parentNode) {
|
|
404
|
-
|
|
404
|
+
let index = self.parentNode.children.indexOf(self);
|
|
405
405
|
if (index !== -1)
|
|
406
406
|
self.parentNode.children.splice(index, 1);
|
|
407
407
|
}
|
|
@@ -410,10 +410,10 @@ HTMLElement.prototype.remove = function() {
|
|
|
410
410
|
|
|
411
411
|
HTMLElement.prototype.append = function(str) {
|
|
412
412
|
|
|
413
|
-
|
|
414
|
-
|
|
413
|
+
let self = this;
|
|
414
|
+
let dom = parseHTML(str, null, null, self.xml);
|
|
415
415
|
|
|
416
|
-
for (
|
|
416
|
+
for (let item of dom.children)
|
|
417
417
|
self.children.push(item);
|
|
418
418
|
|
|
419
419
|
return dom.children.length === 1 ? dom.children[0] : dom.children;
|
|
@@ -421,10 +421,10 @@ HTMLElement.prototype.append = function(str) {
|
|
|
421
421
|
|
|
422
422
|
HTMLElement.prototype.prepend = function(str) {
|
|
423
423
|
|
|
424
|
-
|
|
425
|
-
|
|
424
|
+
let self = this;
|
|
425
|
+
let dom = parseHTML(str, null, null, self.xml);
|
|
426
426
|
|
|
427
|
-
for (
|
|
427
|
+
for (let item of dom.children)
|
|
428
428
|
self.children.unshift(item);
|
|
429
429
|
|
|
430
430
|
return dom;
|
|
@@ -436,19 +436,19 @@ HTMLElement.prototype.text = function() {
|
|
|
436
436
|
|
|
437
437
|
HTMLElement.prototype.toString = HTMLElement.prototype.html = function(formatted) {
|
|
438
438
|
|
|
439
|
-
|
|
440
|
-
|
|
439
|
+
let self = this;
|
|
440
|
+
let builder = [];
|
|
441
441
|
|
|
442
|
-
|
|
442
|
+
let browse = function(children, level) {
|
|
443
443
|
|
|
444
|
-
for (
|
|
444
|
+
for (let item of children) {
|
|
445
445
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
446
|
+
let indent = formatted && level ? ''.padLeft(level, '\t') : '';
|
|
447
|
+
let tag = item.tagName.toLowerCase();
|
|
448
|
+
let attrs = [];
|
|
449
449
|
|
|
450
|
-
for (
|
|
451
|
-
|
|
450
|
+
for (let key in item.attrs) {
|
|
451
|
+
let val = item.attrs[key];
|
|
452
452
|
if (!val && (key === 'class' || key.substring(0, 5) === 'data-' || key === 'id'))
|
|
453
453
|
continue;
|
|
454
454
|
attrs.push(key + (val ? ('="' + (val || '') + '"') : ''));
|
|
@@ -480,17 +480,17 @@ HTMLElement.prototype.toString = HTMLElement.prototype.html = function(formatted
|
|
|
480
480
|
};
|
|
481
481
|
|
|
482
482
|
function removeComments(html) {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
483
|
+
let tagBeg = '<!--';
|
|
484
|
+
let tagEnd = '-->';
|
|
485
|
+
let beg = html.indexOf(tagBeg);
|
|
486
|
+
let end = 0;
|
|
487
487
|
while (beg !== -1) {
|
|
488
488
|
end = html.indexOf(tagEnd, beg + 4);
|
|
489
489
|
|
|
490
490
|
if (end === -1)
|
|
491
491
|
break;
|
|
492
492
|
|
|
493
|
-
|
|
493
|
+
let comment = html.substring(beg, end + 3);
|
|
494
494
|
html = html.replaceAll(comment, '');
|
|
495
495
|
beg = html.indexOf(tagBeg, beg);
|
|
496
496
|
}
|
|
@@ -500,8 +500,8 @@ function removeComments(html) {
|
|
|
500
500
|
|
|
501
501
|
function parseHTML(html, trim, onerror, isxml) {
|
|
502
502
|
|
|
503
|
-
|
|
504
|
-
|
|
503
|
+
let makeText = function(parent, str) {
|
|
504
|
+
let obj = new HTMLElement();
|
|
505
505
|
obj.xml = isxml;
|
|
506
506
|
obj.tagName = 'TEXT';
|
|
507
507
|
obj.children = [];
|
|
@@ -511,14 +511,14 @@ function parseHTML(html, trim, onerror, isxml) {
|
|
|
511
511
|
return obj;
|
|
512
512
|
};
|
|
513
513
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
514
|
+
let parseAttrs = function(str) {
|
|
515
|
+
let attrs = str.match(/[a-z-0-9A-Z\:_-]+(=("|').*?("|'))?/g);
|
|
516
|
+
let obj = {};
|
|
517
517
|
if (attrs) {
|
|
518
|
-
for (
|
|
518
|
+
for (let m of attrs) {
|
|
519
519
|
m = m.trim();
|
|
520
|
-
|
|
521
|
-
|
|
520
|
+
let index = m.indexOf('=');
|
|
521
|
+
let key, val;
|
|
522
522
|
key = (index === -1 ? m : m.substring(0, index)).trim();
|
|
523
523
|
val = index === -1 ? '' : m.substring(m.indexOf('"', index) + 1, m.lastIndexOf('"')).trim();
|
|
524
524
|
obj[key] = val;
|
|
@@ -527,13 +527,13 @@ function parseHTML(html, trim, onerror, isxml) {
|
|
|
527
527
|
return obj;
|
|
528
528
|
};
|
|
529
529
|
|
|
530
|
-
|
|
530
|
+
let parseElements = function(str, parent) {
|
|
531
531
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
532
|
+
let counter = 0;
|
|
533
|
+
let count = 0;
|
|
534
|
+
let beg = str.indexOf('<');
|
|
535
|
+
let end = -1;
|
|
536
|
+
let tmp;
|
|
537
537
|
|
|
538
538
|
if (beg !== -1)
|
|
539
539
|
end = str.indexOf('>', beg + 1);
|
|
@@ -558,8 +558,8 @@ function parseHTML(html, trim, onerror, isxml) {
|
|
|
558
558
|
parent.children.push(makeText(parent, tmp));
|
|
559
559
|
}
|
|
560
560
|
|
|
561
|
-
|
|
562
|
-
|
|
561
|
+
let node = str.substring(beg + 1, end);
|
|
562
|
+
let dom = new HTMLElement();
|
|
563
563
|
|
|
564
564
|
dom.xml = isxml;
|
|
565
565
|
|
|
@@ -572,8 +572,8 @@ function parseHTML(html, trim, onerror, isxml) {
|
|
|
572
572
|
dom.unpair = true;
|
|
573
573
|
}
|
|
574
574
|
|
|
575
|
-
|
|
576
|
-
|
|
575
|
+
let tag = node;
|
|
576
|
+
let index = -1;
|
|
577
577
|
|
|
578
578
|
for (let i = 0; i < tag.length; i++) {
|
|
579
579
|
let c = tag[i];
|
|
@@ -624,10 +624,10 @@ function parseHTML(html, trim, onerror, isxml) {
|
|
|
624
624
|
}
|
|
625
625
|
}
|
|
626
626
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
627
|
+
let pos = -1;
|
|
628
|
+
let tagBeg = '<' + dom.raw;
|
|
629
|
+
let tagEnd = '</' + dom.raw + '>';
|
|
630
|
+
let unpair = false;
|
|
631
631
|
|
|
632
632
|
// Tries to parse the content of the "dom.raw" element
|
|
633
633
|
while (true) {
|
|
@@ -694,7 +694,7 @@ function parseHTML(html, trim, onerror, isxml) {
|
|
|
694
694
|
|
|
695
695
|
}
|
|
696
696
|
|
|
697
|
-
|
|
697
|
+
let inner = str.substring(0, pos - tagEnd.length);
|
|
698
698
|
if (inner.indexOf('<') === -1 || (!isxml && (/\<(script|style|template)/).test(tag))) {
|
|
699
699
|
if (trim)
|
|
700
700
|
inner = inner.trim();
|
|
@@ -719,7 +719,7 @@ function parseHTML(html, trim, onerror, isxml) {
|
|
|
719
719
|
|
|
720
720
|
html = removeComments(html);
|
|
721
721
|
|
|
722
|
-
|
|
722
|
+
let dom = new HTMLElement();
|
|
723
723
|
dom.xml = isxml;
|
|
724
724
|
|
|
725
725
|
while (html)
|
package/markdown.js
CHANGED
|
@@ -480,6 +480,17 @@ String.prototype.markdown = function(opt, nested) {
|
|
|
480
480
|
lines[i] = lines[i].replace(REG_ENCODETAGS, ENCODE);
|
|
481
481
|
|
|
482
482
|
if (!lines[i]) {
|
|
483
|
+
|
|
484
|
+
if (opt.emptynewline !== false && !lines[i - 1])
|
|
485
|
+
builder.push('<br />');
|
|
486
|
+
|
|
487
|
+
if (table) {
|
|
488
|
+
table = null;
|
|
489
|
+
if (opt.tables !== false)
|
|
490
|
+
builder.push('</tbody></table>');
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
closeul();
|
|
483
494
|
builder.push('');
|
|
484
495
|
continue;
|
|
485
496
|
}
|
package/package.json
CHANGED
package/querybuilder.js
CHANGED
|
@@ -929,13 +929,13 @@ QBP.gridfields = function(fields, allowed) {
|
|
|
929
929
|
// Grid filtering
|
|
930
930
|
QBP.gridfilter = function(name, obj, type, key) {
|
|
931
931
|
|
|
932
|
-
|
|
933
|
-
|
|
932
|
+
let builder = this;
|
|
933
|
+
let value = obj[name] || '';
|
|
934
934
|
|
|
935
935
|
if (!value || typeof(value) !== 'string')
|
|
936
936
|
return builder;
|
|
937
937
|
|
|
938
|
-
|
|
938
|
+
let arr, val;
|
|
939
939
|
|
|
940
940
|
if (!key)
|
|
941
941
|
key = name;
|
|
@@ -966,13 +966,13 @@ QBP.gridfilter = function(name, obj, type, key) {
|
|
|
966
966
|
}
|
|
967
967
|
|
|
968
968
|
// Between
|
|
969
|
-
|
|
969
|
+
let index = value.indexOf(' - ');
|
|
970
970
|
if (index !== -1) {
|
|
971
971
|
|
|
972
972
|
arr = value.split(' - ');
|
|
973
973
|
|
|
974
|
-
for (
|
|
975
|
-
|
|
974
|
+
for (let i = 0, length = arr.length; i < length; i++) {
|
|
975
|
+
let item = arr[i].trim();
|
|
976
976
|
arr[i] = convert(item, type);
|
|
977
977
|
}
|
|
978
978
|
|
|
@@ -991,28 +991,35 @@ QBP.gridfilter = function(name, obj, type, key) {
|
|
|
991
991
|
index = value.indexOf(',');
|
|
992
992
|
if (index !== -1) {
|
|
993
993
|
|
|
994
|
-
|
|
994
|
+
let exact = value[0] === '=';
|
|
995
|
+
let arr = (exact ? value.substring(1) : value).split(',');
|
|
995
996
|
|
|
996
997
|
if (type === undefined || type === String) {
|
|
997
|
-
|
|
998
|
-
for (
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
998
|
+
if (exact) {
|
|
999
|
+
for (let i = 0; i < arr.length; i++)
|
|
1000
|
+
arr[i] = arr[i].trim();
|
|
1001
|
+
builder.in(key, arr);
|
|
1002
|
+
} else {
|
|
1003
|
+
builder.or(function() {
|
|
1004
|
+
for (let i = 0; i < arr.length; i++) {
|
|
1005
|
+
let item = arr[i].trim();
|
|
1006
|
+
builder.search(key, item);
|
|
1007
|
+
}
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1003
1010
|
return builder;
|
|
1004
1011
|
}
|
|
1005
1012
|
|
|
1006
|
-
for (
|
|
1013
|
+
for (let i = 0; i < arr.length; i++)
|
|
1007
1014
|
arr[i] = convert(arr[i], type);
|
|
1008
1015
|
|
|
1009
1016
|
return builder.in(key, arr);
|
|
1010
1017
|
}
|
|
1011
1018
|
|
|
1012
1019
|
if (type === undefined || type === String)
|
|
1013
|
-
return value[0] === '
|
|
1020
|
+
return value[0] === '=' ? builder.where(key, '=', value.substring(1)) : builder.search(key, value);
|
|
1014
1021
|
|
|
1015
|
-
|
|
1022
|
+
let comparer = '=';
|
|
1016
1023
|
|
|
1017
1024
|
switch (value[0]) {
|
|
1018
1025
|
case '>':
|
package/routing.js
CHANGED
|
@@ -150,7 +150,6 @@ function Route(url, action, size) {
|
|
|
150
150
|
}
|
|
151
151
|
t.size = size || 0;
|
|
152
152
|
}
|
|
153
|
-
|
|
154
153
|
t.middleware = [];
|
|
155
154
|
|
|
156
155
|
index = t.url.indexOf('*');
|
|
@@ -566,24 +565,25 @@ exports.lookup = function(ctrl, auth = 0, skip = false) {
|
|
|
566
565
|
|
|
567
566
|
exports.split = function(url, lowercase) {
|
|
568
567
|
|
|
569
|
-
if (lowercase)
|
|
570
|
-
url = url.toLowerCase();
|
|
571
|
-
|
|
572
568
|
if (url[0] === '/')
|
|
573
569
|
url = url.substring(1);
|
|
574
570
|
|
|
575
571
|
if (url[url.length - 1] === '/')
|
|
576
572
|
url = url.substring(0, url.length - 1);
|
|
577
573
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
574
|
+
let count = 0;
|
|
575
|
+
let end = 0;
|
|
576
|
+
let arr = [];
|
|
577
|
+
let tmp;
|
|
581
578
|
|
|
582
|
-
for (
|
|
579
|
+
for (let i = 0; i < url.length; i++) {
|
|
583
580
|
switch (url[i]) {
|
|
584
581
|
case '/':
|
|
585
582
|
if (count === 0) {
|
|
586
|
-
|
|
583
|
+
tmp = url.substring(end + (arr.length ? 1 : 0), i);
|
|
584
|
+
if (lowercase && tmp[0] !== '{')
|
|
585
|
+
tmp = tmp.toLowerCase();
|
|
586
|
+
arr.push(tmp);
|
|
587
587
|
end = i;
|
|
588
588
|
}
|
|
589
589
|
break;
|
|
@@ -596,8 +596,12 @@ exports.split = function(url, lowercase) {
|
|
|
596
596
|
}
|
|
597
597
|
}
|
|
598
598
|
|
|
599
|
-
if (!count)
|
|
600
|
-
|
|
599
|
+
if (!count) {
|
|
600
|
+
tmp = url.substring(end + (arr.length ? 1 : 0), url.length);
|
|
601
|
+
if (lowercase && tmp[0] !== '{')
|
|
602
|
+
tmp = tmp.toLowerCase();
|
|
603
|
+
arr.push(tmp);
|
|
604
|
+
}
|
|
601
605
|
|
|
602
606
|
if (arr.length === 1 && !arr[0])
|
|
603
607
|
arr[0] = '/';
|
package/utils.js
CHANGED
|
@@ -2160,16 +2160,22 @@ DP.parseDate = function() {
|
|
|
2160
2160
|
|
|
2161
2161
|
SP.toName = function() {
|
|
2162
2162
|
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2163
|
+
let a = '';
|
|
2164
|
+
let p = 0;
|
|
2165
|
+
let space = false;
|
|
2166
|
+
let val = this;
|
|
2167
|
+
let spaces = 0;
|
|
2168
|
+
|
|
2169
|
+
for (let i = 0; i < val.length; i++) {
|
|
2170
|
+
|
|
2171
|
+
let c = val.charCodeAt(i);
|
|
2167
2172
|
|
|
2168
|
-
for (var i = 0; i < val.length; i++) {
|
|
2169
|
-
var c = val.charCodeAt(i);
|
|
2170
2173
|
if ((c < 65 || (c > 90 && c < 97) || (c > 122 && c < 128)) && c !== 32)
|
|
2171
2174
|
continue;
|
|
2172
2175
|
|
|
2176
|
+
if (c === 32 && p === 32)
|
|
2177
|
+
continue;
|
|
2178
|
+
|
|
2173
2179
|
if (a && p !== 32) {
|
|
2174
2180
|
|
|
2175
2181
|
if (c === 32) {
|
|
@@ -5879,8 +5885,8 @@ exports.connect = function(opt, callback) {
|
|
|
5879
5885
|
|
|
5880
5886
|
SP.toJSONSchema = SP.parseSchema = function(name, url) {
|
|
5881
5887
|
|
|
5882
|
-
|
|
5883
|
-
|
|
5888
|
+
let obj = {};
|
|
5889
|
+
let p = (url || F.config.url || 'https://schemas.totaljs.com');
|
|
5884
5890
|
|
|
5885
5891
|
if (p[p.length - 1] !== '/')
|
|
5886
5892
|
p += '/';
|
|
@@ -5890,8 +5896,8 @@ SP.toJSONSchema = SP.parseSchema = function(name, url) {
|
|
|
5890
5896
|
obj.type = 'object';
|
|
5891
5897
|
obj.properties = {};
|
|
5892
5898
|
|
|
5893
|
-
|
|
5894
|
-
|
|
5899
|
+
let str = this;
|
|
5900
|
+
let nestedtypes = [];
|
|
5895
5901
|
|
|
5896
5902
|
str = str.replace(/\[.*?\]/g, function(text) {
|
|
5897
5903
|
if (text.substring(1, 2) === '@')
|
|
@@ -5905,17 +5911,34 @@ SP.toJSONSchema = SP.parseSchema = function(name, url) {
|
|
|
5905
5911
|
return '{#' + (nestedtypes.push(text.substring(1, text.length - 1)) - 1) + '}';
|
|
5906
5912
|
});
|
|
5907
5913
|
|
|
5908
|
-
|
|
5909
|
-
|
|
5914
|
+
let prop = str.split(/,|\n/);
|
|
5915
|
+
let required = [];
|
|
5916
|
+
let errors = null;
|
|
5917
|
+
|
|
5918
|
+
for (let i = 0; i < prop.length; i++) {
|
|
5910
5919
|
|
|
5911
|
-
|
|
5920
|
+
let line = prop[i].trim();
|
|
5921
|
+
let errindex = line.indexOf('//');
|
|
5922
|
+
let err = null;
|
|
5923
|
+
|
|
5924
|
+
if (errindex != -1) {
|
|
5925
|
+
if (!errors)
|
|
5926
|
+
errors = {};
|
|
5927
|
+
err = line.substring(errindex + 2).trim();
|
|
5928
|
+
line = line.substring(0, errindex).trim();
|
|
5929
|
+
}
|
|
5912
5930
|
|
|
5913
|
-
|
|
5914
|
-
|
|
5931
|
+
let arr = line.split(':').trim();
|
|
5932
|
+
let tmp = null;
|
|
5915
5933
|
|
|
5916
5934
|
if (arr[0][0] === '@') {
|
|
5917
|
-
|
|
5935
|
+
tmp = arr[0].substring(1);
|
|
5936
|
+
let ext = F.jsonschemas[tmp];
|
|
5918
5937
|
if (ext) {
|
|
5938
|
+
|
|
5939
|
+
if (err)
|
|
5940
|
+
errors[tmp] = err;
|
|
5941
|
+
|
|
5919
5942
|
for (let m of ext.required)
|
|
5920
5943
|
required.push(m);
|
|
5921
5944
|
for (let m in ext.properties)
|
|
@@ -5930,15 +5953,18 @@ SP.toJSONSchema = SP.parseSchema = function(name, url) {
|
|
|
5930
5953
|
required.push(arr[0]);
|
|
5931
5954
|
}
|
|
5932
5955
|
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5956
|
+
if (err)
|
|
5957
|
+
errors[arr[0]] = err;
|
|
5958
|
+
|
|
5959
|
+
let type = (arr[1] || 'string').trim();
|
|
5960
|
+
// let type = typename.toLowerCase().trim();
|
|
5961
|
+
let size = 0;
|
|
5962
|
+
let isarr = type[0] === '[';
|
|
5937
5963
|
if (isarr)
|
|
5938
5964
|
type = type.substring(1, type.length - 1);
|
|
5939
5965
|
|
|
5940
|
-
|
|
5941
|
-
|
|
5966
|
+
let nestedschema = '';
|
|
5967
|
+
let isenum = type[0] === '{';
|
|
5942
5968
|
|
|
5943
5969
|
if (isenum) {
|
|
5944
5970
|
tmp = type.substring(2, type.length - 1);
|
|
@@ -5954,7 +5980,7 @@ SP.toJSONSchema = SP.parseSchema = function(name, url) {
|
|
|
5954
5980
|
}
|
|
5955
5981
|
}
|
|
5956
5982
|
|
|
5957
|
-
|
|
5983
|
+
let index = type.indexOf('(');
|
|
5958
5984
|
if (index !== -1) {
|
|
5959
5985
|
size = +type.substring(index + 1, type.length - 1).trim();
|
|
5960
5986
|
type = type.substring(0, index);
|
|
@@ -5989,7 +6015,7 @@ SP.toJSONSchema = SP.parseSchema = function(name, url) {
|
|
|
5989
6015
|
type = 'object';
|
|
5990
6016
|
}
|
|
5991
6017
|
|
|
5992
|
-
|
|
6018
|
+
let ltype = type.toLowerCase();
|
|
5993
6019
|
|
|
5994
6020
|
switch (ltype) {
|
|
5995
6021
|
case 'string2':
|
|
@@ -6100,7 +6126,14 @@ SP.toJSONSchema = SP.parseSchema = function(name, url) {
|
|
|
6100
6126
|
if (required.length)
|
|
6101
6127
|
obj.required = required;
|
|
6102
6128
|
|
|
6129
|
+
obj.errors = errors;
|
|
6103
6130
|
obj.transform = exports.jsonschematransform;
|
|
6131
|
+
obj.validate = function(value, partial, path) {
|
|
6132
|
+
let err = new F.TBuilders.ErrorBuilder();
|
|
6133
|
+
err.throw();
|
|
6134
|
+
let output = this.transform(value, partial, err, path);
|
|
6135
|
+
return output.response;
|
|
6136
|
+
};
|
|
6104
6137
|
|
|
6105
6138
|
if (name)
|
|
6106
6139
|
F.jsonschemas[name] = obj;
|
|
@@ -6110,17 +6143,20 @@ SP.toJSONSchema = SP.parseSchema = function(name, url) {
|
|
|
6110
6143
|
|
|
6111
6144
|
exports.jsonschematransform = function(value, partial, error, path) {
|
|
6112
6145
|
|
|
6113
|
-
|
|
6146
|
+
let self = this;
|
|
6114
6147
|
|
|
6115
6148
|
if (!error)
|
|
6116
6149
|
error = new ErrorBuilder();
|
|
6117
6150
|
|
|
6118
|
-
|
|
6151
|
+
if (self.errors)
|
|
6152
|
+
error.dictionary = self.errors;
|
|
6153
|
+
|
|
6154
|
+
let response = F.TJSONSchema.transform(self, error, value, false, path, partial);
|
|
6119
6155
|
return { error: error.items.length ? error : null, response: response };
|
|
6120
6156
|
};
|
|
6121
6157
|
|
|
6122
6158
|
exports.set = function(obj, path, value) {
|
|
6123
|
-
|
|
6159
|
+
let cachekey = 'uset' + path;
|
|
6124
6160
|
|
|
6125
6161
|
if (F.temporary.utils[cachekey])
|
|
6126
6162
|
return F.temporary.utils[cachekey](obj, value);
|
|
@@ -6128,27 +6164,26 @@ exports.set = function(obj, path, value) {
|
|
|
6128
6164
|
if ((/__proto__|constructor|prototype|eval|function|\*|\+|;|\s|\(|\)|!/).test(path))
|
|
6129
6165
|
return value;
|
|
6130
6166
|
|
|
6131
|
-
|
|
6132
|
-
|
|
6167
|
+
let arr = parsepath(path);
|
|
6168
|
+
let builder = [];
|
|
6133
6169
|
|
|
6134
|
-
for (
|
|
6135
|
-
|
|
6136
|
-
|
|
6170
|
+
for (let i = 0; i < arr.length - 1; i++) {
|
|
6171
|
+
let type = arr[i + 1] ? (REG_ISARR.test(arr[i + 1]) ? '[]' : '{}') : '{}';
|
|
6172
|
+
let p = 'w' + (arr[i][0] === '[' ? '' : '.') + arr[i];
|
|
6137
6173
|
builder.push('if(typeof(' + p + ')!==\'object\'||' + p + '==null)' + p + '=' + type + ';');
|
|
6138
6174
|
}
|
|
6139
6175
|
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
var fn = new Function('w', 'a', 'b', a);
|
|
6176
|
+
let v = arr[arr.length - 1];
|
|
6177
|
+
let ispush = v.lastIndexOf('[]') !== -1;
|
|
6178
|
+
let a = builder.join(';') + ';var v=typeof(a)===\'function\'?a(F.TUtils.get(b)):a;w' + (v[0] === '[' ? '' : '.') + (ispush ? v.replace(REG_REPLACEARR, '.push(v)') : (v + '=v')) + ';return v';
|
|
6179
|
+
let fn = new Function('w', 'a', 'b', a);
|
|
6145
6180
|
F.temporary.utils[cachekey] = fn;
|
|
6146
6181
|
return fn(obj, value, path);
|
|
6147
6182
|
};
|
|
6148
6183
|
|
|
6149
6184
|
exports.get = function(obj, path) {
|
|
6150
6185
|
|
|
6151
|
-
|
|
6186
|
+
let cachekey = 'uget' + path;
|
|
6152
6187
|
|
|
6153
6188
|
if (F.temporary.utils[cachekey])
|
|
6154
6189
|
return F.temporary.utils[cachekey](obj);
|
|
@@ -6156,14 +6191,14 @@ exports.get = function(obj, path) {
|
|
|
6156
6191
|
if ((/__proto__|constructor|prototype|eval|function|\*|\+|;|\s|\(|\)|!/).test(path))
|
|
6157
6192
|
return;
|
|
6158
6193
|
|
|
6159
|
-
|
|
6160
|
-
|
|
6194
|
+
let arr = parsepath(path);
|
|
6195
|
+
let builder = [];
|
|
6161
6196
|
|
|
6162
|
-
for (
|
|
6197
|
+
for (let i = 0, length = arr.length - 1; i < length; i++)
|
|
6163
6198
|
builder.push('if(!w' + (!arr[i] || arr[i][0] === '[' ? '' : '.') + arr[i] + ')return');
|
|
6164
6199
|
|
|
6165
|
-
|
|
6166
|
-
|
|
6200
|
+
let v = arr[arr.length - 1];
|
|
6201
|
+
let fn = (new Function('w', builder.join(';') + ';return w' + (v[0] === '[' ? '' : '.') + v));
|
|
6167
6202
|
F.temporary.utils[cachekey] = fn;
|
|
6168
6203
|
return fn(obj);
|
|
6169
6204
|
};
|
package/viewengine.js
CHANGED
|
@@ -116,7 +116,7 @@ exports.compile = function(name, content, debug = true) {
|
|
|
116
116
|
|
|
117
117
|
while (command) {
|
|
118
118
|
|
|
119
|
-
if (!isCookie && command.command.
|
|
119
|
+
if (!isCookie && command.command.includes('cookie'))
|
|
120
120
|
isCookie = true;
|
|
121
121
|
|
|
122
122
|
if (old) {
|
|
@@ -186,7 +186,7 @@ exports.compile = function(name, content, debug = true) {
|
|
|
186
186
|
|
|
187
187
|
counter++;
|
|
188
188
|
|
|
189
|
-
if (cmd.
|
|
189
|
+
if (cmd.includes('foreach var '))
|
|
190
190
|
cmd = cmd.replace(' var ', SPACE);
|
|
191
191
|
|
|
192
192
|
newCommand = (cmd.substring(8, cmd.indexOf(SPACE, 8)) || '').trim();
|
|
@@ -378,7 +378,7 @@ function prepare(command, dcommand, functions) {
|
|
|
378
378
|
return 'self.hostname';
|
|
379
379
|
|
|
380
380
|
case 'href':
|
|
381
|
-
return command.
|
|
381
|
+
return command.includes('(') ? ('self.' + command) : 'self.href()';
|
|
382
382
|
|
|
383
383
|
case 'url':
|
|
384
384
|
return 'self.' + command;
|
|
@@ -387,7 +387,10 @@ function prepare(command, dcommand, functions) {
|
|
|
387
387
|
case 'description':
|
|
388
388
|
case 'keywords':
|
|
389
389
|
case 'author':
|
|
390
|
-
return command.
|
|
390
|
+
return command.includes('(') ? ('self.' + command) : '((repository[\'' + command + '\'] || \'\') + \'\').safehtml()';
|
|
391
|
+
|
|
392
|
+
case 'meta':
|
|
393
|
+
return command.includes('(') ? ('self.' + command) : ('self.' + command + '()');
|
|
391
394
|
|
|
392
395
|
case 'title2':
|
|
393
396
|
return 'self.' + command;
|
|
@@ -399,10 +402,10 @@ function prepare(command, dcommand, functions) {
|
|
|
399
402
|
return '(repository[\'' + command.substring(1) + '\'] || \'\')';
|
|
400
403
|
|
|
401
404
|
case 'place':
|
|
402
|
-
return command.
|
|
405
|
+
return command.includes('(') ? ('self.' + command) : ('(repository[\'' + command + '\'] || \'\')');
|
|
403
406
|
|
|
404
407
|
case 'import':
|
|
405
|
-
return 'self.' + command + (command.
|
|
408
|
+
return 'self.' + command + (command.includes('(') ? '' : '()');
|
|
406
409
|
|
|
407
410
|
case 'index':
|
|
408
411
|
return '(' + command + ')';
|
|
@@ -424,7 +427,7 @@ function prepare(command, dcommand, functions) {
|
|
|
424
427
|
return '(new Date()' + command.substring(3) + ')';
|
|
425
428
|
|
|
426
429
|
default:
|
|
427
|
-
return F.def.helpers[name] ? ('F.def.helpers.' + insertcall(command)) : ('self.safehtml(' + (functions.
|
|
430
|
+
return F.def.helpers[name] ? ('F.def.helpers.' + insertcall(command)) : ('self.safehtml(' + (!functions.includes(name) ? command[0] === '!' ? command.substring(1) + ')' : command + ', 1)' : command + ')'));
|
|
428
431
|
}
|
|
429
432
|
}
|
|
430
433
|
|
|
@@ -668,6 +671,28 @@ View.prototype.keywords = function(value) {
|
|
|
668
671
|
return '';
|
|
669
672
|
};
|
|
670
673
|
|
|
674
|
+
View.prototype.meta = function() {
|
|
675
|
+
|
|
676
|
+
let self = this;
|
|
677
|
+
|
|
678
|
+
if (!arguments.length)
|
|
679
|
+
return makehtmlmeta(self);
|
|
680
|
+
|
|
681
|
+
if (arguments[0])
|
|
682
|
+
self.repository.title = arguments[0].encode();
|
|
683
|
+
|
|
684
|
+
if (arguments[1])
|
|
685
|
+
self.repository.description = arguments[1].encode();
|
|
686
|
+
|
|
687
|
+
if (arguments[2] && arguments[2].length)
|
|
688
|
+
self.repository.keywords = (arguments[2] instanceof Array ? arguments[2].join(', ') : arguments[2]).encode();
|
|
689
|
+
|
|
690
|
+
if (arguments[3])
|
|
691
|
+
self.repository.image = arguments[3];
|
|
692
|
+
|
|
693
|
+
return '';
|
|
694
|
+
};
|
|
695
|
+
|
|
671
696
|
// @{href({ key1: 1, key2: 2 })}
|
|
672
697
|
// @{href('key', 'value')}
|
|
673
698
|
// @{href({ key1: 1, key2: 2 })}
|
|
@@ -784,12 +809,13 @@ function makehtmlmeta(self) {
|
|
|
784
809
|
builder += '<meta name="description" content="' + repo.description.safehtml() + '" />';
|
|
785
810
|
|
|
786
811
|
if (repo.keywords)
|
|
787
|
-
builder += '<meta name="
|
|
812
|
+
builder += '<meta name="keywords" content="' + repo.keywords.safehtml() + '" />';
|
|
788
813
|
|
|
789
814
|
if (repo.image) {
|
|
790
815
|
let tmp = repo.image.substring(0, 6);
|
|
791
|
-
let src = tmp === 'http:/' || tmp === 'https:' || tmp.substring(0, 2) === '//' ? repo.image :
|
|
792
|
-
|
|
816
|
+
let src = tmp === 'http:/' || tmp === 'https:' || tmp.substring(0, 2) === '//' ? repo.image : self.controller ? self.controller.hostname(repo.image[0] === '/' ? repo.image : ('/' + repo.image)) : '';
|
|
817
|
+
if (src)
|
|
818
|
+
builder += '<meta property="og:image" content="' + src + '" /><meta name="twitter:image" content="' + src + '" />';
|
|
793
819
|
}
|
|
794
820
|
|
|
795
821
|
return builder;
|
|
@@ -827,7 +853,7 @@ View.prototype.import = function() {
|
|
|
827
853
|
continue;
|
|
828
854
|
}
|
|
829
855
|
|
|
830
|
-
if (m.
|
|
856
|
+
if (!m.includes('+')) {
|
|
831
857
|
let absolute = m[0] === '/';
|
|
832
858
|
let key = absolute ? m : ('/' + m);
|
|
833
859
|
if (REG_CHECKCSS.test(m)) {
|
|
@@ -923,4 +949,4 @@ View.prototype.render = function(name, model, ispartial = false) {
|
|
|
923
949
|
return content;
|
|
924
950
|
};
|
|
925
951
|
|
|
926
|
-
exports.View = View;
|
|
952
|
+
exports.View = View;
|