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

refactor: use Object.assign and var to let/const #8

Merged
merged 2 commits into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
5 changes: 2 additions & 3 deletions lib/renderer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

var ejs = require('ejs');
var assign = require('object-assign');
const ejs = require('ejs');

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

ejsRenderer.compile = function(data) {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
],
"license": "MIT",
"dependencies": {
"ejs": "^2.3.4",
"object-assign": "^4.0.1"
"ejs": "^2.3.4"
},
"devDependencies": {
"chai": "^3.4.1",
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