PDA

View Full Version : [OPEN] DomHelper.Template.compile



Animal
26 Oct 2006, 3:54 AM
Instead of


compile : function(){
var html = this.html;
var re = /\{(\w+)\}/g;
var body = [];
body.push("this.compiled = function(values){ return ");
var result;
var lastMatchEnd = 0;
while ((result = re.exec(html)) != null){
body.push("'", html.substring(lastMatchEnd, result.index), "' + ");
body.push("values[", html.substring(result.index+1,re.lastIndex-1), "] + ");
lastMatchEnd = re.lastIndex;
}
body.push("'", html.substr(lastMatchEnd), "';};");
eval(body.join(''));



It should be



compile : function(){
var html = this.html;
var re = /\{(\w+)\}/g;
var body = [];
body.push("this.compiled = function(values){ return ");
var result;
var lastMatchEnd = 0;
while ((result = re.exec(html)) != null){
body.push("'", html.substring(lastMatchEnd, result.index), "' + ");
body.push("values[\"", html.substring(result.index+1,re.lastIndex-1), "\"] + ");
lastMatchEnd = re.lastIndex;
}
body.push("'", html.substr(lastMatchEnd), "';};");
eval(body.join(''));


The strings inside {}s are the property names in the values associative array.

jack.slocum
26 Oct 2006, 7:17 AM
It's already been fixed with single quotes. There's a thread about it in the help forum.