Skip to content

Commit

Permalink
Merge pull request hapijs#942 from wpreul/master
Browse files Browse the repository at this point in the history
Layouts work correctly in jade
  • Loading branch information
geek committed Jun 25, 2013
2 parents 252a6f8 + b7849ed commit 2bf793f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ When creating a server instance, the following options configure the server's be
not supported and are ignored. Defaults to no helpers support (empty path).
- `basePath` - a base path used as prefix for `path` and `partialsPath`. No default.
- `layout` - if set to `true`, layout support is enabled. A layout is a single template file used as the parent template for other view templates
in the same engine. The layout template name must be 'layout.ext' where 'ext' is the engine's extension.
Defaults to `false`.
in the same engine. The layout template name must be 'layout.ext' where 'ext' is the engine's extension. Disable 'layout' when using Jade as
it will handle including any layout files independently of Hapi. Defaults to `false`.
- `layoutKeyword` - the key used by the template engine to denote where primary template content should go. Defaults to `'content'`.
- `encoding` - the text encoding used by the templates when reading the files and outputting the result. Defaults to `'utf-8'`.
- `isCached` - if set to `false`, templates will not be cached (thus will be read from file on every use). Defaults to `true`.
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
3 changes: 2 additions & 1 deletion test/unit/templates/valid/layout.jade
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
html
body
block content
block content
=content
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

0 comments on commit 2bf793f

Please sign in to comment.