Skip to content

Commit 56038c3

Browse files
committed
next
- Added at NextDoor - Version 2.0 of this modules' docs.
1 parent 2405049 commit 56038c3

30 files changed

+980
-374
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: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,29 @@ var processJavaScript = require("./process/javascript");
33
var path = require("path");
44

55
/**
6-
* @parent plugins
7-
* @module {function} bit-docs-js
8-
* @group bit-docs-js/modules modules
9-
* @group bit-docs-js/tags tags
10-
* @group bit-docs-js/templates templates
6+
* @parent bit-docs-js/modules
7+
* @module {bit-docs/types/plugin} bit-docs-js/bit-docs
118
*
12-
* @description Tags, templates, and basic styles for JavaScript.
13-
*
14-
* @param {Object} [bitDocs] The configuration object passed by `bit-docs` at
15-
* 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.
1615
*
1716
* @body
1817
*
19-
* This plugin registers onto these hooks:
18+
* ## Use
19+
*
20+
* Registers onto these hooks:
2021
* - `tags`
2122
* - `processor`
2223
* - `html`
2324
*
25+
* ### Tags
26+
*
2427
* Registering the `tags` hook adds JavaScript-related tags:
25-
* - [bit-docs-js/tags/function @function]
28+
* - [bit-docs-js/tag/function]
2629
* - [bit-docs-js/tags/module @module]
2730
* - [bit-docs-js/tags/option @option]
2831
* - [bit-docs-js/tags/param @param]
@@ -32,14 +35,19 @@ var path = require("path");
3235
* - [bit-docs-js/tags/signature @signature]
3336
* - [bit-docs-js/tags/typedef @typedef]
3437
*
38+
* ### Processor
39+
*
3540
* Registering the `processor` hook adds a processor for `*.js` files that gets
3641
* code comments in JavaScript, and processes tags like `@function` and
3742
* `@param` into [bit-docs/types/docObject]s that are subsequently added to the
3843
* [bit-docs/types/docMap].
3944
*
40-
* The processor is also smart enough process regular comments above functions
41-
* that have not explicitly been documented with closure type annotations, and
42-
* 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
4351
*
4452
* Registering the `html` hook adds a mustache template used to generate the
4553
* HTML for the tags added by this plugin.

process/code.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,29 @@ var _ = require("lodash");
44
* @parent bit-docs-js/modules
55
* @module {function} bit-docs-js/process/code
66
*
7-
* Process a code hint into properties on a [bit-docs/types/docObject].
7+
* Process a line of code to add properties on a [bit-docs/types/docObject].
88
*
99
* @signature `processCode(options, callback)`
1010
*
11-
* Using the `options.code`, and `options.tags`, processes the code into
12-
* properties on a [bit-docs/types/docObject].
11+
* @param {bit-docs-js/types/processCodeOptions} options
1312
*
14-
* The `callback` is called with the new [bit-docs/types/docObject].
15-
*
16-
* @param {bit-docs/types/processOptions} options An options object that
17-
* contains the code to process.
18-
*
19-
* @param {function(bit-docs/types/docObject,bit-docs/types/docObject)} callback(newDoc,newScope)
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
2017
*
21-
* A function that is called back with a [bit-docs/types/docObject] created
22-
* from the code and the scope `docObject`. If no [bit-docs/types/docObject] is
23-
* created, `newDoc` will be null.
18+
* Callback to call with the new [bit-docs/types/docObject].
2419
*
2520
* @body
2621
*
2722
* ## Use
2823
*
29-
* process.code(
30-
* {code: "foo: function(){"},
31-
* function(newDoc){
32-
* newDoc.type //-> "function"
33-
* }
24+
* processCode({
25+
* code: "foo: function(){"
26+
* },
27+
* function(newDoc) {
28+
* newDoc.type //-> "function"
29+
* }
3430
* )
3531
*/
3632
module.exports = function(options, callback){

process/code_and_comment.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ var typeCheckReg = /^\s*@(\w+)/;
99
*
1010
* @signature `processCodeAndComment(options, callback)`
1111
*
12-
* Processes a code suggestion and then a comment and produces a
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
1315
* [bit-docs/types/docObject].
1416
*
15-
* @param {bit-docs/types/processOptions} options An options object that
16-
* contains the code and comment to process.
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-
* @param {function(bit-docs/types/docObject,bit-docs/types/docObject)} callback(newDoc,newScope)
23+
* @param {bit-docs/types/processorCallback} callback
1924
*
20-
* A function that is called back with a [bit-docs/types/docObject] created
21-
* from the code and the scope `docObject`. If no [bit-docs/types/docObject] is
22-
* created, `newDoc` will be null.
23-
*
24-
* @option newDoc the new documentation object
25-
* @option newScope the new scope
25+
* Callback to call with the new [bit-docs/types/docObject].
2626
*/
2727
module.exports = function(options, callback){
2828
var self = this;

tags/class.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,40 @@ var funcMatch = /(?:([\w\.\$]+)|(["'][^"']+["']))\s*[=]\s*function\s?\(([^\)]*)/
55
var codeMatch = /([\w\.\$]+?).extend\(\s*["']([^"']*)["']/;
66

77
/**
8-
* @parent bit-docs-js/tags
9-
* @module {bit-docs-process-tags/tag} bit-docs-js/tags/class @class
10-
* @hide
8+
* @parent bit-docs-js/modules
9+
* @module {bit-docs-process-tags/types/tag} bit-docs-js/tags/class
1110
*
12-
* DEPRECATED: Gets converted to [bit-docs-js/tags/constructor].
13-
*
14-
* @signature `@class NAME [TITLE]`
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].
1521
*/
1622
module.exports = {
17-
add: function(line, curData, scope, docMap){
23+
/**
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]`
40+
*/
41+
add: function(line){
1842
console.warn("Using the @class directive. It is deprecated!");
1943
// it's possible this has already been matched as something else
2044
// ... clear parent

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].

tags/codeend.js

Lines changed: 72 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,83 @@
1+
/**
2+
* @parent bit-docs-js/modules
3+
* @module {bit-docs-process-tags/types/tag} bit-docs-js/tags/codeend
4+
*
5+
* @description Use this module to add the [bit-docs-js/tag/codeend] tag.
6+
*
7+
* @signature `require('./tags/codeend');`
8+
*
9+
* @return {bit-docs-process-tags/types/tag} Tag object configured for the
10+
* [bit-docs-js/tag/codeend] tag.
11+
*
12+
* @body
13+
*/
14+
module.exports = {
115
/**
2-
* @hide
3-
* @parent bit-docs-js/tags
4-
* @module {bit-docs/types/tag} bit-docs-js/tags/codeend @codeend
16+
* @signature `add(line, data)`
517
*
6-
* @description
18+
* [bit-docs-process-tags/types/tag.add] for [bit-docs-js/tag/codeend].
719
*
8-
* Stops a code block.
20+
* @param {String} line Text from [bit-docs-js/tag/codeend] until the end
21+
* of line.
922
*
10-
* ### Example:
23+
* For example:
1124
*
12-
* @codestart
13-
*
14-
* /*
15-
* * @codestart
16-
* * /* @class
17-
* * * Person represents a human with a name. Read about the
18-
* * * animal class [Animal | here].
19-
* * * @constructor
20-
* * * You must pass in a name.
21-
* * * @param {String} name A person's name
22-
* * *|
23-
* * Person = function(name){
24-
* * this.name = name
25-
* * Person.count ++;
26-
* * }
27-
* * /* @Static *|
28-
* * steal.Object.extend(Person, {
29-
* * /* Number of People *|
30-
* * count: 0
31-
* * })
32-
* * /* @Prototype *|
33-
* * Person.prototype = {
34-
* * /* Returns a formal name
35-
* * * @return {String} the name with "Mrs." added
36-
* * *|
37-
* * fancyName : function(){
38-
* * return "Mrs. "+this.name;
39-
* * }
40-
* * }
41-
* * @codeend
42-
* *|
43-
*
44-
* @codeend
25+
* @codestart javascript
26+
* @@codeend
27+
* @codeend
28+
*
29+
* @param {Object} curData Custom data object hydrated by [bit-docs-js/tags/codestart].
30+
*
31+
* For example:
32+
*
33+
* ```js
34+
* {
35+
* type: 'javascript',
36+
* lines: ['/**', ' * @demo demos/example.html 300', ' *|'],
37+
* last: {
38+
* code: '@demo PATH [HEIGHT]',
39+
* description: '\n',
40+
* params: []
41+
* },
42+
* _last: undefined
43+
* }
44+
* ```
45+
*
46+
* @return {bit-docs-process-tags/types/processTagsCommand} `['poppop', '...']`.
47+
*
48+
* For example:
49+
*
50+
* @codestart javascript
51+
* [
52+
* 'poppop',
53+
* '```javascript\n/**\n * @demo demos/example.html 300\n *|\n```'
54+
* ]
55+
* @codeend
4556
*/
46-
module.exports = {
47-
add: function( line, data ) {
57+
add: function( line, data ) {
58+
if (!data.lines ) {
59+
console.warn('you probably have a @codeend without a @codestart')
60+
}
4861

49-
if (!data.lines ) {
50-
console.warn('you probably have a @codeend without a @codestart')
51-
}
62+
var joined = data.lines.join("\n");
5263

53-
var joined = data.lines.join("\n");
64+
if ( data.type == "javascript" || data.type == "js") { //convert comments
65+
joined = joined.replace(/\*\|/g, "*/")
66+
}
5467

55-
if ( data.type == "javascript" || data.type == "js") { //convert comments
56-
joined = joined.replace(/\*\|/g, "*/")
57-
}
58-
var out = "```" + data.type + "\n"
59-
+ joined.replace(/&lt;/g,"<")
60-
.replace(/&gt;/g,">")
61-
.replace(/&amp;/g,"&") +
68+
var out = "```" + data.type + "\n"
69+
+ joined.replace(/&lt;/g,"<")
70+
.replace(/&gt;/g,">")
71+
.replace(/&amp;/g,"&") +
6272
"\n```";
6373

64-
return ["poppop", out];
65-
},
66-
keepStack: true
67-
};
74+
return ["poppop", out];
75+
},
76+
/**
77+
* @property {Boolean} keepStack
78+
*
79+
* [bit-docs-process-tags/types/tag.keepStack] set `true` for
80+
* [bit-docs-js/tag/codeend].
81+
*/
82+
keepStack: true
83+
};

0 commit comments

Comments
 (0)