Template string - Node.js String

Node.js examples for String:Template

Description

Template string

Demo Code

/** /*from w w  w . j  ava2s .c  om*/
 * Template string
 */
var Template = (function(){
  return {  
      'parseItem' : function(tpl, source, destination){  
        return tpl.replace(new RegExp('[\{]' + source + '[\}]', 'g'), destination);
      },  
      'parse' : function(tpl, source){
        for(var i in source){
          tpl = Template.parseItem(tpl, i, source[i]);
        }
        return tpl;
      }
  } 
})();

Related Tutorials