Skip to content

Commit

Permalink
refactor: use ES6 syntax
Browse files Browse the repository at this point in the history
var to let/const
arrow functions
  • Loading branch information
weyusi committed Nov 1, 2018
1 parent 414bb13 commit ddb1728
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

'use strict';

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

hexo.extend.renderer.register('ejs', 'html', renderer, true);
2 changes: 1 addition & 1 deletion lib/renderer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var ejs = require('ejs');
const ejs = require('ejs');

function ejsRenderer(data, locals) {
return ejs.render(data.text, Object.assign({filename: data.path}, locals));
Expand Down
46 changes: 23 additions & 23 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
'use strict';

var should = require('chai').should(); // eslint-disable-line
var fs = require('hexo-fs');
var pathFn = require('path');
const should = require('chai').should(); // eslint-disable-line
const fs = require('hexo-fs');
const pathFn = require('path');

describe('EJS renderer', function() {
var r = require('../lib/renderer');
describe('EJS renderer', () => {
const r = require('../lib/renderer');

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

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

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

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

it('include', function() {
var body = '<% include test %>';
var path = pathFn.join(__dirname, 'include_test', 'index.ejs');
var includePath = pathFn.join(path, '../test.ejs');
var includeBody = 'include body';
it('include', () => {
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(function() {
var result = r({
return fs.writeFile(includePath, includeBody).then(() => {
const result = r({
text: body,
path: path
});

result.should.eql(includeBody);
}).finally(function() {
}).finally(() => {
return fs.unlink(includePath);
});
});

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

Expand Down

0 comments on commit ddb1728

Please sign in to comment.