Templates 2.0 (#636)

Templates 2.0 and a whole bunch of other refactoring
This commit is contained in:
Zef Hemel
2024-01-20 19:16:07 +01:00
committed by GitHub
parent 0a6a0016a2
commit f30b1d3418
171 changed files with 2038 additions and 1628 deletions
+9
View File
@@ -40,6 +40,15 @@ export function handlebarHelpers() {
nextWeek.setDate(nextWeek.getDate() + 7);
return niceDate(nextWeek);
},
weekStart: (startOnMonday = true) => {
const d = new Date();
const day = d.getDay();
let diff = d.getDate() - day;
if (startOnMonday) {
diff += day == 0 ? -6 : 1;
}
return niceDate(new Date(d.setDate(diff)));
},
ifEq: function (v1: any, v2: any, options: any) {
if (v1 === v2) {
return options.fn(this);
+16 -8
View File
@@ -10,14 +10,22 @@ export function handlebarsSyscalls(): SysCallMapping {
obj: any,
globals: Record<string, any> = {},
): string => {
const templateFn = Handlebars.compile(
template,
{ noEscape: true },
);
return templateFn(obj, {
helpers: handlebarHelpers(),
data: globals,
});
return renderHandlebarsTemplate(template, obj, globals);
},
};
}
export function renderHandlebarsTemplate(
template: string,
obj: any,
globals: Record<string, any>,
) {
const templateFn = Handlebars.compile(
template,
{ noEscape: true },
);
return templateFn(obj, {
helpers: handlebarHelpers(),
data: globals,
});
}