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

Add settings docs #283

Merged
merged 2 commits into from
Apr 12, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/plugins/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,33 @@ module.exports = {
fn: plugin
};
```

### using `settings`
```js
const plugin = ({ display, settings }) => {
const icon = require('[path-to-icon]/icon.png');

display({
icon: settings.icon ? icon : '',
title: `${settings.username}, you have been around for ${settings.age}`,
subtitle: `Favorite languages: ${settings.languages.join(',')}`,
})
}

module.exports = {
fn: plugin,
settings: {
username: { type: 'string' },
age: { type: 'number', defaultValue: 42 },
icon: { type: 'bool' },
languages: {
type: 'option',
description: 'Your favorite programming languages'
options: ['JavaScript', 'Haskell', 'Rust'],
multi: true,
createable: true,
}
}
}

```
21 changes: 21 additions & 0 deletions docs/plugins/plugin-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This plugin will write to console all changes in your search field of Cerebro ap
* `copyToClipboard` – `Function(text: String)`, copy text to clipboard;
* `replaceTerm` – `Function(text: String)`, replace text in main Cerebro input;
* `hideWindow` – `Function()`, hide main Cerebro window.
* `settings` - `Object`, contains user provided values of all specified settings keys;


Let's show something in results list:
Expand Down Expand Up @@ -149,3 +150,23 @@ Arguments: `message: Object` – object that you sent from `initializeAsync`
Use this function to receive data back from your `initializeAsync` function.

Check `initializeAsync` and `onMessage` [example](./examples.md#using-initializeasync-and-onmessage)

### `settings`
Type: `Object`

This object is used to specify settings that a plugin user can change. Each setting should include a `description` and a `type`. Other keys include:
* `label` - `String`, object key for the setting. also used to access it;
* `description` - `String`, description of the setting;
* `type` - `String`, used to decide element for rendering a setting:
* `string`
* `number`
* `bool`
* `option`
* `defaultValue` - `Any`, default value for the setting;
* `options` - `Array`, all possible options that can be selected by the user. applicable only for `option`;
* `multi` - `Bool`, allows user to select more than one option for `option` settings. applicable only for `option`;
* `createable` - `Bool`, allows user created options. applicable only for `option`;

Check `settings` [example](./examples.md#using-settings)

Look at [React Select](https://github.com/JedWatson/react-select) for more details on how the `option` type works.