Comparing version 3.0.0 to 4.0.0
@@ -0,5 +1,6 @@ | ||
'use strict'; | ||
// Load modules | ||
var Fs = require('fs'); | ||
var Path = require('path'); | ||
const Fs = require('fs'); | ||
const Path = require('path'); | ||
@@ -9,3 +10,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -23,4 +24,4 @@ | ||
var self = this; | ||
Fs.readdirSync(this._dirPath).forEach(function (file) { | ||
const self = this; | ||
Fs.readdirSync(this._dirPath).forEach((file) => { | ||
@@ -59,3 +60,3 @@ if (file[0] !== '.') { | ||
var contents = Fs.readFileSync(Path.join(this._dirPath, file)); | ||
const contents = Fs.readFileSync(Path.join(this._dirPath, file)); | ||
@@ -62,0 +63,0 @@ return { |
@@ -0,7 +1,8 @@ | ||
'use strict'; | ||
// Load modules | ||
var Path = require('path'); | ||
var Hapi = require('hapi'); | ||
var Pages = require('./pages'); | ||
var Vision = require('../..'); | ||
const Path = require('path'); | ||
const Hapi = require('hapi'); | ||
const Pages = require('./pages'); | ||
const Vision = require('../..'); | ||
@@ -11,6 +12,6 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
var view = function (viewName) { | ||
const view = function (viewName) { | ||
@@ -24,3 +25,3 @@ return function (request, reply) { | ||
var getPages = function (request, reply) { | ||
const getPages = function (request, reply) { | ||
@@ -31,3 +32,3 @@ return reply.view('index', { pages: Object.keys(Pages.getAll()), title: 'All pages' }); | ||
var getPage = function (request, reply) { | ||
const getPage = function (request, reply) { | ||
@@ -38,3 +39,3 @@ return reply.view('page', { page: Pages.getPage(request.params.page), title: request.params.page }); | ||
var createPage = function (request, reply) { | ||
const createPage = function (request, reply) { | ||
@@ -46,3 +47,3 @@ Pages.savePage(request.payload.name, request.payload.contents); | ||
var showEditForm = function (request, reply) { | ||
const showEditForm = function (request, reply) { | ||
@@ -53,3 +54,3 @@ return reply.view('edit', { page: Pages.getPage(request.params.page), title: 'Edit: ' + request.params.page }); | ||
var updatePage = function (request, reply) { | ||
const updatePage = function (request, reply) { | ||
@@ -63,5 +64,5 @@ Pages.savePage(request.params.page, request.payload.contents); | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000, state: { ignoreErrors: true } }); | ||
server.register(Vision, function (err) { | ||
server.register(Vision, (err) => { | ||
@@ -85,3 +86,3 @@ if (err) { | ||
server.route({ method: 'POST', path: '/pages/{page}/edit', handler: updatePage }); | ||
server.start(function (err) { | ||
server.start((err) => { | ||
@@ -88,0 +89,0 @@ if (err) { |
@@ -0,5 +1,6 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hapi = require('hapi'); | ||
var Vision = require('../..'); | ||
const Hapi = require('hapi'); | ||
const Vision = require('../..'); | ||
@@ -9,6 +10,6 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
var rootHandler = function (request, reply) { | ||
const rootHandler = function (request, reply) { | ||
@@ -24,5 +25,5 @@ reply.view('index', { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
server.register(Vision, function (err) { | ||
server.register(Vision, (err) => { | ||
@@ -40,3 +41,3 @@ if (err) { | ||
server.route({ method: 'GET', path: '/', handler: rootHandler }); | ||
server.start(function (err) { | ||
server.start((err) => { | ||
@@ -43,0 +44,0 @@ if (err) { |
@@ -0,5 +1,6 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hapi = require('hapi'); | ||
var Vision = require('../..'); | ||
const Hapi = require('hapi'); | ||
const Vision = require('../..'); | ||
@@ -9,6 +10,6 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
var rootHandler = function (request, reply) { | ||
const rootHandler = function (request, reply) { | ||
@@ -24,5 +25,5 @@ reply.view('index', { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
server.register(Vision, function (err) { | ||
server.register(Vision, (err) => { | ||
@@ -41,3 +42,3 @@ if (err) { | ||
server.route({ method: 'GET', path: '/', handler: rootHandler }); | ||
server.start(function (err) { | ||
server.start((err) => { | ||
@@ -44,0 +45,0 @@ if (err) { |
@@ -0,5 +1,6 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hapi = require('hapi'); | ||
var Vision = require('../..'); | ||
const Hapi = require('hapi'); | ||
const Vision = require('../..'); | ||
@@ -9,6 +10,6 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
var handler = function (request, reply) { | ||
const handler = function (request, reply) { | ||
@@ -24,5 +25,5 @@ reply.view('basic/index', { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
server.register(Vision, function (err) { | ||
server.register(Vision, (err) => { | ||
@@ -39,3 +40,3 @@ if (err) { | ||
server.route({ method: 'GET', path: '/', handler: handler }); | ||
server.start(function (err) { | ||
server.start((err) => { | ||
@@ -42,0 +43,0 @@ if (err) { |
@@ -0,5 +1,6 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hapi = require('hapi'); | ||
var Vision = require('../..'); | ||
const Hapi = require('hapi'); | ||
const Vision = require('../..'); | ||
@@ -9,6 +10,6 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
var handler = function (request, reply) { | ||
const handler = function (request, reply) { | ||
@@ -24,5 +25,5 @@ reply.view('index', { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
server.register(Vision, function (err) { | ||
server.register(Vision, (err) => { | ||
@@ -41,3 +42,3 @@ if (err) { | ||
server.route({ method: 'GET', path: '/', handler: handler }); | ||
server.start(function (err) { | ||
server.start((err) => { | ||
@@ -44,0 +45,0 @@ if (err) { |
@@ -0,5 +1,6 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hapi = require('hapi'); | ||
var Vision = require('../..'); | ||
const Hapi = require('hapi'); | ||
const Vision = require('../..'); | ||
@@ -9,6 +10,6 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
var handler = function (request, reply) { | ||
const handler = function (request, reply) { | ||
@@ -24,5 +25,5 @@ reply.view('withLayout/index', { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
server.register(Vision, function (err) { | ||
server.register(Vision, (err) => { | ||
@@ -40,3 +41,3 @@ if (err) { | ||
server.route({ method: 'GET', path: '/', handler: handler }); | ||
server.start(function (err) { | ||
server.start((err) => { | ||
@@ -43,0 +44,0 @@ if (err) { |
@@ -0,5 +1,6 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hapi = require('hapi'); | ||
var Vision = require('../..'); | ||
const Hapi = require('hapi'); | ||
const Vision = require('../..'); | ||
@@ -9,6 +10,6 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
var handler = function (request, reply) { | ||
const handler = function (request, reply) { | ||
@@ -24,5 +25,5 @@ reply.view('withPartials/index', { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
server.register(Vision, function (err) { | ||
server.register(Vision, (err) => { | ||
@@ -40,3 +41,3 @@ if (err) { | ||
server.route({ method: 'GET', path: '/', handler: handler }); | ||
server.start(function (err) { | ||
server.start((err) => { | ||
@@ -43,0 +44,0 @@ if (err) { |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
module.exports = function (message) { | ||
@@ -2,0 +4,0 @@ |
@@ -0,5 +1,6 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hapi = require('hapi'); | ||
var Vision = require('../..'); | ||
const Hapi = require('hapi'); | ||
const Vision = require('../..'); | ||
@@ -9,6 +10,6 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
var rootHandler = function (request, reply) { | ||
const rootHandler = function (request, reply) { | ||
@@ -21,3 +22,3 @@ reply.view('index', { | ||
var aboutHandler = function (request, reply) { | ||
const aboutHandler = function (request, reply) { | ||
@@ -33,5 +34,5 @@ reply.view('about', { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
server.register(Vision, function (err) { | ||
server.register(Vision, (err) => { | ||
@@ -52,3 +53,3 @@ if (err) { | ||
server.route({ method: 'GET', path: '/about', handler: aboutHandler }); | ||
server.start(function (err) { | ||
server.start((err) => { | ||
@@ -55,0 +56,0 @@ if (err) { |
@@ -0,13 +1,18 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hapi = require('hapi'); | ||
var Vision = require('../..'); | ||
const Hapi = require('hapi'); | ||
const Vision = require('../..'); | ||
require('babel-core/register')({ | ||
plugins: ['transform-react-jsx'] | ||
}); | ||
// Declare internals | ||
var internals = {}; | ||
const internals = {}; | ||
var rootHandler = function (request, reply) { | ||
const rootHandler = function (request, reply) { | ||
@@ -20,3 +25,3 @@ reply.view('index', { | ||
var aboutHandler = function (request, reply) { | ||
const aboutHandler = function (request, reply) { | ||
@@ -32,5 +37,5 @@ reply.view('about', { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
server.register(Vision, function (err) { | ||
server.register(Vision, (err) => { | ||
@@ -51,3 +56,3 @@ if (err) { | ||
server.route({ method: 'GET', path: '/about', handler: aboutHandler }); | ||
server.start(function (err) { | ||
server.start((err) => { | ||
@@ -54,0 +59,0 @@ if (err) { |
@@ -1,2 +0,2 @@ | ||
var React = require('react/addons'); | ||
var React = require('react'); | ||
var Head = require('./includes/head.jsx'); | ||
@@ -3,0 +3,0 @@ var Foot = require('./includes/foot.jsx'); |
@@ -1,2 +0,2 @@ | ||
var React = require('react/addons'); | ||
var React = require('react'); | ||
@@ -3,0 +3,0 @@ var Component = React.createClass({ |
@@ -1,2 +0,2 @@ | ||
var React = require('react/addons'); | ||
var React = require('react'); | ||
@@ -3,0 +3,0 @@ var Component = React.createClass({ |
@@ -1,2 +0,2 @@ | ||
var React = require('react/addons'); | ||
var React = require('react'); | ||
var Layout = require('./layout.jsx'); | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
var React = require('react/addons'); | ||
var React = require('react'); | ||
var Head = require('./includes/head.jsx'); | ||
@@ -12,4 +12,4 @@ var Foot = require('./includes/foot.jsx'); | ||
{this.props.children} | ||
<Foot /> | ||
</body> | ||
<Foot /> | ||
</html> | ||
@@ -16,0 +16,0 @@ ); |
@@ -0,5 +1,6 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hapi = require('hapi'); | ||
var Vision = require('../..'); | ||
const Hapi = require('hapi'); | ||
const Vision = require('../..'); | ||
@@ -9,6 +10,6 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
var indexHandler = function (request, reply) { | ||
const indexHandler = function (request, reply) { | ||
@@ -18,3 +19,3 @@ reply.view('index.html'); | ||
var oneHandler = function (request, reply) { | ||
const oneHandler = function (request, reply) { | ||
@@ -24,3 +25,3 @@ reply.view('index.jade'); | ||
var twoHandler = function (request, reply) { | ||
const twoHandler = function (request, reply) { | ||
@@ -33,5 +34,5 @@ reply.view('handlebars.html'); | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
server.register(Vision, function (err) { | ||
server.register(Vision, (err) => { | ||
@@ -57,3 +58,3 @@ if (err) { | ||
server.route({ method: 'GET', path: '/two', handler: twoHandler }); | ||
server.start(function (err) { | ||
server.start((err) => { | ||
@@ -60,0 +61,0 @@ if (err) { |
@@ -0,6 +1,7 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hapi = require('hapi'); | ||
var Mustache = require('mustache'); | ||
var Vision = require('../..'); | ||
const Hapi = require('hapi'); | ||
const Mustache = require('mustache'); | ||
const Vision = require('../..'); | ||
@@ -10,6 +11,6 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
var rootHandler = function (request, reply) { | ||
const rootHandler = function (request, reply) { | ||
@@ -25,5 +26,5 @@ reply.view('index', { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
server.register(Vision, function (err) { | ||
server.register(Vision, (err) => { | ||
@@ -53,3 +54,3 @@ if (err) { | ||
server.route({ method: 'GET', path: '/', handler: rootHandler }); | ||
server.start(function (err) { | ||
server.start((err) => { | ||
@@ -56,0 +57,0 @@ if (err) { |
@@ -0,6 +1,7 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hapi = require('hapi'); | ||
var Mustache = require('mustache'); | ||
var Vision = require('../..'); | ||
const Hapi = require('hapi'); | ||
const Mustache = require('mustache'); | ||
const Vision = require('../..'); | ||
@@ -10,6 +11,6 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
var rootHandler = function (request, reply) { | ||
const rootHandler = function (request, reply) { | ||
@@ -25,5 +26,5 @@ reply.view('index', { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
server.register(Vision, function (err) { | ||
server.register(Vision, (err) => { | ||
@@ -54,3 +55,3 @@ if (err) { | ||
server.route({ method: 'GET', path: '/', handler: rootHandler }); | ||
server.start(function (err) { | ||
server.start((err) => { | ||
@@ -57,0 +58,0 @@ if (err) { |
@@ -0,6 +1,7 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hapi = require('hapi'); | ||
var Mustache = require('mustache'); | ||
var Vision = require('../..'); | ||
const Hapi = require('hapi'); | ||
const Mustache = require('mustache'); | ||
const Vision = require('../..'); | ||
@@ -10,6 +11,6 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
var rootHandler = function (request, reply) { | ||
const rootHandler = function (request, reply) { | ||
@@ -25,7 +26,7 @@ reply.view('index', { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
server.register(Vision, function (err) { | ||
server.register(Vision, (err) => { | ||
var partials = {}; | ||
const partials = {}; | ||
@@ -57,3 +58,3 @@ server.views({ | ||
server.route({ method: 'GET', path: '/', handler: rootHandler }); | ||
server.start(function (err) { | ||
server.start((err) => { | ||
@@ -60,0 +61,0 @@ if (err) { |
@@ -0,7 +1,8 @@ | ||
'use strict'; | ||
// Load modules | ||
var Hapi = require('hapi'); | ||
var Nunjucks = require('nunjucks'); | ||
var Path = require('path'); | ||
var Vision = require('../..'); | ||
const Hapi = require('hapi'); | ||
const Nunjucks = require('nunjucks'); | ||
const Path = require('path'); | ||
const Vision = require('../..'); | ||
@@ -11,6 +12,6 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
var rootHandler = function (request, reply) { | ||
const rootHandler = function (request, reply) { | ||
@@ -26,5 +27,5 @@ reply.view('index', { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
server.register(Vision, function (err) { | ||
server.register(Vision, (err) => { | ||
@@ -40,3 +41,3 @@ if (err) { | ||
var template = Nunjucks.compile(src, options.environment); | ||
const template = Nunjucks.compile(src, options.environment); | ||
@@ -60,3 +61,3 @@ return function (context) { | ||
server.route({ method: 'GET', path: '/', handler: rootHandler }); | ||
server.start(function (err) { | ||
server.start((err) => { | ||
@@ -63,0 +64,0 @@ if (err) { |
@@ -0,10 +1,7 @@ | ||
'use strict'; | ||
// Load modules | ||
var Fs = require('fs'); | ||
var Path = require('path'); | ||
var Boom = require('boom'); | ||
var Hoek = require('hoek'); | ||
var Joi = require('joi'); | ||
var Items = require('items'); | ||
var Manager = require('./manager'); | ||
const Hoek = require('hoek'); | ||
const Joi = require('joi'); | ||
const Manager = require('./manager'); | ||
// Additional helper modules required in constructor | ||
@@ -15,3 +12,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -54,3 +51,3 @@ | ||
var realm = (this.realm.plugins.vision || this.request.server.realm.plugins.vision || {}); | ||
const realm = (this.realm.plugins.vision || this.request.server.realm.plugins.vision || {}); | ||
Hoek.assert(realm.manager, 'Cannot render view without a views manager configured'); | ||
@@ -64,2 +61,4 @@ return this.response(realm.manager._response(template, context, options, this.request)); | ||
exports.register.attributes = { | ||
connections: false, | ||
once: true, | ||
pkg: require('../package.json') | ||
@@ -74,5 +73,5 @@ }; | ||
var isServer = (typeof this.route === 'function'); | ||
var server = (isServer ? this : this.server); | ||
var vision = ((!isServer ? this.route.realm.plugins.vision : null) || server.realm.plugins.vision || server.root.realm.plugins.vision || {}); | ||
const isServer = (typeof this.route === 'function'); | ||
const server = (isServer ? this : this.server); | ||
const vision = ((!isServer ? this.route.realm.plugins.vision : null) || server.realm.plugins.vision || server.root.realm.plugins.vision || {}); | ||
Hoek.assert(vision.manager, 'Missing views manager'); | ||
@@ -91,3 +90,3 @@ return vision.manager.render(template, context, options, callback); | ||
var settings = { // Shallow copy to allow making dynamic changes to context | ||
const settings = { // Shallow copy to allow making dynamic changes to context | ||
template: options.template, | ||
@@ -100,3 +99,3 @@ context: options.context, | ||
var context = { | ||
const context = { | ||
params: request.params, | ||
@@ -109,5 +108,5 @@ payload: request.payload, | ||
if (settings.context) { // Shallow copy to avoid cloning unknown objects | ||
var keys = Object.keys(settings.context); | ||
for (var i = 0, il = keys.length; i < il; ++i) { | ||
var key = keys[i]; | ||
const keys = Object.keys(settings.context); | ||
for (let i = 0, il = keys.length; i < il; ++i) { | ||
const key = keys[i]; | ||
context[key] = settings.context[key]; | ||
@@ -114,0 +113,0 @@ } |
@@ -0,9 +1,10 @@ | ||
'use strict'; | ||
// Load modules | ||
var Fs = require('fs'); | ||
var Path = require('path'); | ||
var Boom = require('boom'); | ||
var Hoek = require('hoek'); | ||
var Joi = require('joi'); | ||
var Items = require('items'); | ||
const Fs = require('fs'); | ||
const Path = require('path'); | ||
const Boom = require('boom'); | ||
const Hoek = require('hoek'); | ||
const Joi = require('joi'); | ||
const Items = require('items'); | ||
// Additional helper modules required in constructor | ||
@@ -14,3 +15,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -81,4 +82,2 @@ | ||
var self = this; | ||
Joi.assert(options, internals.schema.manager); | ||
@@ -88,8 +87,8 @@ | ||
var engines = options.engines; | ||
var defaultExtension = options.defaultExtension; | ||
const engines = options.engines; | ||
const defaultExtension = options.defaultExtension; | ||
// Clone options | ||
var defaults = Hoek.applyToDefaultsWithShallow(internals.defaults, options, ['engines', 'context']); | ||
const defaults = Hoek.applyToDefaultsWithShallow(internals.defaults, options, ['engines', 'context']); | ||
delete defaults.engines; | ||
@@ -100,3 +99,3 @@ delete defaults.defaultExtension; | ||
var extensions = Object.keys(engines); | ||
const extensions = Object.keys(engines); | ||
Hoek.assert(extensions.length, 'Views manager requires at least one registered extension handler'); | ||
@@ -110,6 +109,6 @@ | ||
extensions.forEach(function (extension) { | ||
extensions.forEach((extension) => { | ||
var config = engines[extension]; | ||
var engine = {}; | ||
const config = engines[extension]; | ||
const engine = {}; | ||
@@ -135,3 +134,3 @@ if (config.compile && | ||
var compiled = null; | ||
let compiled = null; | ||
try { | ||
@@ -144,5 +143,5 @@ compiled = engine.module.compile(str, opt); | ||
var renderer = function (context, runtimeOptions, renderNext) { | ||
const renderer = function (context, runtimeOptions, renderNext) { | ||
var rendered = null; | ||
let rendered = null; | ||
try { | ||
@@ -171,8 +170,8 @@ rendered = compiled(context, runtimeOptions); | ||
self._loadPartials(engine); | ||
self._loadHelpers(engine); | ||
this._loadPartials(engine); | ||
this._loadHelpers(engine); | ||
// Set engine | ||
self._engines[extension] = engine; | ||
this._engines[extension] = engine; | ||
}); | ||
@@ -191,15 +190,15 @@ }; | ||
var load = function () { | ||
const load = function () { | ||
var partialsPaths = [].concat(engine.config.partialsPath); | ||
const partialsPaths = [].concat(engine.config.partialsPath); | ||
partialsPaths.forEach(function (partialsPath) { | ||
partialsPaths.forEach((partialsPath) => { | ||
var path = internals.path(engine.config.relativeTo, partialsPath); | ||
var files = traverse(path); | ||
files.forEach(function (file) { | ||
const path = internals.path(engine.config.relativeTo, partialsPath); | ||
const files = traverse(path); | ||
files.forEach((file) => { | ||
var offset = path.slice(-1) === Path.sep ? 0 : 1; | ||
var name = file.slice(path.length + offset, -engine.suffix.length).replace(/\\/g, '/'); | ||
var src = Fs.readFileSync(file).toString(engine.config.encoding); | ||
const offset = path.slice(-1) === Path.sep ? 0 : 1; | ||
const name = file.slice(path.length + offset, -engine.suffix.length).replace(/\\/g, '/'); | ||
const src = Fs.readFileSync(file).toString(engine.config.encoding); | ||
engine.module.registerPartial(name, src); | ||
@@ -210,10 +209,10 @@ }); | ||
var traverse = function (path) { | ||
const traverse = function (path) { | ||
var files = []; | ||
let files = []; | ||
Fs.readdirSync(path).forEach(function (file) { | ||
Fs.readdirSync(path).forEach((file) => { | ||
file = Path.join(path, file); | ||
var stat = Fs.statSync(file); | ||
const stat = Fs.statSync(file); | ||
if (stat.isDirectory()) { | ||
@@ -247,7 +246,7 @@ files = files.concat(traverse(file)); | ||
var helpersPaths = [].concat(engine.config.helpersPath); | ||
const helpersPaths = [].concat(engine.config.helpersPath); | ||
helpersPaths.forEach(function (helpersPath) { | ||
helpersPaths.forEach((helpersPath) => { | ||
var path = internals.path(engine.config.relativeTo, helpersPath); | ||
let path = internals.path(engine.config.relativeTo, helpersPath); | ||
if (!Hoek.isAbsolutePath(path)) { | ||
@@ -257,6 +256,6 @@ path = Path.join(process.cwd(), path); | ||
Fs.readdirSync(path).forEach(function (file) { | ||
Fs.readdirSync(path).forEach((file) => { | ||
file = Path.join(path, file); | ||
var stat = Fs.statSync(file); | ||
const stat = Fs.statSync(file); | ||
if (!stat.isDirectory() && | ||
@@ -266,6 +265,6 @@ Path.basename(file)[0] !== '.') { | ||
try { | ||
var helper = require(file); | ||
const helper = require(file); | ||
if (typeof helper === 'function') { | ||
var offset = path.slice(-1) === Path.sep ? 0 : 1; | ||
var name = file.slice(path.length + offset, -Path.extname(file).length); | ||
const offset = path.slice(-1) === Path.sep ? 0 : 1; | ||
const name = file.slice(path.length + offset, -Path.extname(file).length); | ||
engine.module.registerHelper(name, helper); | ||
@@ -283,6 +282,4 @@ } | ||
var self = this; | ||
this._prepare(filename, options, (err, compiled) => { | ||
this._prepare(filename, options, function (err, compiled) { | ||
if (err) { | ||
@@ -292,3 +289,3 @@ return callback(err); | ||
self._render(compiled, context, function (err, rendered) { | ||
this._render(compiled, context, (err, rendered) => { | ||
@@ -307,8 +304,6 @@ if (err) { | ||
var self = this; | ||
options = options || {}; | ||
var fileExtension = Path.extname(template).slice(1); | ||
var extension = fileExtension || this._defaultExtension; | ||
const fileExtension = Path.extname(template).slice(1); | ||
const extension = fileExtension || this._defaultExtension; | ||
if (!extension) { | ||
@@ -318,3 +313,3 @@ return callback(Boom.badImplementation('Unknown extension and no defaultExtension configured for view template: ' + template)); | ||
var engine = this._engines[extension]; | ||
const engine = this._engines[extension]; | ||
if (!engine) { | ||
@@ -334,3 +329,3 @@ return callback(Boom.badImplementation('No view engine found for file: ' + template)); | ||
return this._prepareEngine(engine, function (err) { | ||
return this._prepareEngine(engine, (err) => { | ||
@@ -341,3 +336,3 @@ if (err) { | ||
return self._prepareTemplates(template, engine, options, callback); | ||
return this._prepareTemplates(template, engine, options, callback); | ||
}); | ||
@@ -352,3 +347,3 @@ }; | ||
try { | ||
return engine.module.prepare(engine.config, function (err) { | ||
return engine.module.prepare(engine.config, (err) => { | ||
@@ -371,9 +366,7 @@ if (err) { | ||
var self = this; | ||
var compiled = { | ||
const compiled = { | ||
settings: Hoek.applyToDefaults(engine.config, options) | ||
}; | ||
this._path(template, compiled.settings, false, function (err, templatePath) { | ||
this._path(template, compiled.settings, false, (err, templatePath) => { | ||
@@ -384,3 +377,3 @@ if (err) { | ||
self._compile(templatePath, engine, compiled.settings, function (err, compiledTemplate) { | ||
this._compile(templatePath, engine, compiled.settings, (err, compiledTemplate) => { | ||
@@ -401,3 +394,3 @@ if (err) { | ||
self._path((compiled.settings.layout === true ? 'layout' : compiled.settings.layout) + engine.suffix, compiled.settings, true, function (err, layoutPath) { | ||
this._path((compiled.settings.layout === true ? 'layout' : compiled.settings.layout) + engine.suffix, compiled.settings, true, (err, layoutPath) => { | ||
@@ -408,3 +401,3 @@ if (err) { | ||
self._compile(layoutPath, engine, compiled.settings, function (err, layout) { | ||
this._compile(layoutPath, engine, compiled.settings, (err, layout) => { | ||
@@ -428,4 +421,4 @@ if (err) { | ||
var isAbsolutePath = Hoek.isAbsolutePath(template); | ||
var isInsecurePath = template.match(/\.\.\//g); | ||
const isAbsolutePath = Hoek.isAbsolutePath(template); | ||
const isInsecurePath = template.match(/\.\.\//g); | ||
@@ -446,3 +439,3 @@ if (!settings.allowAbsolutePaths && | ||
var paths; | ||
let paths; | ||
if (isAbsolutePath) { | ||
@@ -454,3 +447,3 @@ paths = [template]; | ||
for (var i = 0, il = paths.length; i < il; ++i) { | ||
for (let i = 0, il = paths.length; i < il; ++i) { | ||
paths[i] = internals.path(settings.relativeTo, paths[i], template); | ||
@@ -460,5 +453,5 @@ } | ||
Items.serial(paths, function (path, nextFile) { | ||
Items.serial(paths, (path, nextFile) => { | ||
Fs.stat(path, function (err, stats) { | ||
Fs.stat(path, (err, stats) => { | ||
@@ -474,3 +467,3 @@ if (!err && | ||
}, | ||
function () { | ||
() => { | ||
@@ -484,11 +477,9 @@ return next(Boom.badImplementation('View file not found: `' + template + '`. Locations searched: [' + paths.join(',') + ']')); | ||
var self = this; | ||
if (this._context) { | ||
var base = typeof this._context === 'function' ? this._context() : this._context; | ||
let base = typeof this._context === 'function' ? this._context() : this._context; | ||
if (context) { | ||
base = Hoek.shallow(base); | ||
var keys = Object.keys(context); | ||
for (var i = 0, il = keys.length; i < il; ++i) { | ||
var key = keys[i]; | ||
const keys = Object.keys(context); | ||
for (let i = 0, il = keys.length; i < il; ++i) { | ||
const key = keys[i]; | ||
base[key] = context[key]; | ||
@@ -507,3 +498,3 @@ } | ||
compiled.template(context, compiled.settings.runtimeOptions, function (err, renderedContent) { | ||
compiled.template(context, compiled.settings.runtimeOptions, (err, renderedContent) => { | ||
@@ -523,3 +514,3 @@ if (err) { | ||
context[compiled.settings.layoutKeyword] = renderedContent; | ||
compiled.layout(context, compiled.settings.runtimeOptions, function (err, renderedWithLayout) { | ||
compiled.layout(context, compiled.settings.runtimeOptions, (err, renderedWithLayout) => { | ||
@@ -562,3 +553,3 @@ delete context[compiled.settings.layoutKeyword]; | ||
Fs.readFile(template, { encoding: settings.encoding }, function (err, data) { | ||
Fs.readFile(template, { encoding: settings.encoding }, (err, data) => { | ||
@@ -569,3 +560,3 @@ if (err) { | ||
engine.compileFunc(data, settings.compileOptions, function (err, compiled) { | ||
engine.compileFunc(data, settings.compileOptions, (err, compiled) => { | ||
@@ -590,3 +581,3 @@ if (err) { | ||
var source = { | ||
const source = { | ||
manager: this, | ||
@@ -604,5 +595,5 @@ template: template, | ||
var manager = response.source.manager; | ||
const manager = response.source.manager; | ||
manager._render(response.source.compiled, response.source.context, function (err, rendered) { | ||
manager._render(response.source.compiled, response.source.context, (err, rendered) => { | ||
@@ -613,3 +604,3 @@ if (err) { | ||
var config = response.source.compiled.settings; | ||
const config = response.source.compiled.settings; | ||
@@ -628,5 +619,5 @@ if (!response.headers['content-type']) { | ||
var manager = response.source.manager; | ||
const manager = response.source.manager; | ||
manager._prepare(response.source.template, response.source.options, function (err, compiled) { | ||
manager._prepare(response.source.template, response.source.options, (err, compiled) => { | ||
@@ -633,0 +624,0 @@ if (err) { |
{ | ||
"name": "vision", | ||
"description": "Templates rendering plugin support for hapi.js", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"repository": "git://github.com/hapijs/vision", | ||
@@ -14,21 +14,24 @@ "main": "lib/index.js", | ||
"engines": { | ||
"node": ">=0.10.32" | ||
"node": ">=4.0.0" | ||
}, | ||
"dependencies": { | ||
"boom": "2.x.x", | ||
"hoek": "^2.9.x", | ||
"items": "^1.1.x", | ||
"boom": "3.x.x", | ||
"hoek": "3.x.x", | ||
"items": "2.x.x", | ||
"joi": "6.x.x" | ||
}, | ||
"devDependencies": { | ||
"code": "1.x.x", | ||
"babel-core": "6.x.x", | ||
"babel-plugin-transform-react-jsx": "6.x.x", | ||
"code": "2.x.x", | ||
"ejs": "2.x.x", | ||
"handlebars": "3.x.x", | ||
"hapi": "9.x.x", | ||
"handlebars": "4.x.x", | ||
"hapi": "11.x.x", | ||
"hapi-react-views": "4.x.x", | ||
"jade": "1.x.x", | ||
"lab": "5.x.x", | ||
"lab": "7.x.x", | ||
"marko": "2.x.x", | ||
"mustache": "2.x.x", | ||
"nunjucks": "1.x.x", | ||
"hapi-react-views": "3.x.x", | ||
"react": "0.x.x" | ||
"nunjucks": "2.x.0", | ||
"react": "0.14.x" | ||
}, | ||
@@ -35,0 +38,0 @@ "scripts": { |
270
README.md
@@ -9,3 +9,4 @@ #vision | ||
**vision** decorates the [server](https://github.com/hapijs/hapi/blob/master/API.md#server) and | ||
**vision** decorates the [server](https://github.com/hapijs/hapi/blob/master/API.md#server), | ||
[request](https://github.com/hapijs/hapi/blob/master/API.md#request-object), and | ||
[reply](https://github.com/hapijs/hapi/blob/master/API.md#reply-interface) interfaces with additional | ||
@@ -16,7 +17,9 @@ methods for managing view engines that can be used to render templated responses. **vision** also | ||
**You will need to install `vision` using something like `npm install --save vision` before you can register it.** | ||
```js | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8080 }); | ||
server.register(require('vision'), function (err) { | ||
server.register(require('vision'), (err) => { | ||
@@ -36,8 +39,5 @@ if (err) { | ||
- [Nunjucks](#nunjucks) | ||
- [Usage](#usage) | ||
- [`server.views(options)`](#serverviewsoptions) | ||
- [`server.render(template, context, [options], callback)`](#serverrendertemplate-context-options-callback) | ||
- [`reply.view(template, [context, [options]])`](#replyviewtemplate-context-options) | ||
- [The `view` handler](#the-view-handler) | ||
See [API.md](./API.md) for detailed usage information. | ||
## Examples | ||
@@ -52,6 +52,6 @@ | ||
```js | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
var rootHandler = function (request, reply) { | ||
const rootHandler = function (request, reply) { | ||
@@ -64,3 +64,3 @@ reply.view('index', { | ||
server.register(require('vision'), function (err) { | ||
server.register(require('vision'), (err) => { | ||
@@ -84,6 +84,6 @@ if (err) { | ||
```js | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
var handler = function (request, reply) { | ||
const handler = function (request, reply) { | ||
@@ -96,3 +96,3 @@ reply.view('basic/index', { | ||
server.register(require('vision'), function (err) { | ||
server.register(require('vision'), (err) => { | ||
@@ -115,6 +115,6 @@ if (err) { | ||
```js | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
var rootHandler = function (request, reply) { | ||
const rootHandler = function (request, reply) { | ||
@@ -127,3 +127,3 @@ reply.view('index', { | ||
var aboutHandler = function (request, reply) { | ||
const aboutHandler = function (request, reply) { | ||
@@ -136,3 +136,3 @@ reply.view('about', { | ||
server.register(require('vision'), function (err) { | ||
server.register(require('vision'), (err) => { | ||
@@ -159,6 +159,6 @@ if (err) { | ||
```js | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
var rootHandler = function (request, reply) { | ||
const rootHandler = function (request, reply) { | ||
@@ -171,3 +171,3 @@ reply.view('index', { | ||
server.register(require('vision'), function (err) { | ||
server.register(require('vision'), (err) => { | ||
@@ -203,6 +203,6 @@ if (err) { | ||
```js | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection({ port: 8000 }); | ||
var rootHandler = function (request, reply) { | ||
const rootHandler = function (request, reply) { | ||
@@ -215,3 +215,3 @@ reply.view('index', { | ||
server.register(require('vision'), function (err) { | ||
server.register(require('vision'), (err) => { | ||
@@ -248,223 +248,1 @@ if (err) { | ||
``` | ||
## Usage | ||
Most interaction with **vision** is done via the [server](https://github.com/hapijs/hapi/blob/master/API.md#server) | ||
and [reply](https://github.com/hapijs/hapi/blob/master/API.md#reply-interface) interfaces. When the | ||
**vision** plugin is registered, the base [Hapi APIs](https://github.com/hapijs/hapi/blob/master/API.md) | ||
are augmented with the following: | ||
### `server.views(options)` | ||
Initializes the server views manager where: | ||
- `options` - a configuration object with the following: | ||
- `engines` - required object where each key is a file extension (e.g. 'html', 'hbr'), mapped | ||
to the npm module used for rendering the templates. Alternatively, the extension can be | ||
mapped to an object with the following options: | ||
- `module` - the npm module used for rendering the templates. The module object must | ||
contain the `compile()` function: | ||
- `compile()` - the rendering function. The required function signature depends on the | ||
`compileMode` settings. If the `compileMode` is `'sync'`, the signature is | ||
`compile(template, options)`, the return value is a function with signature | ||
`function(context, options)`, and the method is allowed to throw errors. If the | ||
`compileMode` is `'async'`, the signature is `compile(template, options, callback)` | ||
where `callback` has the signature `function(err, compiled)` where `compiled` is a | ||
function with signature `function(context, options, callback)` and `callback` has the | ||
signature `function(err, rendered)`. | ||
- `prepare(config, next)` - initializes additional engine state. | ||
The `config` object is the engine configuration object allowing updates to be made. | ||
This is useful for engines like Nunjucks that rely on additional state for rendering. | ||
`next` has the signature `function(err)`. | ||
- `registerPartial(name, src)` - registers a partial for use during template rendering. | ||
The `name` is the partial path that templates should use to reference the partial and | ||
`src` is the uncompiled template string for the partial. | ||
- `registerHelper(name, helper)` - registers a helper for use during template rendering. | ||
The `name` is the name that templates should use to reference the helper and `helper` | ||
is the function that will be invoked when the helper is called. | ||
- any of the `views` options listed below (except `defaultExtension`) to override the | ||
defaults for a specific engine. | ||
- `defaultExtension` - defines the default filename extension to append to template names when | ||
multiple engines are configured and not explicit extension is provided for a given template. | ||
No default value. | ||
- `path` - the root file path used to resolve and load the templates identified when calling | ||
[`reply.view()`](https://github.com/hapijs/hapi/blob/master/API.md#replyviewtemplate-context-options). | ||
Defaults to current working directory. | ||
- `partialsPath` - the root file path where partials are located. Partials are small segments | ||
of template code that can be nested and reused throughout other templates. Defaults to no | ||
partials support (empty path). | ||
- `helpersPath` - the directory path where helpers are located. Helpers are functions used | ||
within templates to perform transformations and other data manipulations using the template | ||
context or other inputs. Each '.js' file in the helpers directory is loaded and the file name | ||
is used as the helper name. The files must export a single method with the signature | ||
`function(context)` and return a string. Sub-folders are not supported and are ignored. | ||
Defaults to no helpers support (empty path). Note that jade does not support loading helpers | ||
this way. | ||
- `relativeTo` - a base path used as prefix for `path` and `partialsPath`. No default. | ||
- `layout` - if set to `true` or a layout filename, layout support is enabled. A layout is a | ||
single template file used as the parent template for other view templates in the same engine. | ||
If `true`, the layout template name must be 'layout.ext' where 'ext' is the engine's | ||
extension. Otherwise, the provided filename is suffixed with the engine's extension and | ||
loaded. Disable `layout` when using Jade as it will handle including any layout files | ||
independently. Defaults to `false`. | ||
- `layoutPath` - the root file path where layout templates are located (using the `relativeTo` | ||
prefix if present). Defaults to `path`. | ||
- `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 `'utf8'`. | ||
- `isCached` - if set to `false`, templates will not be cached (thus will be read from file on | ||
every use). Defaults to `true`. | ||
- `allowAbsolutePaths` - if set to `true`, allows absolute template paths passed to | ||
[`reply.view()`](https://github.com/hapijs/hapi/blob/master/API.md#replyviewtemplate-context-options). | ||
Defaults to `false`. | ||
- `allowInsecureAccess` - if set to `true`, allows template paths passed to | ||
[`reply.view()`](https://github.com/hapijs/hapi/blob/master/API.md#replyviewtemplate-context-options) | ||
to contain '../'. Defaults to `false`. | ||
- `compileOptions` - options object passed to the engine's compile function. Defaults to empty | ||
options `{}`. | ||
- `runtimeOptions` - options object passed to the returned function from the compile operation. | ||
Defaults to empty options `{}`. | ||
- `contentType` - the content type of the engine results. Defaults to `'text/html'`. | ||
- `compileMode` - specify whether the engine `compile()` method is `'sync'` or `'async'`. | ||
Defaults to `'sync'`. | ||
- `context` - a global context used with all templates. The global context option can be either | ||
an object or a function that takes no arguments and returns a context object. When rendering | ||
views, the global context will be merged with any context object specified on the handler or | ||
using [`reply.view()`](https://github.com/hapijs/hapi/blob/master/API.md#replyviewtemplate-context-options). | ||
When multiple context objects are used, values from the global context always have lowest precedence. | ||
When [`server.views()`](https://github.com/hapijs/hapi/blob/master/API.md#serverviewsoptions) is called within a | ||
plugin, the views manager is only available to [plugins](https://github.com/hapijs/hapi/blob/master/API.md#plugins) | ||
methods. | ||
### `server.render(template, context, [options], callback)` | ||
Utilizes the server views manager to render a template where: | ||
- `template` - the template filename and path, relative to the views manager templates path (`path` | ||
or `relativeTo`). | ||
- `context` - optional object used by the template to render context-specific result. Defaults to | ||
no context (`{}`). | ||
- `options` - optional object used to override the views manager configuration. | ||
- `callback` - the callback function with signature `function (err, rendered, config)` where: | ||
- `err` - the rendering error if any. | ||
- `rendered` - the result view string. | ||
- `config` - the configuration used to render the template. | ||
```js | ||
var Hapi = require('hapi'); | ||
var server = new Hapi.Server(); | ||
server.connection({ port: 80 }); | ||
server.views({ | ||
engines: { html: require('handlebars') }, | ||
path: __dirname + '/templates' | ||
}); | ||
var context = { | ||
title: 'Views Example', | ||
message: 'Hello, World' | ||
}; | ||
server.render('hello', context, function (err, rendered, config) { | ||
console.log(rendered); | ||
}); | ||
``` | ||
### `reply.view(template, [context, [options]])` | ||
Concludes the handler activity by returning control over to the router with a templatized view | ||
response where: | ||
- `template` - the template filename and path, relative to the templates path configured via the | ||
server views manager. | ||
- `context` - optional object used by the template to render context-specific result. Defaults to | ||
no context `{}`. | ||
- `options` - optional object used to override the server's views manager configuration for this | ||
response. Cannot override `isCached`, `partialsPath`, or `helpersPath` which are only loaded at | ||
initialization. | ||
Returns a [response object](https://github.com/hapijs/hapi/blob/master/API.md#response-object). | ||
The [response flow control rules](https://github.com/hapijs/hapi/blob/master/API.md#flow-control) apply. | ||
```js | ||
var Hapi = require('hapi'); | ||
var server = new Hapi.Server(); | ||
server.connection({ port: 80 }); | ||
server.views({ | ||
engines: { html: require('handlebars') }, | ||
path: __dirname + '/templates' | ||
}); | ||
var handler = function (request, reply) { | ||
var context = { | ||
title: 'Views Example', | ||
message: 'Hello, World' | ||
}; | ||
return reply.view('hello', context); | ||
}; | ||
server.route({ method: 'GET', path: '/', handler: handler }); | ||
``` | ||
**templates/hello.html** | ||
```html | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>{{title}}</title> | ||
</head> | ||
<body> | ||
<div> | ||
<h1>{{message}}</h1> | ||
</div> | ||
</body> | ||
</html> | ||
``` | ||
### The `view` handler | ||
The `view` handler can be used with routes registered in the same realm as the view manager. The | ||
handler takes an `options` parameter that can be either a string or an object. When the `options` | ||
parameter is a string, it should be the filename and path of the template relative to the templates | ||
path configured via the views manager. When the `options` parameter is an object, it may have the | ||
following keys: | ||
- `template` - the template filename and path, relative to the templates path configured via the | ||
server views manager. | ||
- `context` - optional object used by the template to render context-specific result. Defaults to | ||
no context `{}`. | ||
- `options` - optional object used to override the server's views manager configuration for this | ||
response. Cannot override `isCached`, `partialsPath`, or `helpersPath` which are only loaded at | ||
initialization. | ||
The rendering `context` contains the `params`, `payload`, `query`, and `pre` values from the | ||
[request](https://github.com/hapijs/hapi/blob/master/API.md#request-properties) by default (these | ||
can be overriden by values explicitly set via the `options`). | ||
```js | ||
var Hapi = require('hapi'); | ||
var server = new Hapi.Server(); | ||
server.connection({ port: 80 }); | ||
server.views({ | ||
engines: { html: require('handlebars') }, | ||
path: __dirname + '/templates' | ||
}); | ||
server.route({ | ||
method: 'GET', | ||
path: '/', | ||
handler: { | ||
view: { | ||
template: 'hello', | ||
context: { | ||
title: 'Views Example', | ||
message: 'Hello, World' | ||
} | ||
} | ||
} | ||
}); | ||
``` |
@@ -0,11 +1,12 @@ | ||
'use strict'; | ||
// Load modules | ||
var Path = require('path'); | ||
var Code = require('code'); | ||
var Handlebars = require('handlebars'); | ||
var Hapi = require('hapi'); | ||
var Hoek = require('hoek'); | ||
var Jade = require('jade'); | ||
var Lab = require('lab'); | ||
var Vision = require('..'); | ||
const Path = require('path'); | ||
const Code = require('code'); | ||
const Handlebars = require('handlebars'); | ||
const Hapi = require('hapi'); | ||
const Hoek = require('hoek'); | ||
const Jade = require('jade'); | ||
const Lab = require('lab'); | ||
const Vision = require('..'); | ||
@@ -15,3 +16,3 @@ | ||
var internals = {}; | ||
const internals = {}; | ||
@@ -21,13 +22,13 @@ | ||
var lab = exports.lab = Lab.script(); | ||
var describe = lab.describe; | ||
var it = lab.it; | ||
var expect = Code.expect; | ||
const lab = exports.lab = Lab.script(); | ||
const describe = lab.describe; | ||
const it = lab.it; | ||
const expect = Code.expect; | ||
describe('handler()', function () { | ||
describe('handler()', () => { | ||
it('handles routes to views', function (done) { | ||
it('handles routes to views', (done) => { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
@@ -44,3 +45,3 @@ server.register(Vision, Hoek.ignore); | ||
url: '/hello' | ||
}, function (res) { | ||
}, (res) => { | ||
@@ -52,5 +53,5 @@ expect(res.result).to.contain('hello'); | ||
it('handles custom context', function (done) { | ||
it('handles custom context', (done) => { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
@@ -64,3 +65,3 @@ server.register(Vision, Hoek.ignore); | ||
server.route({ method: 'GET', path: '/', handler: { view: { template: 'valid/index', context: { message: 'heyloo' } } } }); | ||
server.inject('/', function (res) { | ||
server.inject('/', (res) => { | ||
@@ -72,5 +73,5 @@ expect(res.result).to.contain('heyloo'); | ||
it('handles custom options', function (done) { | ||
it('handles custom options', (done) => { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
@@ -85,3 +86,3 @@ server.register(Vision, Hoek.ignore); | ||
server.route({ method: 'GET', path: '/', handler: { view: { template: 'valid/options', options: { layout: 'elsewhere' } } } }); | ||
server.inject('/', function (res) { | ||
server.inject('/', (res) => { | ||
@@ -93,5 +94,5 @@ expect(res.result).to.contain('+hello'); | ||
it('includes prerequisites in the default view context', function (done) { | ||
it('includes prerequisites in the default view context', (done) => { | ||
var pre = function (request, reply) { | ||
const pre = function (request, reply) { | ||
@@ -101,3 +102,3 @@ reply('PreHello'); | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
@@ -123,3 +124,3 @@ server.register(Vision, Hoek.ignore); | ||
server.inject('/', function (res) { | ||
server.inject('/', (res) => { | ||
@@ -131,5 +132,5 @@ expect(res.result).to.contain('PreHello'); | ||
it('handles both custom and default contexts', function (done) { | ||
it('handles both custom and default contexts', (done) => { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
@@ -143,3 +144,3 @@ server.register(Vision, Hoek.ignore); | ||
server.route({ method: 'GET', path: '/', handler: { view: { template: 'valid/testContext', context: { message: 'heyloo' } } } }); | ||
server.inject('/?test=yes', function (res) { | ||
server.inject('/?test=yes', (res) => { | ||
@@ -152,5 +153,5 @@ expect(res.result).to.contain('heyloo'); | ||
it('overrides default contexts when provided with context of same name', function (done) { | ||
it('overrides default contexts when provided with context of same name', (done) => { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
@@ -164,3 +165,3 @@ server.register(Vision, Hoek.ignore); | ||
server.route({ method: 'GET', path: '/', handler: { view: { template: 'valid/testContext', context: { message: 'heyloo', query: { test: 'no' } } } } }); | ||
server.inject('/?test=yes', function (res) { | ||
server.inject('/?test=yes', (res) => { | ||
@@ -173,5 +174,5 @@ expect(res.result).to.contain('heyloo'); | ||
it('handles a global context', function (done) { | ||
it('handles a global context', (done) => { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
@@ -188,3 +189,3 @@ server.register(Vision, Hoek.ignore); | ||
server.route({ method: 'GET', path: '/', handler: { view: { template: 'valid/testContext' } } }); | ||
server.inject('/', function (res) { | ||
server.inject('/', (res) => { | ||
@@ -197,5 +198,5 @@ expect(res.result).to.contain('<h1></h1>'); | ||
it('overrides the global context with the default handler context', function (done) { | ||
it('overrides the global context with the default handler context', (done) => { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
@@ -216,3 +217,3 @@ server.register(Vision, Hoek.ignore); | ||
server.route({ method: 'GET', path: '/', handler: { view: { template: 'valid/testContext' } } }); | ||
server.inject('/?test=yes', function (res) { | ||
server.inject('/?test=yes', (res) => { | ||
@@ -225,5 +226,5 @@ expect(res.result).to.contain('<h1>yes</h1>'); | ||
it('overrides the global and default contexts with a custom handler context', function (done) { | ||
it('overrides the global and default contexts with a custom handler context', (done) => { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
@@ -245,3 +246,3 @@ server.register(Vision, Hoek.ignore); | ||
server.route({ method: 'GET', path: '/', handler: { view: { template: 'valid/testContext', context: { message: 'override', query: { test: 'no' } } } } }); | ||
server.inject('/?test=yes', function (res) { | ||
server.inject('/?test=yes', (res) => { | ||
@@ -254,5 +255,5 @@ expect(res.result).to.contain('<h1>no</h1>'); | ||
it('throws on missing views', function (done) { | ||
it('throws on missing views', (done) => { | ||
var server = new Hapi.Server({ debug: false }); | ||
const server = new Hapi.Server({ debug: false }); | ||
server.register(Vision, Hoek.ignore); | ||
@@ -269,3 +270,3 @@ server.connection(); | ||
server.inject('/', function (res) { | ||
server.inject('/', (res) => { | ||
@@ -278,7 +279,7 @@ expect(res.statusCode).to.equal(500); | ||
describe('render()', function () { | ||
describe('render()', () => { | ||
it('renders view (root)', function (done) { | ||
it('renders view (root)', (done) => { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
@@ -292,3 +293,3 @@ server.register(Vision, Hoek.ignore); | ||
server.render('test', { title: 'test', message: 'Hapi' }, function (err, rendered, config) { | ||
server.render('test', { title: 'test', message: 'Hapi' }, (err, rendered, config) => { | ||
@@ -301,5 +302,5 @@ expect(rendered).to.exist(); | ||
it('renders view (root with options)', function (done) { | ||
it('renders view (root with options)', (done) => { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
@@ -312,3 +313,3 @@ server.register(Vision, Hoek.ignore); | ||
server.render('test', { title: 'test', message: 'Hapi' }, { path: Path.join(__dirname, '/templates/valid') }, function (err, rendered, config) { | ||
server.render('test', { title: 'test', message: 'Hapi' }, { path: Path.join(__dirname, '/templates/valid') }, (err, rendered, config) => { | ||
@@ -321,5 +322,5 @@ expect(rendered).to.exist(); | ||
it('renders view (plugin)', function (done) { | ||
it('renders view (plugin)', (done) => { | ||
var test = function (server, options, next) { | ||
const test = function (server, options, next) { | ||
@@ -331,3 +332,3 @@ server.views({ | ||
var view = server.render('test', { message: 'steve' }, function (err, rendered, config) { | ||
server.render('test', { message: 'steve' }, (err, rendered, config) => { | ||
@@ -351,10 +352,10 @@ server.route([ | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
server.register(Vision, Hoek.ignore); | ||
server.register(test, function (err) { | ||
server.register(test, (err) => { | ||
expect(err).to.not.exist(); | ||
server.inject('/view', function (res) { | ||
server.inject('/view', (res) => { | ||
@@ -367,7 +368,7 @@ expect(res.result).to.equal('<h1>steve</h1>'); | ||
it('renders view (plugin without views)', function (done) { | ||
it('renders view (plugin without views)', (done) => { | ||
var test = function (server, options, next) { | ||
const test = function (server, options, next) { | ||
var view = server.render('test', { message: 'steve' }, function (err, rendered, config) { | ||
server.render('test', { message: 'steve' }, (err, rendered, config) => { | ||
@@ -391,3 +392,3 @@ server.route([ | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
@@ -401,6 +402,6 @@ server.register(Vision, Hoek.ignore); | ||
server.register(test, function (err) { | ||
server.register(test, (err) => { | ||
expect(err).to.not.exist(); | ||
server.inject('/view', function (res) { | ||
server.inject('/view', (res) => { | ||
@@ -413,5 +414,5 @@ expect(res.result).to.equal('<h1>steve</h1>'); | ||
it('renders view (plugin with options)', function (done) { | ||
it('renders view (plugin with options)', (done) => { | ||
var test = function (server, options, next) { | ||
const test = function (server, options, next) { | ||
@@ -422,3 +423,3 @@ server.views({ | ||
var view = server.render('test', { message: 'steve' }, { relativeTo: Path.join(__dirname, '/templates/plugin') }, function (err, rendered, config) { | ||
server.render('test', { message: 'steve' }, { relativeTo: Path.join(__dirname, '/templates/plugin') }, (err, rendered, config) => { | ||
@@ -442,10 +443,10 @@ server.route([ | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
server.register(Vision, Hoek.ignore); | ||
server.register(test, function (err) { | ||
server.register(test, (err) => { | ||
expect(err).to.not.exist(); | ||
server.inject('/view', function (res) { | ||
server.inject('/view', (res) => { | ||
@@ -458,7 +459,7 @@ expect(res.result).to.equal('<h1>steve</h1>'); | ||
it('throws on missing views', function (done) { | ||
it('throws on missing views', (done) => { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.register(Vision, Hoek.ignore); | ||
expect(function () { | ||
expect(() => { | ||
@@ -470,5 +471,5 @@ server.render('test'); | ||
it('renders view (plugin request)', function (done) { | ||
it('renders view (plugin request)', (done) => { | ||
var test = function (server, options, next) { | ||
const test = function (server, options, next) { | ||
@@ -485,3 +486,3 @@ server.views({ | ||
request.render('test', { message: 'steve' }, function (err, rendered, config) { | ||
request.render('test', { message: 'steve' }, (err, rendered, config) => { | ||
@@ -500,10 +501,10 @@ return reply(rendered); | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
server.register(Vision, Hoek.ignore); | ||
server.register(test, function (err) { | ||
server.register(test, (err) => { | ||
expect(err).to.not.exist(); | ||
server.inject('/view', function (res) { | ||
server.inject('/view', (res) => { | ||
@@ -517,11 +518,11 @@ expect(res.result).to.equal('<h1>steve</h1>'); | ||
describe('views()', function () { | ||
describe('views()', () => { | ||
it('requires plugin with views', function (done) { | ||
it('requires plugin with views', (done) => { | ||
var test = function (server, options, next) { | ||
const test = function (server, options, next) { | ||
server.path(__dirname); | ||
var views = { | ||
const views = { | ||
engines: { 'html': Handlebars }, | ||
@@ -545,3 +546,3 @@ path: './templates/plugin' | ||
server.ext('onRequest', function (request, reply) { | ||
server.ext('onRequest', (request, reply) => { | ||
@@ -562,14 +563,14 @@ if (request.path === '/ext') { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
server.register(Vision, Hoek.ignore); | ||
server.register({ register: test, options: { message: 'viewing it' } }, function (err) { | ||
server.register({ register: test, options: { message: 'viewing it' } }, (err) => { | ||
expect(err).to.not.exist(); | ||
server.inject('/view', function (viewResponse) { | ||
server.inject('/view', (viewResponse) => { | ||
expect(viewResponse.result).to.equal('<h1>viewing it</h1>'); | ||
server.inject('/ext', function (extResponse) { | ||
server.inject('/ext', (extResponse) => { | ||
@@ -583,5 +584,5 @@ expect(extResponse.result).to.equal('<h1>grabbed</h1>'); | ||
it('requires plugin with views with specific relativeTo', function (done) { | ||
it('requires plugin with views with specific relativeTo', (done) => { | ||
var test = function (server, options, next) { | ||
const test = function (server, options, next) { | ||
@@ -609,10 +610,10 @@ server.views({ | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
server.register(Vision, Hoek.ignore); | ||
server.register(test, function (err) { | ||
server.register(test, (err) => { | ||
expect(err).to.not.exist(); | ||
server.inject('/view', function (res) { | ||
server.inject('/view', (res) => { | ||
@@ -625,5 +626,5 @@ expect(res.result).to.equal('<h1>steve</h1>'); | ||
it('defaults to server views', function (done) { | ||
it('defaults to server views', (done) => { | ||
var test = function (server, options, next) { | ||
const test = function (server, options, next) { | ||
@@ -646,3 +647,3 @@ server.route({ | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
@@ -653,3 +654,3 @@ server.register(Vision, Hoek.ignore); | ||
var views = { | ||
const views = { | ||
engines: { 'html': Handlebars }, | ||
@@ -661,6 +662,6 @@ path: './templates/plugin' | ||
server.register({ register: test, options: { message: 'viewing it' } }, function (err) { | ||
server.register({ register: test, options: { message: 'viewing it' } }, (err) => { | ||
expect(err).to.not.exist(); | ||
server.inject('/view', function (res) { | ||
server.inject('/view', (res) => { | ||
@@ -673,8 +674,8 @@ expect(res.result).to.equal('<h1>viewing it</h1>'); | ||
it('throws on multiple views', function (done) { | ||
it('throws on multiple views', (done) => { | ||
var server = new Hapi.Server(); | ||
const server = new Hapi.Server(); | ||
server.register(Vision, Hoek.ignore); | ||
server.views({ engines: { 'html': Handlebars } }); | ||
expect(function () { | ||
expect(() => { | ||
@@ -686,1 +687,52 @@ server.views({ engines: { 'html': Handlebars } }); | ||
}); | ||
describe('Plugin', () => { | ||
it('can be registered before connections', (done) => { | ||
const plugin = function (server, options, next) { | ||
server.dependency('vision'); | ||
server.connection(); | ||
next(); | ||
}; | ||
plugin.attributes = { | ||
connections: false, | ||
name: 'test' | ||
}; | ||
const server = new Hapi.Server(); | ||
server.register([Vision, plugin], Hoek.ignore); | ||
expect(server.views).to.be.a.function(); | ||
server.initialize((err) => { | ||
expect(err).to.not.exist(); | ||
server.stop(done); | ||
}); | ||
}); | ||
it('only registers once', (done) => { | ||
const one = function (server, options, next) { | ||
server.register(Vision, next); | ||
}; | ||
const two = function (server, options, next) { | ||
server.register(Vision, next); | ||
}; | ||
one.attributes = { name: 'one' }; | ||
two.attributes = { name: 'two' }; | ||
const server = new Hapi.Server(); | ||
server.register([one, two], (err) => { | ||
expect(err).to.not.exist(); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
exports = module.exports = 'not a function'; |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
exports = module.exports = function (context) { | ||
@@ -2,0 +4,0 @@ |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
exports = module.exports = function (context) { | ||
@@ -2,0 +4,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
156591
103
3161
5
0
13
234
+ Addedboom@3.2.2(transitive)
+ Addedhoek@3.0.44.3.1(transitive)
+ Addeditems@2.2.1(transitive)
- Removedboom@2.10.1(transitive)
- Removeditems@1.1.1(transitive)
Updatedboom@3.x.x
Updatedhoek@3.x.x
Updateditems@2.x.x