Skip to content

Commit

Permalink
Merge 16bd6d8 into a027779
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubgs committed Jan 22, 2019
2 parents a027779 + 16bd6d8 commit 93217ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/plugins/helper/partial.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ module.exports = ctx => function partial(name, locals, options = {}) {
const viewLocals = { layout: false };

if (!view) {
ctx.log.warn('Partial %s does not exist. %s', chalk.magenta(name), chalk.gray(`(in ${currentView})`));
return '';
throw new Error(`Partial ${name} does not exist. (in ${currentView})`);
}

if (options.only) {
Expand Down
9 changes: 7 additions & 2 deletions test/scripts/helpers/partial.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ describe('partial', () => {
const hexo = new Hexo(pathFn.join(__dirname, 'partial_test'), {silent: true});
const themeDir = pathFn.join(hexo.base_dir, 'themes', 'test');
const viewDir = pathFn.join(themeDir, 'layout') + pathFn.sep;
const viewName = 'article.swig'

const ctx = {
site: hexo.locals,
config: hexo.config,
view_dir: viewDir,
filename: pathFn.join(viewDir, 'post', 'article.swig'),
filename: pathFn.join(viewDir, 'post', viewName),
foo: 'foo',
cache: true
};
Expand Down Expand Up @@ -43,7 +44,11 @@ describe('partial', () => {
partial('widget/tag').should.eql('tag widget');

// not found
partial('foo').should.eql('');
try {
partial('foo')
} catch (err) {
err.should.have.property('message', `Partial foo does not exist. (in post/${viewName})`);
}
});

it('locals', () => {
Expand Down

0 comments on commit 93217ab

Please sign in to comment.