From 363a11a2642ec892770f8347b27888ca54aaf3f0 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 18 Jul 2022 16:45:04 +0200 Subject: [PATCH] Add prefixLines and substring helpers to query templates --- packages/plugs/query/engine.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/plugs/query/engine.ts b/packages/plugs/query/engine.ts index 9c2dc92..51ce5be 100644 --- a/packages/plugs/query/engine.ts +++ b/packages/plugs/query/engine.ts @@ -144,6 +144,17 @@ export async function renderQuery( if (parsedQuery.render) { Handlebars.registerHelper("json", (v) => JSON.stringify(v)); 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) => { if (typeof prefix === "string") { let yaml = YAML.stringify(v)