Skip to content

Commit 5867cd7

Browse files
committed
docs: update examples and have code as seperate files
the seperate files are ease-of-use for directly using the "dox" binary
1 parent 0550a76 commit 5867cd7

File tree

7 files changed

+204
-61
lines changed

7 files changed

+204
-61
lines changed

Readme.md

+138-61
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ to inspect the generated data you can use the `--debug` flag, which is easier to
2727
dox --debug < utils.js
2828
```
2929

30-
utils.js:
30+
[utils.js](./doc_examples/utils.js):
3131

3232
```js
3333
/**
@@ -175,6 +175,8 @@ the "summary", and the "body". The following example has only a "summary",
175175
as it consists of a single paragraph only, therefore the "full" property has
176176
only this value as well.
177177

178+
[write1.js](./doc_examples/write1.js):
179+
178180
```js
179181
/**
180182
* Output the given `str` to _stdout_.
@@ -187,15 +189,23 @@ exports.write = function(str) {
187189

188190
yields:
189191

190-
```js
191-
description:
192-
{ full: '<p>Output the given <code>str</code> to <em>stdout</em>.</p>',
193-
summary: '<p>Output the given <code>str</code> to <em>stdout</em>.</p>',
194-
body: '' },
192+
```json
193+
[
194+
{
195+
"description": {
196+
"full": "<p>Output the given <code>str</code> to <em>stdout</em>.</p>",
197+
"summary": "<p>Output the given <code>str</code> to <em>stdout</em>.</p>",
198+
"body": ""
199+
},
200+
// ... other tags
201+
}
202+
]
195203
```
196204

197205
Large descriptions might look something like the following, where the "summary" is still the first paragraph, the remaining description becomes the "body". Keep in mind this _is_ markdown, so you can indent code, use lists, links, etc. Dox also augments markdown, allowing "Some Title:\n" to form a header.
198206

207+
[write2.js](./doc_examples/write2.js):
208+
199209
```js
200210
/**
201211
* Output the given `str` to _stdout_
@@ -220,19 +230,26 @@ exports.write = function(str, options) {
220230

221231
yields:
222232

223-
```js
224-
description:
225-
{ full: '<p>Output the given <code>str</code> to <em>stdout</em><br />or the stream specified by <code>options</code>.</p>\n\n<h2>Options</h2>\n\n<ul>\n<li><code>stream</code> defaulting to <em>stdout</em></li>\n</ul>\n\n<h2>Examples</h2>\n\n<pre><code>mymodule.write(\'foo\')\nmymodule.write(\'foo\', { stream: process.stderr })\n</code></pre>',
226-
summary: '<p>Output the given <code>str</code> to <em>stdout</em><br />or the stream specified by <code>options</code>.</p>',
227-
body: '<h2>Options</h2>\n\n<ul>\n<li><code>stream</code> defaulting to <em>stdout</em></li>\n</ul>\n\n<h2>Examples</h2>\n\n<pre><code>mymodule.write(\'foo\')\nmymodule.write(\'foo\', { stream: process.stderr })\n</code></pre>' }
233+
```json
234+
[
235+
{
236+
"description": {
237+
"full": "<p>Output the given <code>str</code> to <em>stdout</em><br />\nor the stream specified by <code>options</code>.</p>\n<p>Options:</p>\n<ul>\n<li><code>stream</code> defaulting to <em>stdout</em></li>\n</ul>\n<p>Examples:</p>\n<pre><code>mymodule.write('foo')\nmymodule.write('foo', { stream: process.stderr })\n</code></pre>",
238+
"summary": "<p>Output the given <code>str</code> to <em>stdout</em><br />\nor the stream specified by <code>options</code>.</p>",
239+
"body": "<p>Options:</p>\n<ul>\n<li><code>stream</code> defaulting to <em>stdout</em></li>\n</ul>\n<p>Examples:</p>\n<pre><code>mymodule.write('foo')\nmymodule.write('foo', { stream: process.stderr })\n</code></pre>"
240+
},
241+
// ... other tags
242+
}
243+
]
228244
```
229245

230246
### Tags
231247

232248
Dox also supports JSdoc-style tags. Currently only __@api__ is special-cased, providing the `comment.isPrivate` boolean so you may omit "private" utilities etc.
233249

234-
```js
250+
[write_tags.js](./doc_examples/write_tags.js):
235251

252+
```js
236253
/**
237254
* Output the given `str` to _stdout_
238255
* or the stream specified by `options`.
@@ -251,24 +268,61 @@ exports.write = function(str, options) {
251268

252269
yields:
253270

254-
```js
255-
tags:
256-
[ { type: 'param',
257-
string: '{String} str',
258-
types: [ 'String' ],
259-
name: 'str',
260-
description: '' },
261-
{ type: 'param',
262-
string: '{{stream: Writable}} options',
263-
types: [ { stream: ['Writable'] } ],
264-
name: 'options',
265-
description: '' },
266-
{ type: 'return',
267-
string: '{Object} exports for chaining',
268-
types: [ 'Object' ],
269-
description: 'exports for chaining' },
270-
{ type: 'api',
271-
visibility: 'public' } ]
271+
```json
272+
[
273+
{
274+
"tags": [
275+
{
276+
"type": "param",
277+
"string": "{String} str",
278+
"name": "str",
279+
"description": "",
280+
"types": [
281+
"String"
282+
],
283+
"typesDescription": "<code>String</code>",
284+
"optional": false,
285+
"nullable": false,
286+
"nonNullable": false,
287+
"variable": false,
288+
"html": "<p>{String} str</p>"
289+
},
290+
{
291+
"type": "param",
292+
"string": "{{stream: Writable}} options",
293+
"name": "options",
294+
"description": "",
295+
"types": [
296+
{
297+
"stream": [
298+
"Writable"
299+
]
300+
}
301+
],
302+
"typesDescription": "{stream: <code>Writable</code>}",
303+
"optional": false,
304+
"nullable": false,
305+
"nonNullable": false,
306+
"variable": false,
307+
"html": "<p>{{stream: Writable}} options</p>"
308+
},
309+
{
310+
"type": "return",
311+
"string": "{Object} exports for chaining",
312+
"types": [
313+
"Object"
314+
],
315+
"typesDescription": "<code>Object</code>",
316+
"optional": false,
317+
"nullable": false,
318+
"nonNullable": false,
319+
"variable": false,
320+
"description": "<p>exports for chaining</p>"
321+
}
322+
],
323+
// ... other tags
324+
}
325+
]
272326
```
273327

274328
#### Complex jsdoc tags
@@ -278,8 +332,9 @@ specify complex object types including optional flag `=`, nullable `?`, non-null
278332

279333
Additionally you can use `typesDescription` which contains formatted HTML for displaying complex types.
280334

281-
```js
335+
[generatePersonInfo.js](./doc_examples/generatePersonInfo.js):
282336

337+
```js
283338
/**
284339
* Generates a person information string based on input.
285340
*
@@ -302,16 +357,15 @@ exports.generatePersonInfo = function(name, options) {
302357

303358
yields:
304359

305-
```js
306-
tags:
360+
```json
307361
[
308362
{
309363
"tags": [
310364
{
311365
"type": "param",
312366
"string": "{string | {name: string, age: number | date}} name Name or person object",
313367
"name": "name",
314-
"description": "Name or person object",
368+
"description": "<p>Name or person object</p>",
315369
"types": [
316370
"string",
317371
{
@@ -324,7 +378,7 @@ tags:
324378
]
325379
}
326380
],
327-
"typesDescription": "<code>string</code>|{ name: <code>string</code>, age: <code>number</code>|<code>date</code> }",
381+
"typesDescription": "<code>string</code> | {name: <code>string</code>, age: <code>number</code> | <code>date</code>}",
328382
"optional": false,
329383
"nullable": false,
330384
"nonNullable": false,
@@ -334,15 +388,15 @@ tags:
334388
"type": "param",
335389
"string": "{{separator: string} =} options An options object",
336390
"name": "options",
337-
"description": "An options object",
391+
"description": "<p>An options object</p>",
338392
"types": [
339393
{
340394
"separator": [
341395
"string"
342396
]
343397
}
344398
],
345-
"typesDescription": "{ separator: <code>string</code> }|<code>undefined</code>",
399+
"typesDescription": "{separator: <code>string</code>|<code>undefined</code>}",
346400
"optional": true,
347401
"nullable": false,
348402
"nonNullable": false,
@@ -359,9 +413,12 @@ tags:
359413
"nullable": false,
360414
"nonNullable": false,
361415
"variable": false,
362-
"description": "The constructed information string"
416+
"description": "<p>The constructed information string</p>"
363417
}
364-
]
418+
],
419+
// ... other tags
420+
}
421+
]
365422
```
366423

367424
### Code
@@ -380,48 +437,68 @@ exports.write = function(str, options) {
380437

381438
The `.ctx` object indicates the context of the code block, is it a method, a function, a variable etc. Below are some examples:
382439

440+
[ctx.js](./doc_examples/ctx.js):
441+
383442
```js
384-
exports.write = function(str, options) {
385-
};
443+
/** */
444+
exports.generate = function(str, options) {};
386445
```
387446

388447
yields:
389448

390-
```js
391-
ctx:
392-
{ type: 'method',
393-
receiver: 'exports',
394-
name: 'write',
395-
string: 'exports.write()' } }
449+
```json
450+
[
451+
{
452+
// ... other tags
453+
"ctx": {
454+
"type": "method",
455+
"receiver": "exports",
456+
"name": "generate",
457+
"string": "exports.generate()"
458+
}
459+
}
460+
]
396461
```
397462

