Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added async handling of the includer #709

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Added async handling of the includer #709

wants to merge 1 commit into from

Conversation

N247S
Copy link

@N247S N247S commented Jan 3, 2023

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));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant