Skip to content

Instantly share code, notes, and snippets.

@artemdemo
Created July 1, 2016 20:26
Show Gist options
  • Select an option

  • Save artemdemo/ae2be23fd8b92badeaf959f7de70bb42 to your computer and use it in GitHub Desktop.

Select an option

Save artemdemo/ae2be23fd8b92badeaf959f7de70bb42 to your computer and use it in GitHub Desktop.

Revisions

  1. artemdemo revised this gist Jul 1, 2016. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion nano-template.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    /* Nano Templates - https://github.com/trix/nano */

    function nano(template, data) {
    return template.replace(/\{([\w\.]*)\}/g, function(str, key) {
    var keys = key.split("."), v = data[keys.shift()];
  2. artemdemo created this gist Jul 1, 2016.
    9 changes: 9 additions & 0 deletions nano-template.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    /* Nano Templates - https://github.com/trix/nano */

    function nano(template, data) {
    return template.replace(/\{([\w\.]*)\}/g, function(str, key) {
    var keys = key.split("."), v = data[keys.shift()];
    for (var i = 0, l = keys.length; i < l; i++) v = v[keys[i]];
    return (typeof v !== "undefined" && v !== null) ? v : "";
    });
    }