Skip to content

Commit

Permalink
add support for groupedData
Browse files Browse the repository at this point in the history
  • Loading branch information
dawnerd committed Mar 2, 2019
1 parent 5fba46e commit aab5c0b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
1 change: 0 additions & 1 deletion .node-version

This file was deleted.

2 changes: 1 addition & 1 deletion lib/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function(viewConfig) {
}
}
// aug with globals:
const obj = aug({}, viewConfig.data, viewConfig.options.globals);
const obj = aug({}, viewConfig.data, viewConfig.groupedData, viewConfig.options.globals);
let result;

try {
Expand Down
47 changes: 47 additions & 0 deletions test/test.views.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,53 @@ lab.test('globals', async() => {
await server.stop();
});

lab.test('grouped', async() => {
const server = new Hapi.Server({
debug: { request: '*', log: 'hapi-views' }
});
server.method('yaml', (request, yamlFile) => {
return new Promise((resolve) => {
return resolve({ test1: true });
});
});
// start server
await server.register([
require('vision'),
{
plugin: require('../'),
options: {
dataPath: `${process.cwd()}/test/yaml`,
routes: {
'/yaml': {
view: 'yaml',
groupedData: {
grouped: true
},
data: {
yaml1: 'yaml()',
}
}
},
globals: {
yaml2: { property: 1235 }
}
}
}
]);
server.views({
engines: { html: require('handlebars') },
path: `${__dirname}/views`
});
const response = await server.inject({ url: '/yaml' });
const context = response.request.response.source.context;
expect(context).to.equal({
yaml1: { test1: true },
yaml2: { property: 1235 },
grouped: true
});
await server.stop();
});

lab.test('onError', async() => {
const server = new Hapi.Server({
debug: { log: 'hapi-views', request: '*' },
Expand Down

0 comments on commit aab5c0b

Please sign in to comment.