From aeac1784dcb0554336520c54bc42f52788e51b55 Mon Sep 17 00:00:00 2001 From: shadowtime2000 <66655515+shadowtime2000@users.noreply.github.com> Date: Mon, 14 Dec 2020 21:42:04 -0800 Subject: [PATCH 1/2] docs: docs jsdoc for renderasync --- src/render.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/render.ts b/src/render.ts index 0e53a1a7..c5b36b99 100644 --- a/src/render.ts +++ b/src/render.ts @@ -36,7 +36,7 @@ function handleCache(template: string | TemplateFunction, options: EtaConfig): T * If `config.async` is `false`, Eta will return the rendered template. * * If `config.async` is `true` and there's a callback function, Eta will call the callback with `(err, renderedTemplate)`. - * If `config.async` is `true` and there's not a callback function, Eta will return a Promise that resolves to the rendered template + * If `config.async` is `true` and there's not a callback function, Eta will return a Promise that resolves to the rendered template. * * If `config.cache` is `true` and `config` has a `name` or `filename` property, Eta will cache the template on the first render and use the cached template for all subsequent renders. * @@ -84,6 +84,21 @@ export default function render( } } +/** + * Render a template asynchronously + * + * If `template` is a string, Eta will compile it to a function and call it with the provided data. + * If `template` is a function, Eta will call it with the provided data. + * + * If there is a callback function, Eta will call it with `(err, renderedTemplate)`. + * If there is not a callback function, Eta will return a Promise that resolves to the rendered template + * + * @param template Template string or template function + * @param data Data to render the template with + * @param config Optional config options + * @param cb Callback function + */ + export function renderAsync( template: string | TemplateFunction, data: object, From 87fa30c96901b13bc508659fb69da4c32343bcc0 Mon Sep 17 00:00:00 2001 From: shadowtime2000 <66655515+shadowtime2000@users.noreply.github.com> Date: Mon, 14 Dec 2020 21:43:19 -0800 Subject: [PATCH 2/2] docs: jsdoc for renderfileasync --- src/file-handlers.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/file-handlers.ts b/src/file-handlers.ts index a341bf90..4fc2de60 100644 --- a/src/file-handlers.ts +++ b/src/file-handlers.ts @@ -241,6 +241,33 @@ function renderFile( return tryHandleCache(data, renderConfig, callback) } +/** + * Render a template from a filepath asynchronously. + * + * @param filepath Path to template file. If relative, specify `views` on the config object + * + * This can take two different function signatures: + * + * - `renderFile(filename, dataAndConfig, [cb])` + * - Eta will merge `dataAndConfig` into `eta.config` + * - `renderFile(filename, data, [config], [cb])` + * + * Note that renderFile does not immediately return the rendered result. If you pass in a callback function, it will be called with `(err, res)`. Otherwise, `renderFile` will return a `Promise` that resolves to the render result. + * + * **Examples** + * + * ```js + * eta.renderFile("./template.eta", data, {cache: true}, function (err, rendered) { + * if (err) console.log(err) + * console.log(rendered) + * }) + * + * let rendered = await eta.renderFile("./template.eta", data, {cache: true}) + * + * let rendered = await eta.renderFile("./template", {...data, cache: true}) + * ``` + */ + function renderFileAsync( filename: string, data: DataObj,