1
0

Add prefixLines and substring helpers to query templates

This commit is contained in:
Zef Hemel 2022-07-18 16:45:04 +02:00
parent 928ef59190
commit 363a11a264

View File

@ -144,6 +144,17 @@ export async function renderQuery(
if (parsedQuery.render) { if (parsedQuery.render) {
Handlebars.registerHelper("json", (v) => JSON.stringify(v)); Handlebars.registerHelper("json", (v) => JSON.stringify(v));
Handlebars.registerHelper("niceDate", (ts) => niceDate(new Date(ts))); Handlebars.registerHelper("niceDate", (ts) => niceDate(new Date(ts)));
Handlebars.registerHelper("prefixLines", (v: string, prefix) =>
v
.split("\n")
.map((l) => prefix + l)
.join("\n")
);
Handlebars.registerHelper("substring", (s, from, to, elipsis = "") =>
s.length > to - from ? s.substring(from, to) + elipsis : s
);
Handlebars.registerHelper("yaml", (v, prefix) => { Handlebars.registerHelper("yaml", (v, prefix) => {
if (typeof prefix === "string") { if (typeof prefix === "string") {
let yaml = YAML.stringify(v) let yaml = YAML.stringify(v)