Skip to content

Commit 3dc08cf

Browse files
authored
Merge branch 'master' into signature-template
2 parents f82f95b + 7d00b1f commit 3dc08cf

32 files changed

+1703
-848
lines changed

bit-docs-js.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@parent plugins
2+
@module bit-docs-js
3+
@group bit-docs-js/types types
4+
@group bit-docs-js/tags tags
5+
@group bit-docs-js/templates templates
6+
@group bit-docs-js/static static
7+
@group bit-docs-js/modules modules
8+
9+
@description Plugin to process `.js` files and help document JavaScript code.
10+
11+
@body
12+
13+
## Use this plugin
14+
15+
Add this plugin to your project `package.json`:
16+
17+
```json
18+
{
19+
"name": "my-project",
20+
---snip---
21+
"bit-docs": {
22+
"dependencies": {
23+
---snip---
24+
"bit-docs-js": "*",
25+
---snip---
26+
},
27+
---snip---
28+
}
29+
}
30+
```
31+
32+
Once added, this plugin allows you to document `.js` files like:
33+
34+
```js
35+
/**
36+
* @module {{}} example/settings settings
37+
* @parent example
38+
* @option {String} environment Production, development, or staging.
39+
* @option {Number} requestTimeout How long to wait between requests.
40+
*/
41+
export default {
42+
environment: "production",
43+
requestTimeout: 100
44+
}
45+
```
46+
47+
Using [bit-docs-js/templates/signature.mustache signature.mustache] in the
48+
[bit-docs-generate-html/site/default/templates/content.mustache default theme],
49+
this example renders like:
50+
51+
<img src="https://user-images.githubusercontent.com/990216/30096690-7e01d47c-929f-11e7-9eac-bbe97f4f1a7f.png" width="50%" />
52+
53+
### See next
54+
55+
- Back-end hooks: [bit-docs-js/bit-docs].
56+
- Front-end assets: [bit-docs-js/index.js].

bit-docs.js

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,51 @@ var processJavaScript = require("./process/javascript");
33
var path = require("path");
44

