Skip to content

Instantly share code, notes, and snippets.

@monjudoh
Created September 10, 2008 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monjudoh/9963 to your computer and use it in GitHub Desktop.
Save monjudoh/9963 to your computer and use it in GitHub Desktop.
var MiniTemplate = function(template){
this.template = eval(['([\'',template.replace(/\$\{([^${}]+)\}/g,'\',{key:\'$1\'},\''),'\'])'].join(''));
};
MiniTemplate.prototype.merge = function(context){
var template = this.template || [];
var temp = [];
for(var i = 0; i < template.length; i++){
if(typeof template[i] == 'string'){
temp.push(template[i]);
}else if(typeof template[i] == 'object' && typeof template[i]['key'] == 'string'){
temp.push(context[ template[i]['key'] ]);
}
}
return temp.join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment