Giter Club home page Giter Club logo

koa-hbs's Introduction

koa-hbs Build Status

Handlebars templates for Koa

ย 

๐Ÿš€ ย  Are you ready to tackle ES6 and hone your JavaScript Skills? ย  ๐Ÿš€
Check out these outstanding ES6 courses by @wesbos


Usage

koa-hbs is middleware. We stash an instance of koa-hbs for you in the library so you don't have to manage it separately. Configure the default instance by passing an options hash to #middleware. To render a template then, just yield this.render('templateName');. Here's a basic app demonstrating all that:

var koa = require('koa');
var hbs = require('koa-hbs');

var app = koa();

// koa-hbs is middleware. `use` it before you want to render a view
app.use(hbs.middleware({
  viewPath: __dirname + '/views'
}));

// Render is attached to the koa context. Call `this.render` in your middleware
// to attach rendered html to the koa response body.
app.use(function *() {
  yield this.render('main', {title: 'koa-hbs'});
})

app.listen(3000);

After a template has been rendered, the template function is cached. #render accepts two arguments - the template to render, and an object containing local variables to be inserted into the template. The result is assigned to Koa's this.response.body.

Options

The plan for koa-hbs is to offer identical functionality as express-hbs (eventaully). These options are supported now.

viewPath required

Type: Array|String
Full path from which to load templates

handlebars

Type:Object:Handlebars
Pass your own instance of handlebars

templateOptions

Type: Object
Hash of handlebars options to pass to template()

extname

Type:String
Alter the default template extension (default: '.hbs')

partialsPath

Type:Array|String
Full path to partials directory

defaultLayout

Type:String
Name of the default layout

layoutsPath

Type:String
Full path to layouts directory

contentHelperName

Type:String
Alter contentFor helper name

blockHelperName

Type:String
Alter block helper name

disableCache

Type:Boolean
Disable template caching

Registering Helpers

Helpers are registered using the #registerHelper method. Here is an example using the default instance (helper stolen from official Handlebars docs:

hbs = require('koa-hbs');

hbs.registerHelper('link', function(text, url) {
  text = hbs.Utils.escapeExpression(text);
  url  = hbs.Utils.escapeExpression(url);

  var result = '<a href="' + url + '">' + text + '</a>';

  return new hbs.SafeString(result);
});

Your helper is then accessible in all views by using, {{link "Google" "http://google.com"}}

The registerHelper, Utils, and SafeString methods all proxy to an internal Handlebars instance. If passing an alternative instance of Handlebars to the middleware configurator, make sure to do so before registering helpers via the koa-hbs proxy of the above functions, or just register your helpers directly via your Handlebars instance.

You can also access the current Koa context in your helper. If you want to have a helper that outputs the current URL, you could write a helper like the following and call it in any template as {{requestURL}}.

hbs.registerHelper('requestURL', function() {
  var url = hbs.templateOptions.data.koa.request.url;
  return url;
});

Registering Partials

The simple way to register partials is to stick them all in a directory, and pass the partialsPath option when generating the middleware. Say your views are in ./views, and your partials are in ./views/partials. Configuring the middleware via

app.use(hbs.middleware({
  viewPath: __dirname + '/views',
  partialsPath: __dirname + '/views/partials'
}));

will cause them to be automatically registered. Alternatively, you may register partials one at a time by calling hbs.registerPartial which proxies to the cached handlebars #registerPartial method.

Layouts

Passing defaultLayout with the a layout name will cause all templates to be inserted into the {{{body}}} expression of the layout. This might look like the following.

<!DOCTYPE html>
<html>
<head>
  <title>{{title}}</title>
</head>
<body>
  {{{body}}}
</body>
</html>

In addition to, or alternatively, you may specify a layout to render a template into. Simply specify {{!< layoutName }} somewhere in your template. koa-hbs will load your layout from layoutsPath if defined, or from viewPath otherwise. If viewPath is set to an Array of paths, the first path in the array will be assumed to contain the layout named.

At this time, only a single content block ({{{body}}}) is supported.

Overriding Layouts using Locals

As of version 0.9.0, it's possible to override the layout used for rendering, using locals. For example:

router.get('/', function *() {
  yield this.render('foo', {
    layout: 'bar'
  });
 });

See the tests for more.

Block content

Reserve areas in a layout by using the block helper like so.

