Skip to content

Commit

Permalink
Merge pull request #115 from lavaxun/master
Browse files Browse the repository at this point in the history
fix cachePartials extension name
  • Loading branch information
jtwebman authored Dec 2, 2018
2 parents c34d4cb + 7cebbb0 commit e9b246f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/hbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ ExpressHbs.prototype.cachePartials = function(cb) {
var dirname = path.dirname(entry.path);
dirname = dirname === '.' ? '' : dirname + '/';

var name = dirname + path.basename(entry.name, path.extname(entry.name));
var name = dirname + path.basename(entry.name, self._options.extname);
// fix the path in windows
name = name.split('\\').join('/');
self.registerPartial(name, source, entry.fullPath);
Expand Down
35 changes: 35 additions & 0 deletions test/customExtension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';
var assert = require('assert');
var hbs = require('..');
var path = require('path');
var H = require('./helpers');


// MEANJS is using custom extension .server.view.html instead of .hbs
// https://github.com/meanjs/mean
describe('custom extension for partials view', function() {
var dirname = path.join(__dirname, 'views/customExtension');
var render = hbs.create().express4({
extname: '.server.view.html',
partialsDir: dirname + '/partialsDir'
});

it('should allow rendering multiple partials with custom extension', function(done) {
function check(err, html) {
assert.ifError(err);
assert.equal(
'<html>' +
'<subpartial>1</subpartial>' +
'<partial>1</partial>' +
'<subpartial>2</subpartial>' +
'<partial>2</partial>' +
'</html>',
H.stripWs(html));
done();
}

var options = {cache: true, settings: {views: dirname }};
render(dirname + '/template.server.view.html', options, check);
});

});
1 change: 1 addition & 0 deletions test/views/customExtension/layout.server.view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html>{{{body}}}</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<partial>1</partial>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<partial>2</partial>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<subpartial>1</subpartial>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<subpartial>2</subpartial>
5 changes: 5 additions & 0 deletions test/views/customExtension/template.server.view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{!< layout}}
{{> subs/subPartial1}}
{{> partial1}}
{{> subs/subPartial2}}
{{> partial2}}

0 comments on commit e9b246f

Please sign in to comment.