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

fix cachePartials extension name #115

Merged
merged 2 commits into from
Dec 2, 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 lib/hbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,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}}