UNPKG

4.91 kBMarkdownView Raw
1# Firedoc Syntax Guide
2
3Firedoc is compatible with all YUIDoc tags (http://yui.github.io/yuidoc/syntax/).
4If you find some tags not working with Firedoc feel free to [submit an issue](https://github.com/fireball-x/firedoc/issues).
5
6> Firedoc is based on YUIDoc so it only does process comments, not actual code.
7
8Firedoc has the following enhanced features:
9
10- [Members for Module](#members-for-module)
11- [Callback Function](#callback-function)
12- [Multi-language Description](#multi-language-description)
13- [Single-line Property/Parameter Declaration](#single-line-propertyparameter-declaration)
14- [Enum](#enum)
15- [Example Link to File](#example-link-to-file)
16- [Detailed Properties of Object Parameter](#detailed-properties-of-object-parameter)
17
18## Members for Module
19
20In both JSDoc and YUIDoc, properties and methods can only exists under `@class`. Firedoc supports direct member of modules.
21You can declare members under module like this:
22```js
23/**
24 * @module FireDoc
25 */
26/**
27 * Prop description
28 * @property test2
29 * @type {String}
30 */
31var test2;
32```
33
34The property `test2` will be listed under `FireDoc` module page. No need to create psuedo classes just for hoding global methods and properties.
35
36## Callback Function
37
38Firedoc added `@callback` tag for declaring callback function signature that you can reuse in many methods.
39
40```js
41/**
42 * @callback ExampleCallback
43 * @param {String} html The HTML to write module view.
44 * @param {Object} view The View Data.
45 */
46 /**
47 * Generates the module files undert "out"/modules/
48 * @method test2
49 * @param {ExampleCallback} cb The callback to execute after it's completed
50 */
51 /**
52 * Generates the module files undert "out"/modules/
53 * @method test3
54 * @param {String} id
55 * @param {ExampleCallback} cb The callback to execute after it's completed
56 */
57```
58In the above example, both method `test2` and `test3` reuses callback function `ExampleCallback` (although in real code it perhaps will be an anonymous function, we give it a name only for convenience of commenting callbacks with the same signatures) .
59
60## Multi-language Description
61
62Firedoc supports multi-language description for any module, class, method, property, parameter. Use language tag `!#en` or `!#zh` to mark the description in a certain language. Then use `firedoc source --zh` to generate api docs for that language.
63
64You can use two patterns for inserting language tags:
65
66### Multilines
67
68```js
69/**
70 * !#en
71 * English class description
72 * !#zh
73 * 中文类型描述
74 * @class FLogic
75 */
76```
77
78### Inline
79
80```js
81/**
82 * !#en English class description !#zh 中文类型描述
83 * @class FLogic
84 */
85```
86
87## Single-line Property/Parameter Declaration
88
89Same as JSDoc syntax:
90```js
91/**
92 * @property {Vec2} position - The local position in its parent's coordinate system
93 */
94```
95
96You can also put description ahead:
97```js
98/**
99 * The local position in its parent's coordinate system
100 * @property {Vec2} position
101 */
102```
103
104## Enum
105
106Use `@enum` with `@property` to document enum definitions.
107
108```js
109/**
110 * Enum description
111 * @enum NumberableBool
112 */
113var NumberableBool = {
114 /**
115 * @property {number} TRUE - stands for true
116 */
117 TRUE: 1,
118 /**
119 * @property {number} FALSE - stands for false
120 */
121 FALSE: -1,
122};
123```
124
125You can write all `@property` in the same comment block as the enum declaration.
126
127## Examples
128
129### Example Link to File
130
131Use `@example` with `@link` to display code in a file as example.
132
133```js
134/**
135* @method example
136* @example {@link path/to/example.js }
137*/
138```
139
140The path `path/to/example.js` is based at your execution path (or cwd).
141
142### Example File with Sections
143
144To hold multiple examples in one file, you can write your example file like this:
145
146```js
147/** @section Food */
148
149var this = 'burger';
150
151this.cook();
152
153/** @section Drink */
154
155var this = 'cola';
156```
157
158And link it to your example with `#section` notion:
159
160```js
161/**
162* @method example
163* @example {@link path/to/example.js#Food }
164*/
165```
166
167This will gives you the following example text:
168
169```js
170var this = 'burger';
171
172this.cook();
173```
174
175### Auto Backtick Wrap
176
177Example code in a linked file or inline will be automatically wrapped in ````js` backtick. No need to add them yourself.
178
179### Example for Class and Modules
180
181Now you can write `@example` tag in class or module block.
182
183
184## Detailed Properties of Object Parameter
185
186If you want to detail the properties of a object parameter for a method, use the following pattern:
187
188```js
189/**
190 * @method star
191 * @param {String} command The command to run
192 * @param {Array} args List of string arguments
193 * @param {Object} options
194 * @param {String} options.cwd
195 * @param {Object} options.env
196 * @param {Array|String} options.stdio
197 * @param {Array} options.customFds
198 */
199```