ejs icon indicating copy to clipboard operation
ejs copied to clipboard

Added async handling of the `includer`

Open N247S opened this issue 3 years ago • 0 comments

This is a possible easy fix for the issue I reported yesterday.

I am not sure if the typescript declarations gets updated automatically, or if that takes additional actions, If more things are required to push this, feel free to ask.

This change allows for the ClientFunction and AsyncClientFunction's third argument (includer) to be both a normal and an async function (or a normal function returning a Promise instance). In fact everything inside a raw-output and escaped-output tag can be. Example:

function customIncluder(options, path, data)
{
  return fetch(path)
    .then((r) => r.text())
    .then((t) => {
      ejs.compile(t, options)(data, null, (ipath, idata) => customIncluder(options, ipath, idata));
    })
}

let data;
let options = {client: true, async: true};
ejs.compile("<%- include("test.ejs") _%>", options)(data, null, (ipath, idata) => customIncluder(options, ipath, idata));

N247S avatar Jan 03 '23 21:01 N247S