# Core Plugins

[![Build Status](https://travis-ci.org/nodewrite/nodewrite-core-plugins.svg?branch=master)](https://travis-ci.org/nodewrite/nodewrite-core-plugins)
[![CodeClimate](https://codeclimate.com/github/nodewrite/nodewrite-core-plugins/badges/gpa.svg)](https://codeclimate.com/github/nodewrite/nodewrite-core-plugins)
[![Coverage Status](https://coveralls.io/repos/github/nodewrite/nodewrite-core-plugins/badge.svg?branch=master)](https://coveralls.io/github/nodewrite/nodewrite-core-plugins?branch=master)
[![Dependency Status](https://gemnasium.com/badges/github.com/nodewrite/nodewrite-core-plugins.svg)](https://gemnasium.com/github.com/nodewrite/nodewrite-core-plugins)

Handles the registration of installed plugins.

## Installation
```shell
npm install nodewrite-core-plugins --save
```
> This is a core package and is installed by default.

## Usage
The file structure for a plugin:
```
.
├── /config
|   └── default.yml
├── /assets
├── /models
├── /public
├── /test
├── /views
|   ├── /helpers
|   ├── /layouts
|   └── /partials
├── README.md [required]
├── icon.png
├── index.js [required]
└── package.json [required]
```

## Helper Methods
* [`server.getPluginRegistry(callback)`](#servergetpluginregistrycallback)
* [`server.getPluginReadMe(name, callback)`](#servergetpluginreadmenamecallback)
* [`server.getPlugin(name, callback)`](#servergetpluginnamecallback)

### `server.getPluginRegistry(callback)`
Returns an array of installed plugin objects.
* `callback` - method to call with a signature of `function(error, plugins)`.
  * `error` - any error encountered while trying to read.
  * `plugins` - registry array of plugins.
```js
server.getPluginRegistry((error, plugins) => {
  if (error) throw error;
  const registry = plugins;
});
```
Resulting registry array:
```js
[
  {
    package: {
      name: "nodewrite-plugin-stripe",
      version: "1.0.0",
      description: "stripe plugin for nodewrite",
      // package.json ..
    },
    short: {
      name: "plugin-stripe",
      url: "/plugins/stripe",
    }
  },
  // etc ...
]
```

### `server.getPluginReadMe(name, callback)`
Returns contents of a plugin's `README.md` file.
* `name` - plugin name of package to read.
* `callback` - method to call with a signature of `function(error, source)`.
  * `error` - any error encountered while trying to read.
  * `source` - contents of plugin `README.md` file.
```js
server.getPluginReadMe('nodewrite-plugin-stripe', (error, source) => {
  if (error) throw error;
  const content = source;
});
```
Resulting content is the raw markdown:
```md
## Stripe Plugin
etc ...
```
### `server.getPlugin(name, callback)`
Returns a single plugin object from the installed plugins registry.
* `name` - plugin name of package to read.
* `callback` - method to call with a signature of `function(error, plugin)`.
  * `error` - any error encountered while trying to read.
  * `plugin` - registry object for plugin.
```js
server.getPlugin('nodewrite-plugin-stripe', (error, plugin) => {
  if (error) throw error;
  const registry = plugin;
});
```
Resulting plugin registry object:
```js
{
  package: {
    name: "nodewrite-plugin-stripe",
    version: "1.0.0",
    description: "stripe plugin for nodewrite",
    // package.json ..
  },
  short: {
    name: "plugin-stripe",
    url: "/plugins/stripe",
  }
}
```
## Getting Help

Open an issue on this repository!
