Animal
10-26-2006, 07: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.
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.