Skip to content
This repository was archived by the owner on Mar 8, 2019. It is now read-only.

Commit fb2bd4b

Browse files
committed
The mixins are documented and the ignore tag corrected
1 parent ca724f1 commit fb2bd4b

19 files changed

+342
-155
lines changed

README.md

Lines changed: 88 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,27 @@ var vueDocs = require('vue-docgen-api');
2222
var componentInfo = vueDocs.parse(filePath);
2323
```
2424

25+
26+
## parse(filePath \[, webpackConfig \])
27+
28+
| Parameter | Type | Description |
29+
| -------------- | ------ | --------------- |
30+
| filePath | string | The file path |
31+
| webpackConfig | object | Optional argument, extracts the necessary loaders to document the component. |
32+
33+
2534
## Using JSDoc tags
2635

2736
You can use the following [JSDoc][] tags when documenting components, props and methods.
2837

29-
## PropTypes
30-
31-
### Example
38+
## Example
3239

3340
For the following component
3441

3542
```html
3643
<template>
3744
<table class="grid">
38-
<thead>
39-
<tr>
40-
<th v-for="key in columns"
41-
@click="sortBy(key)"
42-
:class="{ active: sortKey == key }">
43-
{{ key | capitalize }}
44-
<span class="arrow" :class="sortOrders[key] > 0 ? 'asc' : 'dsc'">
45-
</span>
46-
</th>
47-
</tr>
48-
</thead>
49-
<tbody>
50-
<tr v-for="entry in filteredData">
51-
<td v-for="key in columns">
52-
{{entry[key]}}
53-
</td>
54-
</tr>
55-
</tbody>
45+
<!-- -->
5646
</table>
5747
</template>
5848

@@ -78,7 +68,7 @@ export default {
7868
*/
7969
msg: {
8070
type: [String, Number],
81-
default: 'Ejemplo'
71+
default: text
8272
},
8373
/**
8474
* describe data
@@ -158,12 +148,6 @@ export default {
158148
}
159149
}
160150
</script>
161-
162-
<style scoped>
163-
.grid {
164-
margin-bottom: 20px;
165-
}
166-
</style>
167151
```
168152

169153
we are getting this output:
@@ -235,15 +219,15 @@ we are getting this output:
235219
}
236220
}
237221
],
238-
"displayName": "Grid",
222+
"displayName": "grid",
239223
"props": {
240224
"msg": {
241225
"type": {
242226
"name": "string|number"
243227
},
244228
"required": "",
245229
"defaultValue": {
246-
"value": "\"Ejemplo\"",
230+
"value": "\"this is a secret\"",
247231
"computed": false
248232
},
249233
"tags": {
@@ -286,6 +270,26 @@ we are getting this output:
286270
"name": "array"
287271
},
288272
"description": "get columns list"
273+
},
274+
"filterKey": {
275+
"type": {
276+
"name": "string"
277+
},
278+
"required": "",
279+
"defaultValue": {
280+
"value": "\"example\"",
281+
"computed": false
282+
},
283+
"tags": {
284+
"ignore": [
285+
{
286+
"title": "ignore",
287+
"description": true
288+
}
289+
]
290+
},
291+
"comment": "/**\n * filter key\n * @ignore\n */",
292+
"description": "filter key"
289293
}
290294
},
291295
"comment": "/**\n * This is an example of creating a reusable grid component and using it with external data.\n * @version 1.0.5\n * @author [Rafael](https://github.com/rafaesc92)\n * @since Version 1.0.1\n */",
@@ -310,6 +314,60 @@ we are getting this output:
310314
]
311315
}
312316
}
317+
318+
```
319+
320+
## Mixins
321+
If you import a mixin, for it to be documented you need to add in the header the mixin tag **@mixin**, for example
322+
323+
```javascript
324+
// src/mixins/colorMixin.js
325+
326+
/**
327+
* @mixin
328+
*/
329+
module.exports = {
330+
props: {
331+
/**
332+
* The color for the button example
333+
*/
334+
color: {
335+
type: String,
336+
default: '#333'
337+
},
338+
}
339+
}
340+
```
341+
342+
```html
343+
<template>
344+
<!-- -->
345+
</template>
346+
<script>
347+
// src/components/Button/Button.vue
348+
349+
import colorMixin from '../../mixins/colorMixin';
350+
export default {
351+
name: 'buttonComponent',
352+
mixins: [colorMixin],
353+
props: {
354+
/**
355+
* The size of the button
356+
* `small, normal, large`
357+
*/
358+
size: {
359+
default: 'normal'
360+
},
361+
/**
362+
* Add custom click actions.
363+
**/
364+
onCustomClick: {
365+
default: () => () => null,
366+
},
367+
},
368+
/* ... */
369+
}
370+
</script>
313371
```
314372

315373
## Change log

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-docgen-api",
3-
"version": "1.0.6",
3+
"version": "2.0.0",
44
"description": "Toolbox to extract information from Vue component files for documentation generation purposes.",
55
"bugs": {
66
"url": "https://github.com/vue-styleguidist/vue-docgen-api/issues"
@@ -10,7 +10,7 @@
1010
"build": "babel src/ -d --out-dir dist/ --ignore __tests__,__mocks__",
1111
"build:watch": "babel src/ --watch -d --out-dir dist/ --ignore __tests__,__mocks__",
1212
"prepublish": "npm run build",
13-
"test": "mocha -c --recursive src/__tests__ tests src/utils/__tests__"
13+
"test": "mocha -c src/__tests__ tests src/utils/__tests__"
1414
},
1515
"repository": {
1616
"type": "git",
@@ -27,16 +27,18 @@
2727
"homepage": "https://github.com/vue-styleguidist/vue-docgen-api#readme",
2828
"dependencies": {
2929
"babel-core": "^6.25.0",
30-
"babel-preset-env": "^1.5.2",
31-
"babel-preset-flow": "^6.23.0",
3230
"babel-plugin-transform-object-rest-spread": "^6.23.0",
3331
"babel-plugin-transform-runtime": "^6.23.0",
32+
"babel-preset-env": "^1.5.2",
33+
"babel-preset-es2015": "^6.24.1",
34+
"babel-preset-flow": "^6.23.0",
3435
"doctrine": "^2.0.0",
36+
"enhanced-require": "^0.5.0-beta6",
37+
"hash-sum": "^1.0.2",
3538
"jsdoc-api": "^3.0.0",
39+
"lru-cache": "^4.1.0",
3640
"vue-template-compiler": "^2.3.4",
37-
"babel-preset-es2015": "^6.24.1",
38-
"hash-sum": "^1.0.2",
39-
"lru-cache": "^4.1.0"
41+
"vue-webpack-loaders": "^1.0.4"
4042
},
4143
"devDependencies": {
4244
"babel-eslint": "^7.2.3",

src/loaders/mixin-loader.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import stateDoc from '../utils/stateDoc';
2+
3+
module.exports = function(source) {
4+
/* istanbul ignore if */
5+
if (this.cacheable) {
6+
this.cacheable();
7+
}
8+
const file = this.request.split('!').pop();
9+
stateDoc.saveMixin(source, file);
10+
return source;
11+
}

src/loaders/vuedoc-loader.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import stateDoc from '../utils/stateDoc';
2+
3+
module.exports = function(source) {
4+
/* istanbul ignore if */
5+
if (this.cacheable) {
6+
this.cacheable();
7+
}
8+
const file = this.request.split('!').pop();
9+
stateDoc.saveComponent(source, file);
10+
return source;
11+
}

src/parse.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import fs from 'fs';
22
import * as utils from './utils';
3+
import stateDoc from './utils/stateDoc';
34

4-
export default function parse(file) {
5+
export default function parse(file, webpackConfig) {
56
const source = fs.readFileSync(file, { encoding: 'utf-8' });
67
if (source === '') {
78
throw new Error('The document is empty');
89
}
9-
const jscodeReqest = utils.getComponentModuleJSCode(source, file);
10-
const component = utils.getSandbox(jscodeReqest).default;
11-
const doc = utils.getDocFile(jscodeReqest, file);
12-
const vueDoc = utils.getVueDoc(doc, component);
10+
stateDoc.file = file;
11+
const component = utils.getComponent(source, file, webpackConfig);
12+
const vueDoc = utils.getVueDoc(stateDoc.docComponent, component);
1313
return vueDoc;
1414
}

src/utils/getComponent.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import optionsWebpack from './optionsWebpack';
2+
const path = require('path');
3+
4+
export default function getComponentModuleJSCode (source, file, webpackConfig){
5+
let myRequire;
6+
if (webpackConfig && webpackConfig.module && webpackConfig.module.loaders) {
7+
optionsWebpack.module.loaders = webpackConfig.module.loaders;
8+
}
9+
let loaders = optionsWebpack.module.loaders;
10+
loaders.push({
11+
test: /\.vue$/,
12+
exclude: /node_modules/,
13+
loader: path.resolve(__dirname, '../loaders/vuedoc-loader.js'),
14+
})
15+
16+
loaders.unshift({
17+
test: /\.js$/,
18+
exclude: /node_modules/,
19+
loader: path.resolve(__dirname, '../loaders/mixin-loader.js'),
20+
});
21+
22+
myRequire = require('enhanced-require')(module, optionsWebpack);
23+
return myRequire(file)
24+
}

src/utils/getProp.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export default function getProp(prop, docPart){
3535
var func = prop.default.toString().replace(fnNameMatchRegex, 'function');
3636
value = JSON.parse(JSON.stringify(func.replace(/\s\s+/g, ' ')))
3737
} else {
38+
if (!prop.type) {
39+
obj['type'] = { name: typeof prop.default }
40+
}
3841
value = JSON.stringify(prop.default)
3942
}
4043
obj['defaultValue'] = {

src/utils/getSandbox.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/utils/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export {default as getComponentModuleJSCode} from './getComponentModuleJSCode';
2+
export {default as getComponent} from './getComponent';
23
export {default as getDocFile} from './getDocFile';
34
export {default as getVueDoc} from './getVueDoc';
45
export {default as getSandbox} from './getSandbox';

src/utils/optionsWebpack.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
let loaders = require('vue-webpack-loaders');
2+
3+
export default {
4+
debug: true,
5+
recursive: true,
6+
resolve: {
7+
modulesDirectories: ['node_modules', 'bower_components'],
8+
},
9+
module: {
10+
loaders,
11+
},
12+
}

0 commit comments

Comments
 (0)