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

Commit 9eb28b0

Browse files
authored
Merge pull request #62 from vue-styleguidist/feat-noscript
Allow documented components not to have a script block
2 parents ec98f47 + d9fce8d commit 9eb28b0

File tree

5 files changed

+59
-10
lines changed

5 files changed

+59
-10
lines changed

.travis.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
language: node_js
22
node_js:
3-
- 9
4-
install:
5-
# Use npm 5.7.x since it has introduced `npm ci`
6-
- if [[ `npm -v` != 5.7* ]]; then npm install -g npm@'>=5.7.1'; fi
7-
- npm ci
3+
- 10
84
branches:
9-
except:
10-
- /^v\d+\.\d+\.\d+$/
5+
only:
6+
- master
117
script:
128
- npm run test
139
stages:

src/utils/getSandbox.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import parseModule from './parseModule'
77
module.exports = function getSandbox(stateDoc, file) {
88
const parsedSource = parseModule(stateDoc.jscodeRequest, file, stateDoc.jscodeLang)
99
const sandbox = evalComponentCode(parsedSource).exports
10+
sandbox.default = sandbox.default || {}
1011
const component = sandbox.default
1112
const listRequire = getSourceInRequire(parsedSource, file)
1213
const mixins = getMixin(listRequire).reverse()

src/utils/stateDoc.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ class stateDoc {
2323
if (this.isMainComponent(file) && this.sourceComponent !== source) {
2424
const parts = parser(source, 'name')
2525
this.slots = getSlots(parts)
26-
this.jscodeRequest = getComponentModuleJSCode(parts, source, file)
27-
this.jscodeLang = parts.script.lang
28-
this.docComponent = this.getDocFile(this.jscodeRequest, file, this.jscodeLang)
26+
this.docComponent = []
27+
if (parts.script) {
28+
this.jscodeRequest = getComponentModuleJSCode(parts, source, file)
29+
this.jscodeLang = parts.script.lang
30+
this.docComponent = this.getDocFile(this.jscodeRequest, file, this.jscodeLang)
31+
}
2932
}
3033
}
3134

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<template>
2+
<button class="buttonComponent">
3+
<!-- @slot Use this slot default -->
4+
<slot/>
5+
</button>
6+
</template>
7+
8+
<style scoped>
9+
.button {
10+
padding: 0.5em 1.5em;
11+
color: #666;
12+
background-color: #fff;
13+
border: 1px solid blue;
14+
border-radius: 0.3em;
15+
text-align: center;
16+
vertical-align: middle;
17+
cursor: pointer;
18+
}
19+
</style>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const path = require('path')
2+
const expect = require('chai').expect
3+
4+
const api = require('../../../dist/main')
5+
const button = path.join(__dirname, './MyButton.vue')
6+
let docButton
7+
8+
describe.only('tests button', () => {
9+
before(function(done) {
10+
this.timeout(10000)
11+
docButton = api.parse(button)
12+
done()
13+
})
14+
15+
it('should return an object', () => {
16+
expect(docButton).to.be.an('object')
17+
})
18+
19+
it('should have a slot.', () => {
20+
expect(Object.keys(docButton['slots']).length).to.equal(1)
21+
})
22+
23+
it('should have a default slot.', () => {
24+
expect(typeof docButton['slots']['default'] !== 'undefined').to.be.true
25+
})
26+
27+
it('the default slot should have "Use this slot default" as description', () => {
28+
expect(docButton['slots']['default']['description']).to.equal('Use this slot default')
29+
})
30+
})

0 commit comments

Comments
 (0)