@onlineapps/cookbook-template-helpers
v1.0.11
Published
Template helper functions for cookbook variable resolution - string2file, file2string, and more
Maintainers
Readme
@onlineapps/cookbook-template-helpers
Template helper functions for cookbook variable resolution. Helper functions enable data transformations directly in cookbook template variables.
Installation
npm install @onlineapps/cookbook-template-helpersOverview
Helper functions can be used in cookbook template variables using the syntax:
{{helper_name(argument)}}Available Helpers
normalizeString
Removes nebezpečné / ne-print znaky, ponechá písmena (včetně diakritiky), čísla, mezery a základní interpunkci. Zachová diakritiku a case.
Signature:
function normalizeString(value)webalizeString
Normalizuje řetězec pro URL/slug: odstraní diakritiku, interpunkci, nahradí mezery pomlčkami, převede na lowercase, zkolabuje vícenásobné pomlčky.
Signature:
function webalizeString(value)string2file
Převede string nebo inline descriptor na file descriptor (přes ContentResolver). Ukládá do storage podle nastavení ContentResolveru.
Signature:
async function string2file(input, context)file2string
Převede file/inline descriptor na string (přes ContentResolver). File stáhne z MinIO, inline vrátí přímo.
Signature:
async function file2string(descriptor, context)Usage in Cookbook
Helpers jsou k dispozici při resolvování template proměnných:
{
"input": {
"title": "{{normalizeString(api_input.title)}}",
"slug": "{{webalizeString(api_input.title)}}",
"file": "{{string2file(api_input.content)}}",
"content": "{{file2string(steps.prepare.output.file_descriptor)}}"
}
}Integration
Helper functions are passed to the cookbook executor:
const templateHelpers = require('@onlineapps/cookbook-template-helpers');
const { CookbookExecutor } = require('@onlineapps/cookbook-executor');
const executor = new CookbookExecutor(cookbook, {
helpers: templateHelpers
});Adding Custom Helpers
You can combine global helpers with custom helpers:
const templateHelpers = require('@onlineapps/cookbook-template-helpers');
const customHelpers = require('./customHelpers');
const allHelpers = {
...templateHelpers,
...customHelpers
};
const executor = new CookbookExecutor(cookbook, {
helpers: allHelpers
});Helper Function Requirements
- Deterministic: Stejný vstup = stejný výstup
- Bez vedlejších efektů: String helpery jsou čisté; file helpery používají ContentResolver
- Chyby: Měly by být jasné a srozumitelné
Dependencies
@onlineapps/content-resolver(pro string2file/file2string)
License
PROPRIETARY
