electron/docs/styleguide.md

234 строки
6.0 KiB
Markdown
Исходник Обычный вид История

2015-08-22 15:07:45 +03:00
# Electron Documentation Styleguide
2016-06-24 22:28:41 +03:00
These are the guidelines for writing Electron documentation.
2015-08-22 15:07:45 +03:00
2016-06-24 04:45:37 +03:00
## Titles
2015-08-22 15:07:45 +03:00
2016-06-24 22:40:55 +03:00
* Each page must have a single `#`-level title at the top.
* Chapters in the same page must have `##`-level titles.
* Sub-chapters need to increase the number of `#` in the title according to
their nesting depth.
* All words in the page's title must be capitalized, except for conjunctions
like "of" and "and" .
2016-06-24 22:40:55 +03:00
* Only the first word of a chapter title must be capitalized.
2016-06-24 04:45:37 +03:00
Using `Quick Start` as example:
```markdown
# Quick Start
...
## Main process
...
## Renderer process
...
## Run your app
2015-08-22 15:07:45 +03:00
2016-06-24 04:45:37 +03:00
...
### Run as a distribution
...
### Manually downloaded Electron binary
...
```
For API references, there are exceptions to this rule.
## Markdown rules
2017-11-24 13:13:57 +03:00
* Use `sh` instead of `cmd` in code blocks (due to the syntax highlighter).
2016-06-24 22:28:41 +03:00
* Lines should be wrapped at 80 columns.
* No nesting lists more than 2 levels (due to the markdown renderer).
2016-08-17 00:07:50 +03:00
* All `js` and `javascript` code blocks are linted with
[standard-markdown](http://npm.im/standard-markdown).
2016-06-24 04:45:37 +03:00
## Picking words
2016-06-24 04:45:37 +03:00
* Use "will" over "would" when describing outcomes.
* Prefer "in the ___ process" over "on".
2016-06-24 04:45:37 +03:00
## API references
2016-06-24 22:28:41 +03:00
The following rules only apply to the documentation of APIs.
2015-08-22 15:07:45 +03:00
2016-06-24 04:45:37 +03:00
### Page title
2015-08-22 15:07:45 +03:00
2016-06-24 04:45:37 +03:00
Each page must use the actual object name returned by `require('electron')`
2016-06-24 22:40:55 +03:00
as the title, such as `BrowserWindow`, `autoUpdater`, and `session`.
2016-06-24 04:45:37 +03:00
2017-11-17 23:14:33 +03:00
Under the page title must be a one-line description starting with `>`.
2015-08-22 15:07:45 +03:00
2016-06-24 04:45:37 +03:00
Using `session` as example:
```markdown
# session
> Manage browser sessions, cookies, cache, proxy settings, etc.
```
2015-08-22 15:07:45 +03:00
2016-06-24 04:45:37 +03:00
### Module methods and events
For modules that are not classes, their methods and events must be listed under
2016-06-24 22:40:55 +03:00
the `## Methods` and `## Events` chapters.
2016-06-24 04:45:37 +03:00
2016-06-24 22:28:41 +03:00
Using `autoUpdater` as an example:
2016-06-24 04:45:37 +03:00
```markdown
# autoUpdater
## Events
### Event: 'error'
## Methods
### `autoUpdater.setFeedURL(url[, requestHeaders])`
```
2015-08-22 15:07:45 +03:00
2016-06-24 04:45:37 +03:00
### Classes
* API classes or classes that are part of modules must be listed under a
2016-06-24 22:40:55 +03:00
`## Class: TheClassName` chapter.
* One page can have multiple classes.
2016-07-13 08:00:28 +03:00
* Constructors must be listed with `###`-level titles.
* [Static Methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static) must be listed under a `### Static Methods` chapter.
* [Instance Methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Prototype_methods) must be listed under an `### Instance Methods` chapter.
* All methods that have a return value must start their description with "Returns `[TYPE]` - Return description"
2016-09-27 07:04:54 +03:00
* If the method returns an `Object`, its structure can be specified using a colon followed by a newline then an unordered list of properties in the same style as function parameters.
2016-07-13 08:00:28 +03:00
* Instance Events must be listed under an `### Instance Events` chapter.
* Instance Properties must be listed under an `### Instance Properties` chapter.
2016-09-25 03:04:10 +03:00
* Instance properties must start with "A [Property Type] ..."
2016-06-24 04:45:37 +03:00
2016-06-24 22:40:55 +03:00
Using the `Session` and `Cookies` classes as an example:
2016-06-24 04:45:37 +03:00
```markdown
# session
## Methods
### session.fromPartition(partition)
## Properties
### session.defaultSession
## Class: Session
### Instance Events
#### Event: 'will-download'
### Instance Methods
#### `ses.getCacheSize(callback)`
### Instance Properties
#### `ses.cookies`
## Class: Cookies
### Instance Methods
#### `cookies.get(filter, callback)`
```
### Methods
2016-06-24 22:28:41 +03:00
The methods chapter must be in the following form:
2016-06-24 04:45:37 +03:00
```markdown
### `objectName.methodName(required[, optional]))`
2016-12-30 01:11:26 +03:00
* `required` String - A parameter description.
* `optional` Integer (optional) - Another parameter description.
2016-06-24 04:45:37 +03:00
...
```
The title can be `###` or `####`-levels depending on whether it is a method of
2016-06-24 22:28:41 +03:00
a module or a class.
2016-06-24 04:45:37 +03:00
2016-06-25 01:59:30 +03:00
For modules, the `objectName` is the module's name. For classes, it must be the
2016-06-24 22:28:41 +03:00
name of the instance of the class, and must not be the same as the module's
name.
2016-06-24 04:45:37 +03:00
2016-06-24 22:28:41 +03:00
For example, the methods of the `Session` class under the `session` module must
use `ses` as the `objectName`.
2016-06-24 04:45:37 +03:00
2016-06-25 01:59:30 +03:00
The optional arguments are notated by square brackets `[]` surrounding the optional argument
2016-06-24 04:45:37 +03:00
as well as the comma required if this optional argument follows another
2016-06-25 01:59:30 +03:00
argument:
```sh
2016-06-25 01:59:30 +03:00
required[, optional]
```
2015-08-22 15:07:45 +03:00
2015-08-24 15:38:29 +03:00
Below the method is more detailed information on each of the arguments. The type
of argument is notated by either the common types:
2016-06-24 22:28:41 +03:00
* [`String`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
* [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
* [`Object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
* [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
* [`Boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
2016-09-25 10:13:34 +03:00
* Or a custom type like Electron's [`WebContent`](api/web-contents.md)
2015-08-22 15:07:45 +03:00
2016-06-24 04:45:37 +03:00
If an argument or a method is unique to certain platforms, those platforms are
denoted using a space-delimited italicized list following the datatype. Values
can be `macOS`, `Windows` or `Linux`.
2016-06-17 22:33:50 +03:00
2016-06-24 22:28:41 +03:00
```markdown
2016-12-30 01:11:26 +03:00
* `animate` Boolean (optional) _macOS_ _Windows_ - Animate the thing.
2016-06-17 22:33:50 +03:00
```
2016-06-25 01:59:30 +03:00
`Array` type arguments must specify what elements the array may include in
2016-06-24 22:40:55 +03:00
the description below.
2016-06-24 04:45:37 +03:00
2016-06-24 22:40:55 +03:00
The description for `Function` type arguments should make it clear how it may be
called and list the types of the parameters that will be passed to it.
2016-06-24 04:45:37 +03:00
2015-08-22 15:07:45 +03:00
### Events
2016-06-24 22:28:41 +03:00
The events chapter must be in following form:
2015-08-22 15:07:45 +03:00
2016-06-24 04:45:37 +03:00
```markdown
### Event: 'wake-up'
2015-08-22 15:07:45 +03:00
Returns:
* `time` String
2016-06-24 04:45:37 +03:00
...
```
2015-08-22 15:07:45 +03:00
2016-06-24 04:45:37 +03:00
The title can be `###` or `####`-levels depending on whether it is an event of
2016-06-24 22:28:41 +03:00
a module or a class.
2016-06-24 04:45:37 +03:00
2016-06-24 22:40:55 +03:00
The arguments of an event follow the same rules as methods.
2016-06-24 04:45:37 +03:00
### Properties
2016-06-24 22:28:41 +03:00
The properties chapter must be in following form:
2016-06-24 04:45:37 +03:00
```markdown
### session.defaultSession
...
2015-08-22 15:07:45 +03:00
```
2016-06-24 04:45:37 +03:00
The title can be `###` or `####`-levels depending on whether it is a property of
2016-06-24 22:28:41 +03:00
a module or a class.
2016-06-24 04:45:37 +03:00
## Documentation Translations
2018-03-02 23:05:49 +03:00
See [electron/i18n](https://github.com/electron/i18n#readme)