diff --git a/src/renderer/src.template.js b/src/renderer/src.template.js new file mode 100644 index 0000000..7609a1f --- /dev/null +++ b/src/renderer/src.template.js @@ -0,0 +1,18 @@ +var TEMPLATE_REGEX = /{([^{}]+?)}/g; + +var TEMPLATE = function(contents){ + this.contents = contents; +}; + +TEMPLATE.prototype.apply = function(obj, processor){ + return this.contents.replace(TEMPLATE_REGEX, (full, match) => { + var value = match.split(".").reduce((o, property) => o[property], obj); + + if (processor){ + var updated = processor(match, value); + return typeof updated === "undefined" ? value : updated; + } + + return value; + }); +};