From b7dee70961ae0c4c10f4091e42c32c99b7974ef2 Mon Sep 17 00:00:00 2001 From: Ca5e Date: Sat, 9 Mar 2024 17:23:58 +0100 Subject: [PATCH] Add `log` helper to documentation tno-terminology-design/tev2-tools#40 --- .../syntax/81-handlebars-helper-functions.md | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/docs/specs/syntax/81-handlebars-helper-functions.md b/docs/specs/syntax/81-handlebars-helper-functions.md index f077809e16..400fa2dfd5 100644 --- a/docs/specs/syntax/81-handlebars-helper-functions.md +++ b/docs/specs/syntax/81-handlebars-helper-functions.md @@ -36,7 +36,6 @@ Here is a summary of the handlebar helpers that can always be used; you can clic | [`#each`](https://handlebarsjs.com/guide/builtin-helpers.html#each) | Iterates over a list of elements. Inside the block, you can use `this` to reference the element being iterated over. | | [`#with`](https://handlebarsjs.com/guide/builtin-helpers.html#with) | Enables you to change the evaluation context of template-parts. | | [`#lookup`](https://handlebarsjs.com/guide/builtin-helpers.html#lookup) | Allows for dynamic parameter resolution using Handlebars variables. | -| [`#log`](https://handlebarsjs.com/guide/builtin-helpers.html#log) | allows for logging of context state while executing a template. | @@ -45,8 +44,8 @@ Here is a summary of the handlebar helpers that can always be used; you can clic The function of the helper `capFirst` is to capitalize every first character from every word in a string. ```ts title="Examples for 'capFirst'" -{{capFirst entry.glossaryTerm}} # e.g. "converter profile" becomes "Converter Profile" -{{capFirst entry.glossaryText}} # e.g. "This is a description; for SOME TERM" becomes "This Is A Description; For SOME TERM" +{{capFirst entry.glossaryTerm}} // e.g. "converter profile" becomes "Converter Profile" +{{capFirst entry.glossaryText}} // e.g. "This is a description; for SOME TERM" becomes "This Is A Description; For SOME TERM" ``` The helper `capFirst` replaces the first character of every word of its argument with the capitalized equivalent. @@ -54,6 +53,21 @@ Words are obtained by splitting the input on space characters.
*It takes a string as input, splits the string at spaces, capitalizes the first character of every split item, reconstructs the input string fomr the split items, and returns the result.* +## `log` {#log} + +This function overwrites the built-in [`log`](https://handlebarsjs.com/guide/builtin-helpers.html#log) helper from Handlebars and behaves similarly. Compared to the default: it makes use of [tslog](https://www.npmjs.com/package/tslog), and adds an option to silence the output related to a [converter](@) call. Any number of arguments may be passed to this helper and all will be forwarded to the logger. + +The log level may be set using the `level` option. Supported values are provided by [tslog](https://www.npmjs.com/package/tslog) [here](https://www.npmjs.com/package/tslog#default-log-level), with the addition of `silent`. When omitted, `warn` is the default value. + +```ts title="Examples for 'log'" +{{log 'termid' termid 'error' err.cause}} +{{log 'info' 'This is an informational message'}} + +// Examples below will prevent errors caused by the conversion call from being logged +{{log 'silent' 'This message will not be logged'}} +{{regularize entry.term}}{{log 'silent'}} +``` + ## `noRefs`{#norefs} The function of the helper `noRefs` is to replace all [TermRefs](@) from a string, with its (capitalized) `showtext`. Capitalization is done by the helper `capFirst`.