Skip to content

Commit

Permalink
Merge 79b4da6 into 80c3ef3
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Dec 23, 2019
2 parents 80c3ef3 + 79b4da6 commit 246c89f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

const renderer = require('./lib/renderer');

hexo.extend.renderer.register('ejs', 'html', renderer, true);
hexo.extend.renderer.register('ejs', 'html', renderer);
6 changes: 2 additions & 4 deletions lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
const ejs = require('ejs');

function ejsRenderer(data, locals) {
return ejs.render(data.text, Object.assign({filename: data.path}, locals));
return ejs.render(data.text, Object.assign({ filename: data.path }, locals), { async: true });
}

ejsRenderer.compile = function(data) {
return ejs.compile(data.text, {
filename: data.path
});
return ejs.compile(data.text, { filename: data.path }, { async: true });
};

module.exports = ejsRenderer;
37 changes: 15 additions & 22 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,39 @@ const pathFn = require('path');
describe('EJS renderer', () => {
const r = require('../lib/renderer');

it('default', () => {
it('default', async () => {
const body = 'Hello <%= name %>';
const result = r({text: body}, {name: 'world'});
const result = await r({ text: body }, { name: 'world' });

result.should.eql('Hello world');
});

it('comments', () => {
const body = [
'Comment <%# hidden %>'
].join('\n');
it('comments', async () => {
const body = ['Comment <%# hidden %>'].join('\n');

const result = r({text: body});
const result = await r({text: body});
result.should.eql('Comment ');
});

it('include', () => {
it('include', async () => {
const body = '<%- include(\'test\') %>';
const path = pathFn.join(__dirname, 'include_test', 'index.ejs');
const includePath = pathFn.join(path, '../test.ejs');
const includeBody = 'include body';

return fs.writeFile(includePath, includeBody).then(() => {
const result = r({
text: body,
path
});
await fs.writeFile(includePath, includeBody);

result.should.eql(includeBody);
}).finally(() => {
return fs.unlink(includePath);
});
const render = await r.compile({ text: body, path });
const result = await render({ text: body, path });
result.should.eql(includeBody);

await fs.unlink(includePath);
});

it('compile', () => {
it('compile', async () => {
const body = 'Hello <%= name %>';
const render = r.compile({text: body});
const result = render({
name: 'world'
});
const render = await r.compile({ text: body });
const result = await render({ name: 'world' });

result.should.eql('Hello world');
});
Expand Down

0 comments on commit 246c89f

Please sign in to comment.