Skip to content

Instantly share code, notes, and snippets.

@segdeha
Created October 27, 2015 21:54
Show Gist options
  • Select an option

  • Save segdeha/b73384e01c48c002c1bd to your computer and use it in GitHub Desktop.

Select an option

Save segdeha/b73384e01c48c002c1bd to your computer and use it in GitHub Desktop.
// based on: http://snipt.org/rpp (which seems now defunct)
function Template(str) {
this.rgx = /{{([^{}]*)}}/g
this.str = str || ''
}
Template.prototype.evaluate = function (vals) {
vals = vals || {}
function repr(str, match) {
return 'string' === typeof vals[match] || 'number' === typeof vals[match] ? vals[match] : str
}
return this.str.replace(this.rgx, repr)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment