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

Fix some problems with async rendering #448

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions lib/ejs.js
Expand Up @@ -641,7 +641,7 @@ Template.prototype = {
e.message += ' while compiling ejs\n\n';
e.message += 'If the above error is not helpful, you may want to try EJS-Lint:\n';
e.message += 'https://github.com/RyanZim/EJS-Lint';
if (!e.async) {
if (!opts.async) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already fixed this in #460 (d6376fa).

e.message += '\n';
e.message += 'Or, if you meant to create an async function, pass async: true as an option.';
}
Expand Down Expand Up @@ -905,12 +905,25 @@ exports.escapeXML = utils.escapeXML;
* Express.js support.
*
* This is an alias for {@link module:ejs.renderFile}, in order to support
* Express.js out-of-the-box.
* Express.js out-of-the-box. If rendered using async, a wrapper callback
* is passed to {@link module:ejs.renderFile} that waits until the returned
* promise is resolved and passes the result to Express.js
*
* @func
*/

exports.__express = exports.renderFile;
exports.__express = function (file, opts, callback) {
if (opts.async) {
exports.renderFile(file, opts, function (err, promise) {
promise.then(function (data) {
callback(err, data);
});
});
}
else {
exports.renderFile(file, opts, callback);
}
};

// Add require support
/* istanbul ignore else */
Expand Down