Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b05af09fb | |||
| 32c61fff42 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.27.17",
|
"version": "0.27.19",
|
||||||
"description": "Utility library",
|
"description": "Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export async function renderTemplate(template: string, data: any, fetch?: (file:
|
|||||||
|
|
||||||
const evaluate = (code: string, data: object, fatal = true) => {
|
const evaluate = (code: string, data: object, fatal = true) => {
|
||||||
try {
|
try {
|
||||||
return Function('data', `Object.assign(this, data); return ${code};`)(data);
|
return Function('data', `with(data) { return ${code}; }`)(data);
|
||||||
} catch {
|
} catch {
|
||||||
if(fatal) throw new TemplateError(`Failed to evaluate: ${code}`);
|
if(fatal) throw new TemplateError(`Failed to evaluate: ${code}`);
|
||||||
else return false;
|
else return false;
|
||||||
@@ -71,7 +71,7 @@ export async function renderTemplate(template: string, data: any, fetch?: (file:
|
|||||||
|
|
||||||
// Extends: `{{ > file.html:property }} CONTENT {{ /> }}`
|
// Extends: `{{ > file.html:property }} CONTENT {{ /> }}`
|
||||||
while(!!(found = /\{\{\s*?>\s*?(.+?):(.+?)\s*?}}([\s\S]*?)\{\{\s*?\/>\s*?}}/g.exec(content))) {
|
while(!!(found = /\{\{\s*?>\s*?(.+?):(.+?)\s*?}}([\s\S]*?)\{\{\s*?\/>\s*?}}/g.exec(content))) {
|
||||||
content = content.replace(found[0], await renderTemplate(await fetch(found[1].trim), {
|
content = content.replace(found[0], await renderTemplate(await fetch(found[1].trim()), {
|
||||||
...data,
|
...data,
|
||||||
[found[2].trim()]: found[3],
|
[found[2].trim()]: found[3],
|
||||||
}, fetch));
|
}, fetch));
|
||||||
|
|||||||
Reference in New Issue
Block a user