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

Commit 6563c32

Browse files
committed
Fixed when the component has no description
1 parent 42c669f commit 6563c32

File tree

4 files changed

+69
-9
lines changed

4 files changed

+69
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-docgen-api",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
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"

src/utils/getVueDoc.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IGNORE_DEFAULT, getDescription, getComment } from './variables';
1+
import { IGNORE_DEFAULT, getDescription, getComment , EMPTY} from './variables';
22
import processTags from './processTags';
33
import processProps from './processProps';
44
import processMethods from './processMethods';
@@ -32,9 +32,14 @@ export default function getVueDoc(docFile, component) {
3232
const docComponent = docFile.filter(comment => {
3333
return comment.longname === 'module.exports'
3434
})[0];
35-
const description = getDescription(docComponent);
36-
const comment = getComment(docComponent);
37-
const tags = processTags(docComponent, IGNORE_DEFAULT);
35+
let description = EMPTY;
36+
let comment = EMPTY;
37+
let tags = {};
38+
if (docComponent) {
39+
description = getDescription(docComponent);
40+
comment = getComment(docComponent);
41+
tags = processTags(docComponent, IGNORE_DEFAULT);
42+
}
3843
const props = processProps(docFile, component);
3944
const methods = processMethods(docFile, component);
4045

tests/components/button/Button.vue

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<template>
2+
<button class="button" @click.prevent="onClick">
3+
<slot></slot>
4+
</button>
5+
</template>
6+
7+
<script>
8+
9+
export default {
10+
name: 'button',
11+
props: {
12+
/**
13+
* The color for the button
14+
*/
15+
color: {
16+
type: String,
17+
default: '#333'
18+
},
19+
/**
20+
* The size of the button
21+
* `small, normal, large`
22+
*/
23+
size: {
24+
type: Number,
25+
default: 'normal'
26+
},
27+
},
28+
data () {
29+
return {
30+
count : 0
31+
}
32+
},
33+
methods: {
34+
onClick(){
35+
console.log('Hola Mundo')
36+
}
37+
}
38+
}
39+
</script>
40+
41+
<style scoped>
42+
.button {
43+
padding: .5em 1.5em;
44+
color: #666;
45+
background-color: #fff;
46+
border: 1px solid blue;
47+
border-radius: .3em;
48+
text-align: center;
49+
vertical-align: middle;
50+
cursor: pointer;
51+
}
52+
</style>

tests/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
const path = require('path');
22
var api = require('../dist/main');
3-
var file = path.join(__dirname, './components/grid/Grid.vue');
3+
var grid = path.join(__dirname, './components/grid/Grid.vue');
4+
var button = path.join(__dirname, './components/button/Button.vue');
45
const expect = require("chai").expect;
56

67
describe('tests', () => {
78
it('should not return error', () => {
8-
expect(() => {api.parse(file)}).to.not.throw()
9+
expect(() => {api.parse(grid)}).to.not.throw()
10+
expect(() => {api.parse(button)}).to.not.throw()
911
})
1012

11-
const docJson = api.parse(file);
12-
console.log(JSON.stringify(docJson, null, 2));
13+
const docJson = api.parse(grid);
14+
const docButtonJson = api.parse(button);
15+
console.log(JSON.stringify(docButtonJson, null, 2));
1316

1417
it('should return an object', () => {
1518
expect(docJson).to.be.an('object')

0 commit comments

Comments
 (0)