Skip to content

Instantly share code, notes, and snippets.

@bitsmanent
Last active January 25, 2018 16:22
Show Gist options
  • Select an option

  • Save bitsmanent/6ff5d8e5a89b08c2a8c2 to your computer and use it in GitHub Desktop.

Select an option

Save bitsmanent/6ff5d8e5a89b08c2a8c2 to your computer and use it in GitHub Desktop.
Build a view from a template and a data set. Replace %{key} with the corresponding value.
function mkview(tpl, d) {
var ret = tpl, re, k;
for(k in d) {
re = new RegExp("%{"+k+"}", "g");
ret = ret.replace(re , d[k]);
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment