EventedMind/iron-router — pull request #959 by zimme (2014-10-26 22:15:06+00:00)
Title: Add namespace to options

This PR is dependent on PR #958.

If #958 isn't merged this PR need to change it's lookupOption order
to not change expected behaviour.

This PR adds namespaced options to hooks making it possible to use

this.lookupOption('template', 'loading') inside hooks to lookup options defined as this

```js
Router.route('/', {
loading: {
template: 'loadingTemplate'
}
});
```

Example
```js
Router.hooks.test = function() {
console.log('test: ' + this.lookupOption('message', 'test'));
this.next();
};

Router.configure({
simpleHook: {
message: 'A simple before hook (gets overridden by options specified when adding hook)'
}
});

Router.onBeforeAction(function() {
console.log('simpleHook: ' + this.lookupOption('message', 'simpleHook'));
console.log('simpleHook: ' + this.lookupOption('name'));
this.next();
},
{
only: 'home',
namespace: 'simpleHook',
message: 'A simple before hook (default message)'
});

Router.onBeforeAction('test', {
message: 'Test hook message'
});

Router.route('/', {
name: 'home',
simpleHook: {
message: 'A simple before hook (overrides options specified when adding hook)'
}
});

// Don't know how this is working in the new version
// But before it wasn't good to try and override Router.configure
// options here. You would use a global ApplicationController instead of Router.configure
HomeController = RouteController.extend({
simpleHook: {
message: 'A simple before hook (overrides route options)'
}
});
```

The only caveat I can think of right now is that you can't use 'except', 'namespace' or 'only' as options for the hook as these are used for restricting where the hook runs and which namespace the hook options uses.