-
Notifications
You must be signed in to change notification settings - Fork 104
/
json2html.js
1360 lines (1021 loc) · 44.7 KB
/
json2html.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// json2html.js 3.2.2
// https://www.json2html.com
// (c) 2006-2024 Crystalline Technologies
// json2html may be freely distributed under the MIT license.
(function() {
"use strict";
// Baseline setup
// --------------
// Establish the root object, `window` (`self`) in the browser, `global`
// on the server, or `this` in some virtual machines. We use `self`
// instead of `window` for `WebWorker` support.
let root = typeof self == 'object' && self.self === self && self ||
typeof global == 'object' && global.global === global && global ||
this ||
{};
//Components {name:template}
let COMPONENTS = {};
//Triggers {name:[{obj,template,ele}]} for updates
let TRIGGERS = {};
/* ---------------------------------------- Interactive HTML Object (iHTML) ------------------------------------------------ */
function iHTML(html){
//Object type
this.type = "iHTML";
//html
this.html = html || "";
//associated events
this.events = {};
//associated update triggers
this.triggers = {};
}
//Append an ihtml object
// obj = ihtml OR html string
iHTML.prototype.append = function(obj){
if(obj)
if(obj.type === "iHTML") {
//Append the html
this.html += obj.html;
//Append the events
Object.assign(this.events, obj.events);
//Append the update triggers
Object.assign(this.triggers, obj.triggers);
}
//Added for chaining
return(this);
};
//Append HTML to this object
iHTML.prototype.appendHTML = function(html){
this.html += html;
};
//Spit out the object as json
iHTML.prototype.toJSON = function(){
return({
"html":this.html,
"events":this.events,
"triggers":this.triggers
});
};
//Seal the object
// don't allow any more properties or methods
Object.seal(iHTML);
/* ---------------------------------------- Tokenizer ------------------------------------------------ */
function Tokenizer( tokenizers, doBuild ){
if( !(this instanceof Tokenizer ) )
return new Tokenizer( tokenizers, onEnd, onFound );
this.tokenizers = tokenizers.splice ? tokenizers : [tokenizers];
if( doBuild )
this.doBuild = doBuild;
}
Tokenizer.prototype.parse = function( src ){
this.src = src;
this.ended = false;
this.tokens = [ ];
do this.next(); while( !this.ended );
return this.tokens;
};
Tokenizer.prototype.build = function( src, real ){
if( src )
this.tokens.push(
!this.doBuild ? src :
this.doBuild(src,real,this.tkn)
);
};
Tokenizer.prototype.next = function(){
let self = this,
plain;
self.findMin();
plain = self.src.slice(0, self.min);
self.build( plain, false );
self.src = self.src.slice(self.min).replace(self.tkn,function( all ){
self.build(all, true);
return '';
});
if( !self.src )
self.ended = true;
};
Tokenizer.prototype.findMin = function(){
let self = this, i=0, tkn, idx;
self.min = -1;
self.tkn = '';
while(( tkn = self.tokenizers[i++]) !== undefined ){
idx = self.src[tkn.test?'search':'indexOf'](tkn);
if( idx != -1 && (self.min == -1 || idx < self.min )){
self.tkn = tkn;
self.min = idx;
}
}
if( self.min == -1 )
self.min = self.src.length;
};
/* ---------------------------------------- Public Methods ------------------------------------------------ */
//Create the new json2html with prototype polution protection
if(!root.json2html) root.json2html = Object.create(null);
//Current Version
root.json2html.version = "3.2.2";
//Render a json2html template to html string
// obj (requried) : json object to render, or json string
// template (required): json2html template (array / json object / json string)
// options (optional) : {
// components : {name:template,...}
// data : passed to event.data
// output : ihtml / html (default)
// }
root.json2html.render = function(obj,template,options) {
//Allow for a json string of json object
let parsed = obj;
//Check for a string (JSON string or literal)
if(typeof(obj) === "string") {
try {
parsed = JSON.parse(obj);
} catch(e) {
//Assume that this is a literal string
parsed = obj;
}
}
//Set the object to the parsed value
// allows for JSON object or a string value of a JSON object or literal
obj = parsed;
//Set the options
if(!options) options = {};
//Set the default to html output
if(!options.output) options.output = "html";
//Check to make sure we have a template and object
if(_typeof(template) !== "object" || _typeof(obj) !== "object") {
//Check what type of output we're looking for
switch(options.output) {
case "ihtml":
return(new iHTML(""));
break;
default:
return("");
break;
}
}
//Check what type of output we're looking for
switch(options.output) {
case "ihtml":
return(_render(obj, template, options));
break;
default:
return(_render(obj, template, options).html);
break;
}
};
//json2html component methods
// use Object.create to prevent prototype polution
root.json2html.component = Object.create(null);
//Add a component (name = string, template = json2html template)
//OR function(components) where component is obj with name:template property eg {"name":template,...}
root.json2html.component.add = function(name,template){
//Determine what we're adding
switch(_typeof(name,true)) {
//Multiple components
case "object":
//Components
COMPONENTS = Object.assign(COMPONENTS,name);
break;
//One component
case "string":
COMPONENTS[name] = template;
break;
//Not supported
default:
break;
}
};
//Get a component
root.json2html.component.get = function(name) {
return(COMPONENTS[name]);
};
//Trigger a component to be updated
// DEPRECATED, use refresh instead
// id (required) : id of the component that needs to be updated
// obj (optional) : object we want to use, will overwrite the original object used for this rendering
root.json2html.trigger = function(id,obj) {
//Make sure we have a id
if(!id) return;
//Get the triggers (always an array)
let arry = TRIGGERS[id];
if(!arry) return;
//Create a list of all triggers that we need to render
let all = [];
//Itterate over all elements to trigger an update for
for(let i=0; i < arry.length; i++) {
//Get the trigger
let trigger = arry[i];
//Get the object
// default to the original trigger object
let _obj = trigger.obj;
if(obj) _obj = obj;
//Add the trigger object
all.push({
"index":i,
"obj":_obj,
"trigger":trigger
});
}
//Perform all the updates
// this needs to be done AFTER triggers are read otherwise we'll have an infinite loop
// render() is called which adds triggers
for(let a=0; a < all.length; a++) {
//Get the trigger object
let o = all[a];
//Render the update if we can find the element in the dom
if( document.contains(o.trigger.ele) ) o.trigger.ele.json2html(o.obj,o.trigger.template,{"method":"replace"});
else {
//Otherwise remove the trigger as it's stale
arry.splice(o.trigger.index,1);
}
}
//Finally save the trigger
// as we might have removed some
TRIGGERS[id] = arry;
};
//Refresh a component with id
// id (required) : id of the component that needs to be updated
// obj (optional) : object we want to use, will overwrite the original object used for this rendering
root.json2html.refresh = root.json2html.trigger;
//Encode the html string to text
root.json2html.toText = function(html) {
//Check for undefined or null
if(html === undefined || html === null) return("");
//Otherwise convert to a string and encode HTML components
return html.toString()
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/\"/g, """)
.replace(/\'/g, "'")
.replace(/\//g, "/");
};
//Hydrate elements with their events & update triggers
root.json2html.hydrate = function(parent,events,triggers) {
let arry = parent;
//Convert the parent to an array of elements
if(!Array.isArray(parent)) arry = [parent];
//For each parent complete the following
for(let i=0; i < arry.length; i++) {
let element = arry[i];
//Attach events and get the elements that need ready to be triggered
let ready = _attachEvents(element,events);
//Trigger all the json2html.ready events
for(let i=0; i < ready.length; i++)
_triggerEvent(ready[i],"j2h-ready");
//Set the upgrade triggers
if(triggers) _setTriggers(element,triggers);
}
return(this);
};
/* ---------------------------------------- JS DOM Methods --------------------------------------------------- */
//ONLY for the browser
// and we have Element defined
if(typeof(window) === "object" && typeof(Element) === "function") {
//Render a json2html template & append to dom element
// obj : json object to render, or json string
// template: json2html template (array / object / json string)
// options : {}
// components : {name:template,...}
// data : passed to event.data
// method : prepend, replace, append (default)
Element.prototype.json2html = function(obj,template,options) {
//Create the optional options if required
if(!options) options = {};
//Default to ihtml output
options.output = "ihtml";
//Render using the master render function
let ihtml = json2html.render(obj,template,options);
//Convert the html into a dom object using innerHTML
// return the childNodes (Node List)
let dom = document.createElement(this.tagName);
dom.innerHTML = ihtml.html;
//Set the element that we want to hydrate with
let ele = this;
//Determine how we should add the new content
switch(options.method) {
//Replace
case "replace":
//Convert to an array
// we'll use this for hydration
ele = Array.from(dom.childNodes);
//Replace
this.replaceWith(...dom.childNodes);
break;
//Prepend
case "prepend":
this.prepend(...dom.childNodes);
break;
//Default to append
default:
this.append(...dom.childNodes);
break;
}
//Rehydrate the object
// this will add the events, trigger ready events and setup trigger updates
json2html.hydrate(ele, ihtml.events, ihtml.triggers);
//Return this for chaining
return(this);
};
}
/* ---------------------------------------- jQuery Methods (if jquery is present) --------------------------------------------------- */
//ONLY for the browser
// and we have jQuery defined
if(typeof(window) === "object")
if(window.jQuery) {
(function($){
//jQuery render template via chaining
// obj : json object to render or json string
// template: json2html template (array / object / json string)
// options : {}
// components : {name:template,...}
// data : passed to event.data
// method : prepend, replace, append (default)
$.fn.json2html = function(obj, template, options) {
//Set the options
if(!options) options = {};
//Make sure we set the output to ihtml
options.output = "ihtml";
//Render each object
return($(this).each(function(){
//Render the template
// use the render function with iHTML output
// then we'll hydrate with events after it's added to the dom
let ihtml = json2html.render(obj,template,options);
//Set the element that we want to hydrate with
let $ele = $(this);
//Determine how we should add the new content
switch(options.method) {
//Replace
case "replace":
//Convert the html into a dom object using innerHTML
// return the childNodes (Node List)
let $dom = $("<" + $ele[0].tagName + ">");
$dom.html(ihtml.html);
//Set the element to the dom object children
$ele = $dom.children();
//Repace with these dom children
$.fn.replaceWith.call($(this),$ele);
break;
//Prepend
case "prepend":
$.fn.prepend.call($(this),ihtml.html);
break;
//Default to append
default:
$.fn.append.call($(this),ihtml.html);
break;
}
//Hydrate with events
$ele.j2hHydrate(ihtml.events,ihtml.triggers);
}));
};
//Hydrate the json2html elements with these events
$.fn.j2hHydrate = function(events,triggers) {
//Attach the events for each element
return($(this).each(function(){
//Hydrate this element with these events
json2html.hydrate(this,events,triggers);
}));
};
})(window.jQuery);
}
/* ---------------------------------------- Prviate Methods ------------------------------------------------ */
//Trigger the event type for this element
function _triggerEvent(element,type) {
let event; // The custom event that will be created
//Check to see if we have the createEvent function
if(document.createEvent){
event = document.createEvent("HTMLEvents");
event.initEvent(type, true, true);
event.eventName = type;
element.dispatchEvent(event);
} else {
event = document.createEventObject();
event.eventName = type;
event.eventType = type;
element.fireEvent("on" + event.eventType, event);
}
}
//Attach the events to the parent & children of this element
// we need to check the parent as well to ensure that events get added after a trigger event
function _attachEvents(parent,events) {
//Record json2html specific ready events
let ready = [];
//Get the elements that need to be triggered
let elements = Array.from( parent.querySelectorAll("[-j2h-e]") );
//Also check to see if the parent element has any triggers
if(parent.getAttribute("-j2h-e")) elements.push(parent);
//Itterate over the elements with events
for(let e=0; e < elements.length; e++) {
let element = elements[e];
//Get the events we should attach to this element
let attach = element.getAttribute("-j2h-e");
//remove the event attribute
element.removeAttribute("-j2h-e");
//Make sure we have some events to attach
if(attach) {
//split by " " (can contain multiple events per element)
let _events = attach.split(" ");
//Add each event
for(let i = 0; i < _events.length; i++) {
//Process each event and keep the context for the event listener
((event)=>{
//Don't have this event then just skip
if(!event) return;
//Add the ready event
// json2html specific event
if(event.type === "ready") {
//Sepcify that we'll need to trigger these later
ready.push(element);
//rename the event to j2h-ready
event.type = "j2h-ready";
}
//Attach the events to the element
element.addEventListener(event.type,function(e){
//Disable j2h-ready events from being propagated
if(event.type === "j2h-ready") e.stopPropagation();
//attach the javascript event
event.data.event = e;
//call the appropriate method
if(_typeof(event.action) === "function") event.action.call(this,event.data);
});
})(events[_events[i]]);
}
}
}
//Return the ready events
return(ready);
}
//Set the update triggers
function _setTriggers(parent,triggers) {
//Get the elements that need to be triggered
let elements = Array.from( parent.querySelectorAll("[-j2h-t]") );
//Also check to see if the parent element has any triggers
if(parent.getAttribute("-j2h-t")) elements.push(parent);
//Itterate over the elements with triggers
for(let e=0; e < elements.length; e++) {
let element = elements[e];
//Get the triggers that we need to listen to
let id = element.getAttribute("-j2h-t");
//Make sure we have some triggers
if(!id) return;
//split by " " (can contain multiple triggers per element)
let _triggers = id.split(" ");
//Add each trigger
for(let i = 0; i < _triggers.length; i++) {
let trigger = triggers[_triggers[i]];
//Don't have a trigger then just skip
if(!trigger) continue;
//Add the element to the trigger
// we need this later to make sure we update the right element
trigger.ele = element;
//Create a new array of triggers for this trigger name
if(!TRIGGERS[trigger.name]) TRIGGERS[trigger.name] = [];
//Add the trigger
TRIGGERS[trigger.name].push(trigger);
}
//remove the event attribute
element.removeAttribute("-j2h-t");
}
}
//Render the object using the template to ihtml (html + events)
// obj : json object
// template: json2html template (array / object / json string)
// options : {}
// components : {name:template,...}
// data : passed to event.data
// method : prepend, replace, append (default)
// output : html / ihtml (although we always output iHTML needed to determine if we bother with events)
function _render(obj, template, options, index, pobj) {
//Create a new ihtml object
let ihtml = new iHTML();
//Check to see what type of object we're rending
switch(_typeof(obj,true)) {
case "array":
//Itterrate through the array and render each object
let len=obj.length;
for(let j=0;j<len;++j) {
//Render the object using this template depending on the type of object
ihtml.append( _renderObj(obj[j], template, options, j, pobj) );
}
break;
//Don't render for undefined or null objects
case "undefined":
case "null":
break;
//Make sure to allow for literals as well
default:
//Render the object using this template depending on the type of object
ihtml.append( _renderObj(obj, template, options, index, pobj) );
break;
}
return(ihtml);
}
//Render an object using this template to ithml
function _renderObj(obj, template, options, index, pobj) {
let ihtml = new iHTML();
//Check the type of template we want to apply
switch(_typeof(template,true)) {
//Array of templates
case "array":
//Itterate through each template
let t_len = template.length;
for(let t=0; t < t_len; ++t) {
//Render the template and append
ihtml.append( _renderObj(obj, template[t], options, index) );
}
break;
//single template & single object
case "object":
let fobj = template["{}"];
//Check to see if this template uses it's own data object
// allows us to run the template under a different data object
// AND we haven't already got the parent before (in the case of an array)
if( _typeof(fobj) === "function" && !pobj) {
//Set the parent object
pobj = obj;
//Get the new object
obj = fobj.call(obj,obj,index);
//Render the object (might be an array)
ihtml.append( _render(obj, template, options, index, pobj) );
} else {
//Render the component
// or html
if(template["[]"]) ihtml.append( _component(pobj, obj, template, options, index) );
else ihtml.append( _html(pobj, obj, template, options, index) );
}
break;
}
return(ihtml);
}
//Get the html value of the object
function _getValue(obj, template, key, options, index) {
let out = "";
//Get the template property
let prop = template[key];
//Check the type of this template property
switch(_typeof(prop,true)) {
//Get the value from the function
case "function":
//Check what typeof value is for the object we're rendering
switch(_typeof(obj)) {
//If this is a json object or array then get the component that we want
case "object":
//Otherwise get the value
return( prop.call(obj,obj,index,options.data) );
break;
//NOT SUPPORTED
case "function":
case "undefined":
case "null":
return("");
break;
//BOOLEAN, NUMBER, BIGINT, STRING, SYMBOL
default:
//Create a new object with the properties (value & index)
let _obj = {"value":obj,"index":index,"data":options.data};
return(prop.call(_obj,_obj,index,options.data));
break;
}
break;
//Check for short hand ${..}
// NOTE that with es6 support short hand is parsed as a template literal
// otherwise parsed internally with simple variable replacement
case "string":
//Check to see if we have es6 support with this browser
if(json2html.es6) {
//Use template literals to parse strings
//Check what typeof value is for the object we're rendering
switch(_typeof(obj)) {
//If this is an json object then get the value we're looking for
case "object":
out = json2html.es6.interpolate.call(prop,obj);
break;
//NOT SUPPORTED
case "function":
case "undefined":
case "null":
return("");
break;
//For literal arrays (and single objects) of type
//BOOLEAN, NUMBER, BIGINT, STRING, SYMBOL
default:
out = json2html.es6.interpolate.call(prop,{
"value":obj,
"index":index
});
break;
}
} else {
//Parse the property string and fill in any tokens using simple variable replacement
out = _parse(prop,function(all,path){
//Check what typeof value is for the object we're rendering
switch(_typeof(obj)) {
//If this is an json object then get the value we're looking for
case "object":
return(_get(obj,path));
break;
//NOT SUPPORTED
case "function":
case "undefined":
case "null":
return("");
break;
//For literal arrays (and single objects) of type
//BOOLEAN, NUMBER, BIGINT, STRING, SYMBOL
default:
//Check the path of the shorthand
switch(path) {
//RESERVED word for literal array value
case "value":
return(obj);
break;
//RESERVED word for literal array value index
case "index":
//Return empty string if we don't have an index
// for objects
if(index === undefined || index === null) return("");
else return(index);
break;
}
break;
}
});
}
break;
//Spit out blank
case "null":
case "undefined":
case "object":
out = "";
break;
//Arrays, and other literals
default:
//Get the string representation for this property
out = prop.toString();
break;
}
return(out);
}
/* ---------------------------------------- Safe Object Methods -------------------------------------------- */
//Get the property from the object
function _get(obj,path){
//Split the path into it's seperate components
let _path = path.split(".");
//Set the object we use to query for this name to be the original object
let subObj = obj;
//Parse the object properties
let c_len = _path.length;
for(let i=0;i<c_len;++i) {
//Skip if we don't have this part of the path
if( _path[i].length > 0 ) {
//Get the sub object using the path
subObj = subObj[_path[i]];
//Break if we don't have this sub object
if(subObj === null || subObj === undefined) break;
}
}
//Return an empty string if we don't have a value
if(subObj === null || subObj === undefined) return("");
return(subObj);
}
/* ---------------------------------------- Interpolate (Template Literals) -------------------------------------------- */
//Typeof helper
function _typeof(obj,checkArray) {
const type = typeof obj;
//Check what kind of object this is
if(type === "object") {
//Check for null
if(obj === null) return("null");
//Check for array
if(checkArray)
if(Array.isArray(obj)) return("array");
}
return(type);
}
//Get a new random id
function _id() {
return (_random()+_random());
}
//Random string (4 characters)
function _random() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
//Determines if we have a void element
// (No end tag, and must not contain any contents)
function _isVoidElement(element) {
//Determine if we match any of the void elements
// as specified by https://www.w3.org/TR/html5/syntax.html#void-elements
switch(element) {
//Allow these void elements
case "area":
case "base":
case "br":
case "col":
case "command":
case "embed":
case "hr":
case "img":
case "input":
case "keygen":
case "link":
case "meta":
case "param":
case "source":
case "track":
case "wbr":
return(true);
break;
//Otherwise we're not void
default:
return(false);
break;
}
}
//Use the tokenizer to parse the str
function _parse(str, method) {
const tokenizer = new Tokenizer([
/\${([\w\-\.\,\$\s]+)}/
],function( src, real, re ){
return real ? src.replace(re,method) : src;
}
);
return(tokenizer.parse(str).join(""));
}
/* ---------------------------------------- Template Types ------------------------------------------------ */
//default html type
// supports <>
// returns iHTML
function _html(pobj, obj, template, options, index){
//Create a new ihtml object for the parent and it's children
let parent = new iHTML(),
children = new iHTML();