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

ES6 style changes and node v4. #66

Merged
merged 2 commits into from Nov 4, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
@@ -1,7 +1,8 @@
language: node_js

node_js:
- "0.10"
- "4.0"
- "4"
- "5"
Copy link
Contributor

Choose a reason for hiding this comment

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

Drop the "". No need.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


sudo: false
34 changes: 17 additions & 17 deletions API.md
Expand Up @@ -113,11 +113,11 @@ Utilizes the server views manager to render a template where:
- `config` - the configuration used to render the template.

```js
var Hapi = require('hapi');
var server = new Hapi.Server();
const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({ port: 80 });

server.register(require('vision'), function (err) {
server.register(require('vision'), (err) => {

if (err) {
throw err;
Expand All @@ -128,12 +128,12 @@ server.register(require('vision'), function (err) {
path: __dirname + '/templates'
});

var context = {
const context = {
title: 'Views Example',
message: 'Hello, World'
};

server.render('hello', context, function (err, rendered, config) {
server.render('hello', context, (err, rendered, config) => {

console.log(rendered);
});
Expand All @@ -155,11 +155,11 @@ this point in the request lifecycle and the `request.render()` method will produ
[`server.render()`](#serverrendertemplate-context-options-callback) can.

```js
var Hapi = require('hapi');
var server = new Hapi.Server();
const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({ port: 80 });

