Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Map object keys in string to its values
*
* @param {String} text
* @param {Object} data
* @return {String}
*/
template: function (text, data) {
return !text ? '' : text.replace(/\{([^\}]+)\}/g, function (value, key) {
return key in data ? data[key] : value;
});
},
@designeng

This comment has been minimized.

Copy link
Owner Author

@designeng designeng commented Apr 19, 2016

Usage:

var htmlSpan = '<span class="{className}">{content}</span>';
var button = utils.template(htmlSpan, {
      className: this.className('button'),
      content:   text
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.