Correction pour selectionner une definition sans regex : defs.node -> defs[node]
This commit is contained in:
parent
504ee83d33
commit
d997066e36
|
@ -1,7 +1,7 @@
|
|||
var FormBuilder=function(a,c){this.parent_element=a;this.form_object=c};FormBuilder.prototype={form_object:this.form_object,defs_object:{},parent_element:this.parent_element,built_form:null};FormBuilder.regex={reg_in_key:/^\/\^(.+)\$\/$/,reg_out_val:/\{(\$[1-9])\}/,pri_out_val:/\{([a-z-]+)\}/g,pri_in_key:/^\$([a-z-]+)$/,arr_out_set:/^\{\{([a-z-]+)\}\}$/,arr_out_val:/\{([a-z-]+)\.([a-z-]+)\}/g,arr_in_key:/^\$\$([a-z-]+)$/};
|
||||
FormBuilder.spread_attr=["children","next_nodes","prev_nodes","attributes","node_link"];FormBuilder.allowed_attr="node node_type next_nodes prev_nodes attributes children text repeat".split(" ");FormBuilder.prototype.add_definition=function(a){for(var c in a)this.defs_object[c]=a[c]};FormBuilder.prototype.build=function(a){a=null==a?{}:a;this.built_form=FormBuilder.formatFormObject(this.form_object,this.defs_object);this.built_form=FormBuilder.replaceStatements(this.form_object,a)};
|
||||
FormBuilder.formatFormObject=function(a,c){if(a.hasOwnProperty("node")&&"string"==typeof a.node){var f=FormBuilder.fetchNodeDefinition(a.node,c);"undefined"!=typeof f.def&&(a.node_link=JSON.parse(JSON.stringify(f.def)),f.hasOwnProperty("scope")&&(a.scope=f.scope))}if(a.hasOwnProperty("children"))for(var b in a.children)a.children[b].parent=a,FormBuilder.formatFormObject(a.children[b],c);return a};
|
||||
FormBuilder.fetchNodeDefinition=function(a,c){var f,b;r=FormBuilder.regex.reg_in_key;if(null!=c&&c.hasOwnProperty(a))return{def:c.node};for(f in c)if(r.test(f)&&(b=new RegExp(f.slice(1,-1)),b.test(a))){matches={};for(b=1;b<RegExp.length&&10>b;b++)matches["$"+b]=RegExp["$"+b];return{def:c[f],scope:matches}}return{}};
|
||||
FormBuilder.fetchNodeDefinition=function(a,c){var f,b;r=FormBuilder.regex.reg_in_key;if(null!=c&&c.hasOwnProperty(a))return{def:c[a]};for(f in c)if(r.test(f)&&(b=new RegExp(f.slice(1,-1)),b.test(a))){matches={};for(b=1;b<RegExp.length&&10>b;b++)matches["$"+b]=RegExp["$"+b];return{def:c[f],scope:matches}}return{}};
|
||||
FormBuilder.replaceStatements=function(a,c,f){a=a instanceof Object?a:{};c=c instanceof Object?JSON.parse(JSON.stringify(c)):{};f=null==f?"":f+" ";var b,g,e;if(a.hasOwnProperty("scope")&&a.scope instanceof Object)for(b in a.scope)c[b]=a.scope[b];a.received=JSON.parse(JSON.stringify(c));for(b in a)if("string"==typeof a[b]){g=FormBuilder.regex.arr_out_set;var d=[];(e=g.exec(a[b]))&&d.push(e[1]);for(e in d)c.hasOwnProperty(d[e])||(c[d[e]]=[]),a[b]=c[d[e]];if(!(0<d.length)){g=FormBuilder.regex.pri_out_val;
|
||||
for(d=[];null!==(e=g.exec(a[b]));)d.push(e[1]);for(e in d)c.hasOwnProperty(d[e])||(c[d[e]]=""),g=new RegExp("{"+d[e]+"}","g"),a[b]=a[b].replace(g,c[d[e]]);if(!(0<d.length)){g=FormBuilder.regex.reg_out_val;lasti=-1;for(d=[];null!==(e=g.exec(a[b]))&&!(lasti>=g.lastIndex);)lasti=g.lastIndex,d.push(e[1]);for(e in d)c.hasOwnProperty(d[e])||(c[d[e]]=""),g=new RegExp("{\\$"+d[e][1]+"}","g"),a[b]=a[b].replace(g,c[d[e]]);if(!(0<d.length)){g=FormBuilder.regex.arr_out_val;for(d=[];null!==(e=g.exec(a[b]));)d.push(e[1]);
|
||||
for(e in d)c.hasOwnProperty(d[e])||(c[d[e]]=""),g=new RegExp("/{"+d[e]+"}/","g"),a[b].replace(g,c[d[e]])}}}}for(b in a)FormBuilder.regex.pri_in_key.test(b)?c[b.substring(1)]=a[b]:FormBuilder.regex.arr_in_key.test(b)&&(c[b.substring(2)]=a[b]);c=JSON.parse(JSON.stringify(c));for(b in a)if(-1<FormBuilder.spread_attr.indexOf(b))if(a[b]instanceof Array)for(var h in a[b])console.log(f+""+a.node,b+"["+h+"]"),FormBuilder.replaceStatements(a[b][h],c,f);else a[b]instanceof Object&&(console.log(f+""+a.node,
|
||||
|
|
|
@ -200,7 +200,7 @@ FormBuilder.fetchNodeDefinition = function(node, defs){
|
|||
=========================================================*/
|
||||
if( defs != null && defs.hasOwnProperty(node) ){
|
||||
|
||||
return { def: defs.node };
|
||||
return { def: defs[node] };
|
||||
|
||||
|
||||
/* [2] Sinon, on cherche une REGEX
|
||||
|
|
Loading…
Reference in New Issue