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

Layouts work correctly in jade #942

Merged
merged 3 commits into from
Jun 25, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 1 addition & 4 deletions lib/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,8 @@ internals.Manager.prototype.render = function (filename, context, options, callb
return callback(err);
}

var layoutContext = Utils.clone(context);

try {
layoutContext[settings.layoutKeyword] = compiled(context, settings.runtimeOptions);
rendered = layout(layoutContext, settings.runtimeOptions);
rendered = compiled(context, settings.runtimeOptions);
}
catch (err) {
return callback(Boom.internal(err.message, err));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't be right. You are compiling the layout and never using it now for any other engine.

Expand Down
4 changes: 4 additions & 0 deletions test/unit/templates/valid/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extends layout

block content
p= message
1 change: 1 addition & 0 deletions test/unit/templates/valid/test.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
p= message
37 changes: 33 additions & 4 deletions test/unit/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ describe('Views', function () {
layout: true
});

var testViewWithJadeLayouts = new Views({
engines: { 'jade': 'jade' },
path: viewsPath + '/valid/',
layout: true
});

var testViewWithoutJadeLayouts = new Views({
engines: { 'jade': 'jade' },
path: viewsPath + '/valid/',
layout: false
});

it('renders with async compile', function (done) {

var views = new Views({
Expand All @@ -57,7 +69,7 @@ describe('Views', function () {
views.render('valid/test', { title: 'test', message: 'Hapi' }, null, function (err, rendered, config) {

expect(rendered).to.exist;
expect(rendered.length).above(1);
expect(rendered).to.contain('Hapi');
done();
});
});
Expand Down Expand Up @@ -92,7 +104,7 @@ describe('Views', function () {
testView.render('valid/test', { title: 'test', message: 'Hapi' }, null, function (err, rendered, config) {

expect(rendered).to.exist;
expect(rendered.length).above(1);
expect(rendered).to.contain('Hapi');
done();
});
});
Expand All @@ -102,10 +114,27 @@ describe('Views', function () {
testViewWithLayouts.render('valid/test', { title: 'test', message: 'Hapi' }, null, function (err, rendered, config) {

expect(rendered).to.exist;
expect(rendered.length).above(1);
expect(rendered).to.contain('Hapi');
done();
});
});

it('should work and not throw with valid jade layouts', function (done) {

testViewWithJadeLayouts.render('index', { title: 'test', message: 'Hapi' }, null, function (err, rendered, config) {

expect(rendered).to.contain('Hapi');
done();
});
});

it('should work and not throw without jade layouts', function (done) {

testViewWithoutJadeLayouts.render('test', { title: 'test', message: 'Hapi Message' }, null, function (err, rendered, config) {

expect(rendered).to.contain('Hapi Message');
done();
});
});

it('should work and not throw with basePath, template name, and no path', function (done) {
Expand All @@ -114,7 +143,7 @@ describe('Views', function () {
views.render('test', { title: 'test', message: 'Hapi' }, { basePath: viewsPath + '/valid' }, function (err, rendered, config) {

expect(rendered).to.exist;
expect(rendered.length).above(1);
expect(rendered).to.contain('Hapi');
done();
});
});
Expand Down