Skip to content

Commit

Permalink
update example and README
Browse files Browse the repository at this point in the history
close #11
  • Loading branch information
zkochan committed Jul 9, 2016
1 parent 113993d commit 6f52190
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ additional information about the plugin, such as name and version.
A very simple plugin looks like:

```js
let myPlugin = {
register(app, options, next) {
next()
}
function myPlugin (app, options, next) {
next()
}

myPlugin.register.attributes = {
myPlugin.attributes = {
name: 'myPlugin',
version: '1.0.0',
}
Expand All @@ -42,13 +40,15 @@ myPlugin.register.attributes = {
Or when written as an external module:

```js
module.exports = function(app, options, next) {
function plugin (app, options, next) {
next()
}

module.exports.attributes = {
plugin.attributes = {
pkg: require('./package.json'),
}

module.exports = plugin
```

Note that in the first example, we set the `name` and `version` attributes specifically,
Expand Down Expand Up @@ -79,17 +79,17 @@ const remi = require('remi')
// load one plugin
let registrator = remi(app)
registrator
.register(require('myplugin'))
.register([{ register: require('myplugin') }])
.then(() => console.log('myplugin was successfully registered'))
.catch(err => console.error('Failed to load plugin:', err))

// load multiple plugins
registrator
.register([require('myplugin'), require('yourplugin')])
.register([{ register: require('myplugin') }, { register: require('yourplugin') }])
.catch(err => console.error('Failed to load plugin:', err))
```

To pass options to your plugin, we instead create an object with `register` and `options` keys, such as:
To pass options to your plugin, we create an object with `register` and `options` keys, such as:

```js
registrator.register({
Expand Down
4 changes: 3 additions & 1 deletion example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Hub.prototype.register = function (plugins) {
let hub = new Hub()
hub
.register([
require('./plugins/foo'),
{
register: require('./plugins/foo'),
},
{
register: require('./plugins/bar'),
options: { sayTimes: 4 }
Expand Down
6 changes: 4 additions & 2 deletions example/plugins/bar.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use strict'
module.exports = function (hub, options, next) {
function plugin (hub, options, next) {
for (let i = 0; i < options.sayTimes; i++) {
console.log('Foo says: ' + hub.fooSays)
}
next()
}

module.exports.attributes = {
plugin.attributes = {
name: 'bar',
version: '0.0.0'
}

module.exports = plugin
6 changes: 4 additions & 2 deletions example/plugins/foo.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
'use strict'
module.exports = function (hub, options, next) {
function plugin (hub, options, next) {
hub.root.fooSays = 'Hello world!'
next()
}

module.exports.attributes = {
plugin.attributes = {
name: 'foo',
version: '0.0.0'
}

module.exports = plugin

0 comments on commit 6f52190

Please sign in to comment.