server.register(require('vision'), function (err) {
server.register(require('vision'), (err) => {

if (err) {
throw err;
Expand All @@ -175,7 +175,7 @@ server.register(require('vision'), function (err) {
path: '/view',
handler: function (request, reply) {

request.render('test', { message: 'hello' }, function (err, rendered, config) {
request.render('test', { message: 'hello' }, (err, rendered, config) => {

return reply(rendered);
});
Expand Down Expand Up @@ -205,11 +205,11 @@ The rendering `context` contains the `params`, `payload`, `query`, and `pre` val
can be overriden by values explicitly set via the `options`).

```js
var Hapi = require('hapi');
var server = new Hapi.Server();
const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({ port: 80 });

server.register(require('vision'), function (err) {
server.register(require('vision'), (err) => {

if (err) {
throw err;
Expand Down Expand Up @@ -257,11 +257,11 @@ The generated response will have the `variety` property set to `view`.
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();
const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({ port: 80 });

server.register(require('vision'), function (err) {
server.register(require('vision'), (err) => {

if (err) {
throw err;
Expand All @@ -272,9 +272,9 @@ server.register(require('vision'), function (err) {
path: __dirname + '/templates'
});

var handler = function (request, reply) {
const handler = function (request, reply) {

var context = {
const context = {
title: 'Views Example',
message: 'Hello, World'
};
Expand Down
36 changes: 18 additions & 18 deletions README.md
Expand Up @@ -16,10 +16,10 @@ implementation for creating templated responses.
**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) => {

if (err) {
console.log("Failed to load vision.");
Expand All @@ -46,18 +46,18 @@ the following examples can be found in the [examples directory](./examples).
### EJS

```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) {

reply.view('index', {
title: 'examples/views/ejs/index.js | Hapi ' + request.server.version,
message: 'Index - Hello World!'
});
};

server.register(require('vision'), function (err) {
server.register(require('vision'), (err) => {

if (err) {
throw err;
Expand All @@ -76,18 +76,18 @@ server.register(require('vision'), function (err) {
### Handlebars

```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) {

reply.view('basic/index', {
title: 'examples/views/handlebars/basic.js | Hapi ' + request.server.version,
message: 'Hello World!'
});
};

server.register(require('vision'), function (err) {
server.register(require('vision'), (err) => {

if (err) {
throw err;
Expand All @@ -105,26 +105,26 @@ server.register(require('vision'), function (err) {
### Jade

```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) {

reply.view('index', {
title: 'examples/views/jade/index.js | Hapi ' + request.server.version,
message: 'Index - Hello World!'
});
};

var aboutHandler = function (request, reply) {
const aboutHandler = function (request, reply) {

reply.view('about', {
title: 'examples/views/jade/index.js | Hapi ' + request.server.version,
message: 'About - Hello World!'
});
};

server.register(require('vision'), function (err) {
server.register(require('vision'), (err) => {

if (err) {
throw err;
Expand All @@ -146,18 +146,18 @@ server.register(require('vision'), function (err) {
### Mustache

```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) {

reply.view('index', {
title: 'examples/views/mustache/index.js | Hapi ' + request.server.version,
message: 'Index - Hello World!'
});
};

server.register(require('vision'), function (err) {
server.register(require('vision'), (err) => {

if (err) {
throw err;
Expand Down Expand Up @@ -188,18 +188,18 @@ server.register(require('vision'), function (err) {
### Nunjucks

```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) {

reply.view('index', {
title: 'examples/views/nunjucks/index.js | Hapi ' + request.server.version,
message: 'Index - Hello World!'
});
};

server.register(require('vision'), function (err) {
server.register(require('vision'), (err) => {

if (err) {
throw err;
Expand Down
13 changes: 7 additions & 6 deletions examples/cms/pages.js
@@ -1,12 +1,13 @@
'use strict';
// Load modules

var Fs = require('fs');
var Path = require('path');
const Fs = require('fs');
const Path = require('path');


// Declare internals

var internals = {};
const internals = {};


internals.Pages = function (dirPath) {
Expand All @@ -19,8 +20,8 @@ internals.Pages = function (dirPath) {

internals.Pages.prototype.loadPagesIntoCache = function () {

var self = this;
Fs.readdirSync(this._dirPath).forEach(function (file) {
const self = this;
Fs.readdirSync(this._dirPath).forEach((file) => {

if (file[0] !== '.') {
self._cache[file] = self.loadPageFile(file);
Expand Down Expand Up @@ -54,7 +55,7 @@ internals.Pages.prototype.savePage = function (name, contents) {

internals.Pages.prototype.loadPageFile = function (file) {

var contents = Fs.readFileSync(Path.join(this._dirPath, file));
const contents = Fs.readFileSync(Path.join(this._dirPath, file));

return {
name: file,
Expand Down
29 changes: 15 additions & 14 deletions examples/cms/server.js
@@ -1,17 +1,18 @@
'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('../..');


// Declare internals

var internals = {};
const internals = {};


var view = function (viewName) {
const view = function (viewName) {

return function (request, reply) {

Expand All @@ -20,32 +21,32 @@ var view = function (viewName) {
};


var getPages = function (request, reply) {
const getPages = function (request, reply) {

return reply.view('index', { pages: Object.keys(Pages.getAll()), title: 'All pages' });
};


var getPage = function (request, reply) {
const getPage = function (request, reply) {

return reply.view('page', { page: Pages.getPage(request.params.page), title: request.params.page });
};


var createPage = function (request, reply) {
const createPage = function (request, reply) {

Pages.savePage(request.payload.name, request.payload.contents);
return reply.view('page', { page: Pages.getPage(request.payload.name), title: 'Create page' });
};


var showEditForm = function (request, reply) {
const showEditForm = function (request, reply) {

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) {

Pages.savePage(request.params.page, request.payload.contents);
return reply.view('page', { page: Pages.getPage(request.params.page), title: request.params.page });
Expand All @@ -54,9 +55,9 @@ var updatePage = function (request, reply) {

internals.main = function () {

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) => {

if (err) {
throw err;
Expand All @@ -75,7 +76,7 @@ internals.main = function () {
server.route({ method: 'POST', path: '/create', handler: createPage });
server.route({ method: 'GET', path: '/pages/{page}/edit', handler: showEditForm });
server.route({ method: 'POST', path: '/pages/{page}/edit', handler: updatePage });
server.start(function (err) {
server.start((err) => {

if (err) {
throw err;
Expand Down