{{#block "sidebar"}}
  <!-- default content for the sidebar block -->
{{/block}}

Then in a template, use the contentFor helper to render content into the block.

{{#contentFor "sidebar"}}
  <aside>
    <h2>{{sidebarTitleLocal}}</h2>
    <p>{{sidebarContentLocal}}</p>
  </aside>
{{/contentFor}}

Disable Template Caching

To disable the caching of templates and partials, use the disableCache option. Set this option to true to disable caching. Default is false. Remember to set this option to false for production environments, or performance could be impacted!

Locals

Application local variables ([this.state](https://github.com/koajs/koa/blob/master/docs/api/context.md#ctxstate)) are provided to all templates rendered within the application.

app.use(function *(next) {
  this.state.title = 'My App';
  this.state.email = '[email protected]';
  yield next;
});

The state object is a JavaScript Object. The properties added to it will be exposed as local variables within your views.

<title>{{title}}</title>

<p>Contact : {{email}}</p>

Koa2

Koa2 is supported via the @next module version. It is considered experimental and requires Node v7 or higher. You can obtain this version by running:

npm install koa-hbs@next --save

For information on using this version, please read the branch's README. If using a version of node older than v7.6, we recommend using harmonica to enable the --harmony flags, which activates native async/await support.

If you'd rather not use an experimental version, or you need to use an older version of Node, you can reference this example repo that demonstrates how to use koa-hbs with Koa2: koa-hbs-koa2-howto

Credit to @chrisveness for the initial investigation.

Example

You can run the included example via npm install koa and node --harmony app.js from the example folder.

Unsupported Features

Here's a few things koa-hbs does not plan to support unless someone can provide really compelling justification.

Async Helpers

koa-hbs does not support asynchronous helpers. No, really - just load your data before rendering a view. This helps on performance and separation of concerns in your app.

Handlebars Version

As of [email protected], the version of the Handlebars dependency bundled with this module has been updated to 4.0.x. If this causes conflicts for your project, you may pass your own instance of Handlebars to the module, or downgrade to the last 0.8.x version.

Credits

Functionality and code were inspired/taken from express-hbs. Many thanks to @jwilm for authoring this middleware.

koa-hbs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

koa-hbs's Issues

Vulnerabilities reported by nsp

Hi Guys

Ive been running nsp on some of my apps and nsp is reporting 3 vulnerabilities in the dependencies

(+) 3 vulnerabilities found
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚               โ”‚ Quoteless Attributes in Templates can lead to Content Injection                                                                    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Name          โ”‚ handlebars                                                                                                                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Installed     โ”‚ 2.0.0                                                                                                                              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Vulnerable    โ”‚ <4.0.0                                                                                                                             โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Patched       โ”‚ >=4.0.0                                                                                                                            โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Path          โ”‚ [email protected] > [email protected] > [email protected]                                                                                โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ More Info     โ”‚ https://nodesecurity.io/advisories/61                                                                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚               โ”‚ Regular Expression Denial of Service                                                                                               โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Name          โ”‚ uglify-js                                                                                                                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Installed     โ”‚ 2.3.6                                                                                                                              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Vulnerable    โ”‚ <2.6.0                                                                                                                             โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Patched       โ”‚ >=2.6.0                                                                                                                            โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Path          โ”‚ [email protected] > [email protected] > [email protected] > [email protected]                                                              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ More Info     โ”‚ https://nodesecurity.io/advisories/48                                                                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚               โ”‚ Incorrect Handling of Non-Boolean Comparisons During Minification                                                                  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Name          โ”‚ uglify-js                                                                                                                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Installed     โ”‚ 2.3.6                                                                                                                              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Vulnerable    โ”‚ <= 2.4.23                                                                                                                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Patched       โ”‚ >= 2.4.24                                                                                                                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Path          โ”‚ [email protected] > [email protected] > [email protected] > [email protected]                                                              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ More Info     โ”‚ https://nodesecurity.io/advisories/39                                                                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

Problem when mounting app on another app

Hi, i have two app App1 and App2 . App1 is my startup application . App2 have some handlebars view. but when i mount App2 on App1 with koa-mount middleware these problem happen :

  1. When start the application and try to load project in error i get this error :

    Error: ENOENT, open 'g:\NAP\Client\Applications\AutenticationUI\views\index.hbs'

  2. If i create index.hbs and mount on App1 I see index.hbs on localhost:3000 but cant see other route and say not found

Error handling for missing templates

#41 introduced error handling that doesn't utilize the preferred koa error mechanism of simply throwing. Add a MissingTemplateError class and throw it when the renderer fails to find a template.

Implement async helpers

The API for this should look something like

hbs.registerAsyncHelper('helperName', function *() {
  /* generator code */
});

koa-hbs has order dependency when used with koa-router

Hi, jwilm

I use koa-hbs(0.4.4) in koa(0.5.5)

app.use(middlewares.bodyparser());
app.use(middlewares.jsonp());
app.use(middlewares.router(app));
app.use(middlewares.compress());
app.use(hbs.middleware({
    viewPath: __dirname + '/views',
    partialsPath: __dirname + '/views/partials',
    layoutsPath: __dirname + '/views/layouts'
}));

// init routes
app.get('/', function*() {
     this.render('index', {title: 'test'});
});

//run app
app.listen(3000);
console.log('listening on port 3000');

when I vist localhost:3000,I found the error

TypeError: Object #<Object> has no method 'render'

but app.use is well

app.use(hbs.middleware({
    viewPath: __dirname + '/views',
    partialsPath: __dirname + '/views/partials',
    layoutsPath: __dirname + '/views/layouts'
}));

//// init routes
//app.get('/', function*() {
//     this.render('index', {title: 'test'});
//});

app.use(function*(){
   yield this.render('index', {title: 'test'});
});

Mising '.' in index.js, line 344

It makes unable to render templates on some circumstances
As far as i can see this:
var tplPath = path.join(viewPath, tpl + this.extname);
should be changed to this
var tplPath = path.join(viewPath, tpl + '.' +this.extname);

No idea of colateral implications, but it's disallowing me to use koa-hbs

Unable to install using npm

npm install koa-hbs

Following are the logs that i have received, while running the above command.

540 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "koa-hbs"
541 verbose node v8.3.0
542 verbose npm  v5.3.0
543 error path /Users/XAM/liimex/portfolio/node_modules/sqlite3/node_modules/node-pre-gyp/node_modules/npmlog/node_modules/are-we-there-yet/node_modules/delegates
544 error code ENOENT
545 error errno -2
546 error syscall rename
547 error enoent ENOENT: no such file or directory, rename '/Users/XAM/liimex/portfolio/node_modules/sqlite3/node_modules/node-pre-gyp/node_modules/npmlog/node_modules/are-we-there-yet/node_modules/delegates' -> '/Users/XAM/liimex/portfolio/node_modules/sqlite3/node_modules/node-pre-gyp/node_modules/npmlog/node_modules/are-we-there-yet/node_modules/.delegates.DELETE'
548 error enoent This is related to npm not being able to find a file.
549 verbose exit [ -2, true ]

RangeError: Maximum call stack size exceeded

Hello guys, I`m having one problem and i dont know what is it..

I`m using mongoose to fetch an array of posts to render my page.

loadPost : function *() {
      var posts = yield Post.find({url: this.params.post}).exec();

    yield this.render('blog/index', {
        'posts' : posts
    });
}

But, when i execute this code occurred this error

RangeError: Maximum call stack size exceeded
    at String.match (native)
    at typeOf (/Users/victorjussiani/Developer/Node.js/kaizen-website/node_modules/koa-hbs/node_modules/merge/merge.js:67:36)
    at clone (/Users/victorjussiani/Developer/Node.js/kaizen-website/node_modules/koa-hbs/node_modules/merge/merge.js:39:11)
    at clone (/Users/victorjussiani/Developer/Node.js/kaizen-website/node_modules/koa-hbs/node_modules/merge/merge.js:57:21)
    at clone (/Users/victorjussiani/Developer/Node.js/kaizen-website/node_modules/koa-hbs/node_modules/merge/merge.js:57:21)
    at clone (/Users/victorjussiani/Developer/Node.js/kaizen-website/node_modules/koa-hbs/node_modules/merge/merge.js:49:21)
    at clone (/Users/victorjussiani/Developer/Node.js/kaizen-website/node_modules/koa-hbs/node_modules/merge/merge.js:57:21)
    at clone (/Users/victorjussiani/Developer/Node.js/kaizen-website/node_modules/koa-hbs/node_modules/merge/merge.js:57:21)
    at clone (/Users/victorjussiani/Developer/Node.js/kaizen-website/node_modules/koa-hbs/node_modules/merge/merge.js:49:21)
    at clone (/Users/victorjussiani/Developer/Node.js/kaizen-website/node_modules/koa-hbs/node_modules/merge/merge.js:57:21)

Sorry for my english, if someone can help me =D

Request: Multiple Partials Paths

While specifying the partials path and preloading of partials is an asset, being limited to only one partials directory is... limiting.

I'd like to see the partialsPath property of config accept an array of paths from which to load partials.

support use of index.hbs for views

Assuming the following folder structure:

/views
  /home
    - index.hbs
    - home.css
  /contact
    - index.hbs
    - contact.css

It should be possible to render a view by calling context.render('home'). koa-hbs should look for an index.hbs file in the /home folder, and use that template if found.

Currently, it is only possible to render a view with the above folder structure by using context.render('home/index').

path.join() doesn't allow array parameter in Node 6

Related to this: nodejs/node#1215

koa-hbs converts user given viewPath to an array if it's a string:

if (!Array.isArray(this.viewPath)) {
  this.viewPath = [this.viewPath];
}

Then in getLayoutPath(), if layoutsPath is not defined, this.viewPath is given as a parameter to path.join. Which in latest Node leads to:

TypeError: Path must be a string. Received [ '/Users/ilkkao/git/mas/server/views' ]
    at assertPath (path.js:7:11)
    at Object.join (path.js:1213:7)
    at Hbs.getLayoutPath (/Users/ilkkao/git/mas/node_modules/koa-hbs/index.js:219:15)

https://github.com/gilt/koa-hbs/blob/master/index.js#L219 line seems problematic. It doesn't do the right thing if the viewPath is an array even with node <6 I think. Older node versions return a comma separated list of paths. That will lead to file not found.

Registering Partials in readme missing text?

The last sentence in the readme section of Registering Partials seems to end abruptly with Configuring the middleware as. Not a big deal but just thought I'd bring it up. Thanks for the plugin!

Release Next as Latest

This is a checklist for the tasks that need to be completed to release koa-hbs@next as koa-hbs@latest, and deprecate 0.9.0.

  • Remove gulp and convert task runner to use NPM scripts
  • Update mocha
  • Refactor using Node 8/9 feature sets (object destructuring, etc)
  • Leverage babel and babel-preset-env to compile dist file targeting Node 6
  • Resolve #70
  • Update README

We're welcoming anyone that would like to contribute pull requests to satisfy this list. If [you] have other suggestions for improvements for 1.0.0, please do share them.

Templates and partials are not cached

I'm not sure if koa-hbs package is maintaned, but I'll give it a shot.

From the presence of disableCache in docs, it looks like all views and partials are cached. But from mye experiments it looks like it is not true.

I want to implement HTML minification. To achieve this task, I've created a Handlebars helper that runs html-minifier over passed content.

const htmlMinifier = require('html-minifier')

hbs.registerHelper('minify', (context, options) => {
  const minified = htmlMinifier.minify(options.fn(context), {
    collapseWhitespace: true,
    removeComments: true,
    removeEmptyAttributes: false, // some <img> tags require alt=""
    minifyCSS: true,
    minifyJS: {
      compress: false, // disable compress to only delete whitespace
      mangle: true, // process whitespace
      warnings: true,
    },
  })
  return new hbs.SafeString(minified)
})

Then I've wrapped this helper over one of my templates that is pulled into the {{{body}}} of default layout. Wrapping code is inside of the template file, not in default layout file.

{{#minify this}}
  {{!-- template code --}}
{{/minify}}

I look into the code and it is minified successfully.

However, when I've started to test how this implementation affects performance, I found out that it causes significant performance issues.

I've double checked and I have disableCache: false.
Without minification average request time is about 7.134ms.
With minification average request time is about 86.812ms, which is about 10 times slower.

I've experimented with minifying smaller pieces of code and it affects timings a lot. Bigger piece of code I minify, bigger request time I get. So, for me it is clear that caching is not working as expected.

Looks like caching is working as when I enable minification, it doesn't affect resulting code until I change disableCache to true and refresh page in browser. Then I see that code is minified and return disableCache to false.

But average request number still grows, so it leads me to thoughts that resulting HTML is taken from cache, while templates are still rendered every time in background.

koa-render support?

Hi,
great middleware! I was just wondering if is possible to make it koa-render compatible so it will be possible to use it as a rendering engine like jade or ejs with the possibility to use layouts and partials.

context.render ends up with 404

Hello,

This is probably an issue with misunderstanding how koa/koa-hbs work, but it may be useful for others when they have the same problem while learning.

TL;DR: instead of rendering my template, I get a 404 even though my route executes, see https://github.com/01binary/shopper/tree/HandlebarsInitial for a snapshot.

  • I setup koa middleware to look for templates in projectdir/dist with .html extension. I have layout.html file there (after executing yarn build):
hbs.middleware({
	viewPath: path.resolve(__dirname, '../../dist'),
	extname: '.html'
})
  • The template looks like this (it was generated by Html Webpack 2 plugin, react dom render goes in "mount"):
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>App</title>
	</head>
	<body>
		<div id="app">
			{{mount}}
		</div>
	<script type="text/javascript" src="scripts/vendor.js?83f7fa2dc8d8f8322d36"></script><script type="text/javascript" src="scripts/app.js?83f7fa2dc8d8f8322d36"></script></body>
</html>
  • I "use" the middleware as directed...
  • In my "/" route, I have:
route.get('/', async(context) => {
	console.log('about to render layout')
	await context.render('layout', { mount: render() });
})

When I navigate to my app, I see "about to render layout" logged out, but then it gets a 404:

  <-- GET /
about to render layout
  --> GET / 404 9,964ms -

Why doesn't the hbs middleare render? Does it send a 404 or does koa send a 404? I can't understand what's happening and how to debug it.

Thank you!

streaming compiled html.

With the new renderToNodeStream React moved ahead by providing way to reduce TTFB and First paint.

Webpack generates assets which are appended to .hbs file using HtmlWebpackPlugin. React generate HTML on server using renderToString which is appended to .hbs using koa-hbs and sent to client.

To switch from renderToString to renderToNodeStream we need to separate .hbs in two parts, above and below some handlebar expression where react appends streaming data using renderToNodeStream.

With the current documentation of koa-hbs I do not found a way to get compiled html and take care of streaming by self.

Please expose an API to get comiled HTML or add support for streaming HTML.

the viewPath maybe an array

the doc says:
viewPath: [required] Full path from which to load templates (Array|String)
when I set an array,it goes wrong:
TypeError: Path must be a string,
is it possible the viewPath an array,just like viewPath: ['./client/web','./client/web2'],

contentFor / block order dependency

I have a layout like:

<!DOCTYPE html>
<html>
<head>
  <title>Example title</title>
</head>
<body>
  <div id="sidebar">
    {{# block "sidebar" }}
      <!-- sidebar goes here -->
    {{/ block }}
  </div>
  {{{body}}}
</body>
</html>

with two partials, one in partials/sidebar.hbs:

{{# contentFor "sidebar" }}
    <nav>
        <ul class="sidebar-submenu">
            {{# block "sidebar-submenu" }}
                <!-- sidebar-submenu goes here -->
            {{/ block }}
        </ul>
    </nav>
</div>
{{/ contentFor }}

and one in partials/sidebar-submenu/submenu-item.hbs with contents:

{{> sidebar }}

{{# contentFor "sidebar-submenu" }}
    <li>List elem 1</li>
    <li>List elem 2</li>
{{/ contentFor }}

I then include this partial in one of the templates:

{{> sidebar-submenu/submenu-item }}

<div>The actual content</div>

The end result is that the first time someone visits the relevant page, the sidebar partial gets populated but the sidebar-submenu one doesn't (I still see the <!-- sidebar-submenu goes here --> comment instead of the content). After the second refresh it's all fine.

Restarting the server doesn't help.

koa 0.20.0, koa-hbs 0.7.0

Layout overrides

We've been using this middleware for a while now and it's worked out really well.

Unless there is already a preferred way of doing this in its current state, we wanted to add the following features:

  • ability to specify the layout on a render level (I know it can be done on the template, but that unfortunately won't work for us)
  • ability to render without a layout when a defaultLayout has been specified

I was able to figure out a way of doing this without modifying koa-hbs, but it's pretty hacky. In the interest of contributing for others to use, I'd be happy to put in a pull request with the changes specified above. If there is already a way of accomplishing the above that I may have missed, I'm more than open to that too.

Thanks!

Yield added to Generator Function Causes RangeError: stack size exceeded

I am trying to get back the response so that I can check it in my unit tests.

Once I added yield, it blew up. I'm using koa-controller as well.

module.exports = {
    find: function *(){
        var response = this;
        response.statusCode = 200;
        var foundData = null;

        //_gateway.find(function(foundData){
            if(!foundData || Object.keys(foundData).length === 0){
                response.body = null;
                response.statusCode = 204;
            }

            response.body = foundData;
            yield response;
        //});
    }
};

error:

RangeError: Maximum call stack size exceeded
at Object.objectToPromise (/node_modules/co/index.js:166:25)

Now if I change yield to yield { message: "test this" }; it's fine. So I wonder if it's because of the underlying source code of koa-controller middleware that's passing back the this koa context and when I try to yield it something funky is going on because koa-controller is probably doing other things in code.

Missing tags/releases in Github repo

I just noticed that there have been a number of publishes to NPM of this module without corresponding tags/releases added to the repo.

It's good to keep the tags up to date for comparison with the relevant npm version.

Best way to change layout at runtime?

Hey,

First off: Thanks for making koa-hbs, it is super awesome and fits my needs exactly. โญ

I am developing a site that has various themes in different layouts, and a different theme is used depending on what URL you hit.

I have this working:

  app.use(function *(next) {
    hbs.configure({
      defaultLayout: 'theme_' + (this.company.theme || 'simple'),
      viewPath: __dirname + '/views'
    });

    this.render = hbs.createRenderer();
    yield next;
  });

But I'm not sure the implications on creating a new renderer every request. Is this a legit technique? Seems like layout caching wouldn't work with this technique... maybe.

Is there a better way to specify the layout at runtime?

Unfortunately, I don't believe I can use the alternative layout syntax because the layout name is dynamic.

Thanks so much!

Docker + Digital Ocean

Just wanted to let you know, I had to downgrade my koa-hbs from 0.7.0 to 0.6.0. On Dokku via Digital Ocean, this.render would never respond in 0.7.0. Wasn't able to fully diagnose it.

disableCache doesn't apply to partials

Using the disableCache option works well for primary views, but isn't respected with regard to partials. While the overhead may be high, it'd be very useful for a development environment if those were given the same consideration as primary views when disableCache is used as an option.

Always "Not found"

Is there any way to throw errors? I get "Not found" for very simple settings ({ viewPath: __dirname + '/views' }), and I'm replicating as best as I can the tests, nothing does and I don't get it. :)

Note: the viewPath value exists, as fs.existsSync(options.viewPath) returns true.

Route Specific Helpers

Hey,

Im in the middle of writing a framework where I want to define route specific helpers. I.e if I am on / then the helper parse will do something, and if I'm in the route /test, then use a different helperparse does something else. My proposal is to add something like this:

this.render('foo', {
  layout: 'bar',
  helpers: {
    lowercase: function(word) {
      return word.toUpperCase();
    }
  }
});

Support: override layout?

I was looking through the code and didn't see a way to overwrite the layout for a render. Am I right about that? My problem is that my root page has a different layout (or no layout) than the rest of my pages. I was expecting something like

this.render('hero-page', {
  title: "Our Product",
  template: null
});

cache bug

koa.use(convert(hbs.middleware({
    extname: '.html',
    viewPath: ['./www/admin', './www/home'],
    layoutsPath: './www',
    partialsPath: ['./www/admin', './www/home'],
    disableCache: true
})));

koa.use(async(ctx, next) => {
    const render = ctx.render;
    ctx.render = async function _convertedRender() {
        return co.call(ctx, render.apply(ctx, arguments))
    }

    await next();
});

###render###

 if(ctx.query.type){
       ctx.state = {
             layout: 'admin/override'
       };
}

await ctx.render('index_index');

If I open the cache, view rendering not to come out, when I closed the cache, the view can render.

Rendering templates without outputting content

Hi, this is a great module but I'm having some issues trying to use it to render HTML for an HTML email without actually sending it down to the client. Here is what I'm doing now (which seems really hacky):

var output = {};
yield this.render.call(output, 'email/confirmation', {
    subject: 'Email Subject'
});
var html = output.body;

This works OK if I'm doing this from within a request - but if I want to sends emails for some other reason (e.g. as a cron job) I don't have a request context anymore - so no this.render. I know I could just use the base handlebars package, but then I don't think I get the cool block/layout stuff you've added in.

Is there something I am missing that would make this easier?

Thanks!

Koa v2

With Node.js v7.0.0 out (with V8 5.4), it's now possible to run Koa v2 using async/await natively, without Babel (albeit behind a --harmony flag).

Would you be able to make a new version of koa-hbs available which will work with Koa v2? (published @next).

(I've tried getting the current koa-hbs working with Koa v2 using koa-adapter, but haven't succeeded).

Option to register partials before first request

We have the need in our application to preload partials before the first request to the app is made. With how koa-hbs currently functions, the partials within the partialsPath property of the config aren't registered until the first request to the app is made. This makes any modification (or use of the partials through the same handlebars instance) before the request is complete problematic.

It would be great to have the option of instructing koa-hbs to register all partials (and even layouts/views) before the first request.

npm package out of date

We need the feature added in #24, but currently the npm package is still not updated, please publish new version, thx.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.