*/
this.execute = function (template, model) {
let templateText = template.innerHTML; //模板中的文本
let codeArray = templateText.split(“\n”); //用换行符分割的代码数组
let compiledCode = “let _html=‘’;\n”; //预编译的代码
for (let i = 0; i < codeArray.length; i++) {
let item = codeArray[i];
let itemTrim = item.trim();
if (itemTrim.startsWith(this.settings.razor)) {
compiledCode += itemTrim.substr(1) + “\n”;
} else {
compiledCode += “_html+=`” + item + “`\n”;
}
}
compiledCode = compiledCode.replace(/</g, “<”); //还原转义的小于号
compiledCode = compiledCode.replace(/>/g, “>”); //还原转义后的大于号
compiledCode = compiledCode.replace(new RegExp(this.settings.razorEncodeChar,“g”), this.settings.razor);//还原转义后的胡须
compiledCode += “template.insertAdjacentHTML(‘beforebegin’,_html);\n”;
compiledCode += “template.remove();”;
if(this.settings.openLog){
let log=“function __execute__(template,model){\n”;
log+=compiledCode;
log+=“\n}”
console.log(log);
}
const __execute__ = new Function(“template”, “model”, compiledCode);
__execute__(template, model);
}
}