55
/**
6-
* @module {function} bit-docs-js
7-
* @parent plugins
8-
* @group bit-docs-js/static static
9-
* @group bit-docs-js/tags tags
6+
* @parent bit-docs-js/modules
7+
* @module {bit-docs/types/plugin} bit-docs-js/bit-docs
108
*
11-
* @description Tags, templates, and basic styles for JavaScript.
12-
*
13-
* @param {Object} [bitDocs] The configuration object passed by `bit-docs` at
14-
* runtime.
9+
* @description Register hooks to add tags, templates, and basic styles useful
10+
* for documenting JavaScript.
11+
*
12+
* @signature `jsPlugin(bitDocs)`
13+
*
14+
* @param {Object} bitDocs Configuration object with a `register` method.
1515
*
1616
* @body
1717
*
18-
* This plugin registers onto these hooks:
18+
* ## Use
19+
*
20+
* Registers onto these hooks:
1921
* - `tags`
2022
* - `processor`
2123
* - `html`
2224
*
23-
* Registering the `tag` hook adds JavaScript-related tags:
24-
* - [bit-docs-js/tags/function @function]
25+
* ### Tags
26+
*
27+
* Registering the `tags` hook adds JavaScript-related tags:
28+
* - [bit-docs-js/tag/function]
29+
* - [bit-docs-js/tags/module @module]
30+
* - [bit-docs-js/tags/option @option]
2531
* - [bit-docs-js/tags/param @param]
32+
* - [bit-docs-js/tags/property @property]
33+
* - [bit-docs-js/tags/prototype @prototype]
34+
* - [bit-docs-js/tags/return @return]
2635
* - [bit-docs-js/tags/signature @signature]
27-
* - ...
36+
* - [bit-docs-js/tags/typedef @typedef]
37+
*
38+
* ### Processor
2839
*
2940
* Registering the `processor` hook adds a processor for `*.js` files that gets
3041
* code comments in JavaScript, and processes tags like `@function` and
31-
* `@param` into docObjects that are subsequently added to the docMap.
42+
* `@param` into [bit-docs/types/docObject]s that are subsequently added to the
43+
* [bit-docs/types/docMap].
3244
*
33-
* The processor is also smart enough process regular comments above functions
34-
* that have not explicitly been documented with closure type annotations, and
35-
* extracts basic signature information such as parameters and/or return type.
45+
* Comments above functions that do not include [bit-docs-js/types/tag]s
46+
* will still be processed as [bit-docs-js/types/tagBlock]s as the processor
47+
* extracts basic signature information such as parameters and/or return type
48+
* from the [bit-docs-js/types/codeLine].
49+
*
50+
* ### HTML
3651
*
3752
* Registering the `html` hook adds a mustache template used to generate the
3853
* HTML for the tags added by this plugin.

process/code.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
var _ = require("lodash");
2+
23
/**
3-
* @function documentjs.process.code
4-
* @parent documentjs.process.methods
5-
*
6-
* Process a code hint into properties on a `docObject`.
7-
*
8-
* @signature `documentjs.process.code(options, callback)`
4+
* @parent bit-docs-js/modules
5+
* @module {function} bit-docs-js/process/code
96
*
10-
* Using the `options.code`, and `options.tags`, processes the code
11-
* into properties on a docObject. The `callback` is called with the new docObject.
7+
* Process a line of code to add properties on a [bit-docs/types/docObject].
128
*
13-
* @param {documentjs.process.processOptions} options An options object that contains
14-
* the code to process.
9+
* @signature `processCode(options, callback)`
1510
*
16-
* @param {function(documentjs.process.docObject,documentjs.process.docObject)} callback(newDoc,newScope)
11+
* @param {bit-docs-js/types/processCodeOptions} options
12+
*
13+
* Options object that includes the [bit-docs-process-tags/types/tagBlock] and
14+
* any line of code that immediately followed the block.
15+
*
16+
* @param {bit-docs/types/processorCallback} callback
1717
*
18-
* A function that is called back with a docObject created from the code and the scope
19-
* `docObject`. If
20-
* no docObject is created, `newDoc` will be null.
18+
* Callback to call with the new [bit-docs/types/docObject].
2119
*
2220
* @body
2321
*
2422
* ## Use
2523
*
26-
* documentjs.process.code(
27-
* {code: "foo: function(){"},
28-
* function(newDoc){
29-
* newDoc.type //-> "function"
30-
* }
24+
* processCode({
25+
* code: "foo: function(){"
26+
* },
27+
* function(newDoc) {
28+
* newDoc.type //-> "function"
29+
* }
3130
* )
3231
*/
3332
module.exports = function(options, callback){

process/code_and_comment.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
1-
var processCode = require("./code"),
2-
processTags = require("bit-docs-process-tags");
1+
var processCode = require("./code");
2+
var processTags = require("bit-docs-process-tags");
33

44
var typeCheckReg = /^\s*@(\w+)/;
5+
56
/**
6-
* @function documentjs.process.codeAndComment
7-
* @parent documentjs.process.methods
8-
*
9-
* @signature `documentjs.process.codeAndComment(options, callback)`
7+
* @parent bit-docs-js/modules
8+
* @module {function} bit-docs-js/process/codeAndComment
109
*
11-
* Processes a code suggestion and then a comment and produces a docObject.
10+
* @signature `processCodeAndComment(options, callback)`
1211
*
13-
* @param {documentjs.process.processOptions} options An options object that contains
14-
* the code and comment to process.
12+
* Processes a [bit-docs-js/types/codeTagBlock] and the
13+
* [bit-docs-js/types/codeLine] immediately following the
14+
* [bit-docs-js/types/codeTagBlock] to produce a new
15+
* [bit-docs/types/docObject].
1516
*
16-
* @param {function(documentjs.process.docObject,documentjs.process.docObject)} callback(newDoc,newScope)
17+
* @param {bit-docs-js/types/processCodeOptions} options
18+
*
19+
* Options object that includes the [bit-docs-js/types/codeTagBlock] and any
20+
* [bit-docs-js/types/codeLine] that immediately followed the
21+
* [bit-docs-js/types/codeTagBlock].
1722
*
18-
* A function that is called back with a docObject created from the code and the scope
19-
* `docObject`. If
20-
* no docObject is created, `newDoc` will be null.
23+
* @param {bit-docs/types/processorCallback} callback
2124
*
22-
* @option newDoc the new documentation object
23-
* @option newScope the new scope
25+
* Callback to call with the new [bit-docs/types/docObject].
2426
*/
2527
module.exports = function(options, callback){
26-
var self = this,
27-
comment = options.comment;
28+
var self = this;
29+
var comment = options.comment;
2830

29-
var firstLine = (typeof comment == 'string' ? comment : comment[0]) || "",
30-
check = firstLine.match(typeCheckReg);
31+
var firstLine = (typeof comment == 'string' ? comment : comment[0]) || "";
32+
var check = firstLine.match(typeCheckReg);
3133

3234
if(check){
3335
if(!options.docObject){

tags/class.js

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,55 @@
1-
var getParent = require("bit-docs-process-tags/get-parent"),
2-
tnd = require("bit-docs-type-annotate").typeNameDescription;
1+
var getParent = require("bit-docs-process-tags/get-parent");
2+
var tnd = require("bit-docs-type-annotate").typeNameDescription;
33

4-
var funcMatch = /(?:([\w\.\$]+)|(["'][^"']+["']))\s*[=]\s*function\s?\(([^\)]*)/,
5-
codeMatch = /([\w\.\$]+?).extend\(\s*["']([^"']*)["']/;
4+
var funcMatch = /(?:([\w\.\$]+)|(["'][^"']+["']))\s*[=]\s*function\s?\(([^\)]*)/;
5+
var codeMatch = /([\w\.\$]+?).extend\(\s*["']([^"']*)["']/;
66

7+
/**
8+
* @parent bit-docs-js/modules
9+
* @module {bit-docs-process-tags/types/tag} bit-docs-js/tags/class
10+
*
11+
* @description Deprecated. Use [bit-docs-js/tags/constructor] instead.
12+
*
13+
* @signature `require('./tags/class');`
14+
*
15+
* @return {bit-docs-process-tags/types/tag} Tag object configured for the
16+
* [bit-docs-js/tag/class] tag.
17+
*
18+
* @body
19+
*
20+
* Gets converted to [bit-docs-js/tags/constructor].
21+
*/
22+
module.exports = {
723
/**
8-
* @constructor documentjs.tags.constructor @constructor
9-
* @hide
10-
* Document a constructor function.
11-
*
12-
* @signature `@constructor NAME [TITLE]`
13-
* @parent documentjs.tags
24+
* @signature `add(line)`
25+
*
26+
* [bit-docs-process-tags/types/tag.add] for [bit-docs-js/tag/class].
27+
*
28+
* Simply converts the scope into that of [bit-docs-js/tags/constructor].
29+
*
30+
* @param {String} line Text from [bit-docs-js/tag/class] until the end
31+
* of line.
32+
*
33+
* For example:
34+
*
35+
* @codestart javascript
36+
* @@class my-project/lib/index
37+
* @codeend
38+
*
39+
* @return {bit-docs-process-tags/types/processTagsCommand} `['scope', this]`
1440
*/
15-
module.exports = {
16-
add: function(line, curData, scope, docMap){
17-
console.warn("Using the @class directive. It is deprecated!");
18-
// it's possible this has already been matched as something else ... clear parent
41+
add: function(line){
42+
console.warn("Using the @class directive. It is deprecated!");
43+
// it's possible this has already been matched as something else
44+
// ... clear parent
1945

20-
this.type = "constructor";
21-
var data = tnd(line);
22-
if(data.name) {
23-
this.name = data.name;
24-
}
25-
26-
this.title = data.description;
27-
return ["scope",this];
46+
this.type = "constructor";
47+
var data = tnd(line);
48+
if(data.name) {
49+
this.name = data.name;
2850
}
29-
};
51+
52+
this.title = data.description;
53+
return ["scope",this];
54+
}
55+
};

tags/class.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@parent bit-docs-js/tags
2+
@constructor bit-docs-js/tag/class @class
3+
4+
@description Deprecated tag. Use [bit-docs-js/tag/constructor] instead.
5+
6+
@signature `@class NAME [TITLE]`
7+
8+
@body
9+
10+
Gets converted to [bit-docs-js/tag/constructor].

0 commit comments

Comments
 (0)