398463
```js
464+
/** */
399465
var foo = 'bar';
400466
```
401467

402468
yields:
403469

404-
```js
405-
ctx:
406-
{ type: 'declaration',
407-
name: 'foo',
408-
value: '\'bar\'',
409-
string: 'foo' }
470+
```json
471+
[
472+
{
473+
// ... other tags
474+
"ctx": {
475+
"type": "declaration",
476+
"name": "foo",
477+
"value": "'bar'",
478+
"string": "foo"
479+
}
480+
}
481+
]
410482
```
411483

412484
```js
413-
function User() {
414-
415-
}
485+
/** */
486+
function User() {}
416487
```
417488

418489
yields:
419490

420-
```js
421-
ctx:
422-
{ type: 'function',
423-
name: 'User',
424-
string: 'User()' } }
491+
```json
492+
[
493+
{
494+
// ... other tags
495+
"ctx": {
496+
"type": "function",
497+
"name": "User",
498+
"string": "User()"
499+
}
500+
}
501+
]
425502
```
426503

427504
### Extending Context Matching

doc_examples/ctx.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** */
2+
exports.generate = function(str, options) {};
3+
4+
/** */
5+
var foo = 'bar';
6+
7+
/** */
8+
function User() {}

doc_examples/generatePersonInfo.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Generates a person information string based on input.
3+
*
4+
* @param {string | {name: string, age: number | date}} name Name or person object
5+
* @param {{separator: string} =} options An options object
6+
* @return {string} The constructed information string
7+
*/
8+
9+
exports.generatePersonInfo = function(name, options) {
10+
var str = '';
11+
var separator = options && options.separator ? options.separator : ' ';
12+
13+
if(typeof name === 'object') {
14+
str = [name.name, '(', name.age, ')'].join(separator);
15+
} else {
16+
str = name;
17+
}
18+
};
File renamed without changes.

doc_examples/write1.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Output the given `str` to _stdout_.
3+
*/
4+
5+
exports.write = function(str) {
6+
process.stdout.write(str);
7+
};

doc_examples/write2.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Output the given `str` to _stdout_
3+
* or the stream specified by `options`.
4+
*
5+
* Options:
6+
*
7+
* - `stream` defaulting to _stdout_
8+
*
9+
* Examples:
10+
*
11+
* mymodule.write('foo')
12+
* mymodule.write('foo', { stream: process.stderr })
13+
*
14+
*/
15+
16+
exports.write = function(str, options) {
17+
options = options || {};
18+
(options.stream || process.stdout).write(str);
19+
};

doc_examples/write_tags.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Output the given `str` to _stdout_
3+
* or the stream specified by `options`.
4+
*
5+
* @param {String} str
6+
* @param {{stream: Writable}} options
7+
* @return {Object} exports for chaining
8+
*/
9+
10+
exports.write = function(str, options) {
11+
options = options || {};
12+
(options.stream || process.stdout).write(str);
13+
return this;
14+
};

0 commit comments

Comments
 (0)