mirror of
https://github.com/chylex/Discord-History-Tracker.git
synced 2025-04-13 15:27:16 +03:00
Add template.js to renderer for basic templating
This commit is contained in:
parent
2a5f430884
commit
7f654eaf5d
18
src/renderer/src.template.js
Normal file
18
src/renderer/src.template.js
Normal file
@ -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;
|
||||
});
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user