-
Notifications
You must be signed in to change notification settings - Fork 1
/
Readme.tpl
133 lines (106 loc) · 4 KB
/
Readme.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# nodoc
A simple and 'low-level' source code comments parser and documentation generator.
> Oops, this doc is generated by nodoc itself !
[![NPM version](https://badge.fury.io/js/nodoc.svg)](http://badge.fury.io/js/nodoc)
[![Deps Up to Date](https://david-dm.org/dracupid/nodoc.svg?style=flat)](https://david-dm.org/dracupid/nodoc)
## Supported Languages
- CoffeeScript
> Other languagage, especially javascript, will be supported soon.
#### Language Name Aliases
Use lower case, used both for language option and extname recognization.
```javascript
<%= alias %>
```
## Usage
0. Convert comment block to an object as following:
#### Parsed Comment Object
```javascript
{
name: 'parseFile',
description: 'Parse source code from file. Use Promise instead of callback',
tags: [ [Object], [Object], [Object], [Object] ], // tag objects array
lineNum: 78
}
```
#### Tag Object
```javascript
{
tagName: 'param',
type: 'string', // only @param, @property, @option, @return
name: 'srcPath', // only @param, @property, @option
description: 'Path of source code file'
}
```
Tags are only key-value pairs, except `@param`, `@return`, `@property`, `@option`. They may have extra type and (maybe) name.
```javascript
var doc = require('nodoc');
// From file
doc.parser.parseFile('./src/parser/index.coffee').then(function(res){});
res = doc.parser.parseFileSync('./src/parser/index.coffee')
//From source code
doc.parser.parse('A piece of source code', 'coffee').then(function(res){});
```
0. Generate gitHub flavored markdown API doc from comments.
```javascript
var doc = require('nodoc'),
fs = require('fs');
doc.generate('./src/parser/index.coffee', {
moduleName: 'parser',
moduleDesc: 'This is a parser!'
}).then(function(markdown){
fs.writeFileSync('./api.md', markdown);
});
```
In this case, predefined tags will make effects.
### Predefined tags
+ `@private`: Hidden in the generated document.
+ `@nodoc`: Same behavior as `@private`, but they are differ in semantics.
+ `@alias`: Shown as an addition of function name.
+ `@prefix`: Add a custom prefix to function name.
+ `@noPrefix`: Only preserve the real name, regard `util.promisify` as `promisify`.
## Comment format
Of course, you need to write your comments in a standard way to make a parser work.
Such as:
```coffeescript
###*
* Generate formatted markdown API document from source code
* @param {string} srcPath Path of source code file
* @param {Object={}} opts Options, optional
* @return {Promise} Resolve formatted markdown
* @example
* ` ``javascript
* nodoc.generate('./src/index.coffee').then(function(md){
* console.log(md);
* });
* ` ``
###
```
As you can see, you can use **markdown** in your comment!
> Reference: [jsdoc](http://usejsdoc.org/)
## API
<%= api %>
## Parser Module
<%= parser %>
## Write your own template
Nodoc uses [underscore template](http://underscorejs.org/#template) to render the markdown template. You need to realize that template is not HTML's privilege.
If you don't want to use the default template, you can use your own.
```javascript
doc.generate('./src/parser/index.coffee', {
template: 'Here is your own template'
tplData: {} // You can use this object to add custom data to your template
}).then(function(markdown){});
```
However, if you even want to use a alternative template engine, please use parser module directly.
## Write your own language parser
If the languages you use is not supported by nodoc, you can write your own parser and register it by `parser.setParser`. If you want your parser to be a part of nodoc, please make a pull request, it is warmly welcomed.
A parser should provide follow APIs:
### Parser API
<%= parserAPI %>
### Rule
A parser uses and is supposed to expose the rules it uses to parse the code.
#### Rules for coffee parser
```javascript
<%= coffeeRule %>
```
### License
MIT