1 /*jslint 2 browser: true, 3 nomen: false, 4 debug: true, 5 forin: true, 6 plusplus: false, 7 undef: true, 8 white: false, 9 onevar: false 10 */ 11 var sc; 12 13 /** 14 * SpazTemplate 15 * designed for fast templating functions 16 * @class SpazTemplate 17 * @constructor 18 */ 19 function SpazTemplate() { 20 21 this._tpls = {}; 22 23 } 24 25 /** 26 * @param string name the name to call the method with in parseTemplate 27 * @param method function the template methid. Should take one param for input data, returns string 28 */ 29 SpazTemplate.prototype.addTemplateMethod = function(name, method) { 30 this._tpls[name] = method; 31 }; 32 33 34 /** 35 * @param string methodname the template method to call. 36 * @param mixed data data to be used by the template method 37 * @return string; 38 */ 39 SpazTemplate.prototype.parseTemplate = function(methodname, data) { 40 var parsed = this._tpls[methodname](data); 41 42 return parsed; 43 }; 44 45 /** 46 * @param string methodname the template method to call 47 * @param array data_array an array of objects to pass to the template method 48 * return string 49 */ 50 SpazTemplate.prototype.parseArray = function(methodname, data_array) { 51 var parsed = ''; 52 for(var k=0; k < data_array.length; k++) { 53 parsed += this.parseTemplate(methodname, data_array[k]); 54 } 55 return parsed; 56 }; 57