Skip to content

Commit afdd540

Browse files
authored
chore(docs): improve component name formatting (#6014)
1 parent 70d4965 commit afdd540

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

docs/components/componentdoc.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@
299299
import Vue from 'vue'
300300
import commonProps from '../common-props.json'
301301
import { defaultConfig } from '../content'
302-
import { kebabCase } from '../utils'
302+
import { getComponentName, getCleanComponentName, kebabCase } from '../utils'
303303
import AnchoredHeading from './anchored-heading'
304304
305305
export default {
@@ -478,13 +478,13 @@ export default {
478478
slotsItems() {
479479
// We use object spread here so that `_showDetails` doesn't
480480
// mutate the original array objects
481-
return this.slots ? this.slots.map(s => ({ ...s })) : []
481+
return this.slots ? this.slots.map(slot => ({ ...slot })) : []
482482
},
483483
componentName() {
484-
return kebabCase(this.component).replace('{', '-{')
484+
return getComponentName(this.component)
485485
},
486486
componentNameClean() {
487-
return this.componentName.replace('{', '').replace('}', '')
487+
return getCleanComponentName(this.component)
488488
},
489489
tag() {
490490
return `<${this.componentName}>`

docs/components/importdoc.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
<script>
124124
import startCase from 'lodash/startCase'
125125
import hljs from '../utils/hljs'
126-
import { kebabCase } from '../utils'
126+
import { getComponentName, kebabCase } from '../utils'
127127
import AnchoredHeading from './anchored-heading'
128128
129129
const importPath = 'bootstrap-vue'
@@ -196,7 +196,7 @@ export default {
196196
const firstComponentImport = this.componentImports[0]
197197
return [
198198
`import { ${firstComponent} } from '${firstComponentImport.importPath}'`,
199-
`Vue.component('${this.componentName(firstComponent)}', ${firstComponent})`
199+
`Vue.component('${getComponentName(firstComponent)}', ${firstComponent})`
200200
].join('\n')
201201
},
202202
directiveImportCode() {
@@ -221,11 +221,8 @@ export default {
221221
})
222222
},
223223
methods: {
224-
componentName(component) {
225-
return kebabCase(component).replace('{', '-{')
226-
},
227224
componentTag(component) {
228-
return `<${this.componentName(component)}>`
225+
return `<${getComponentName(component)}>`
229226
},
230227
directiveName(directive) {
231228
return kebabCase(directive)

docs/utils/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
const RX_HYPHENATE = /\B([A-Z])/g
22

33
// Converts PascalCase or camelCase to kebab-case
4-
export const kebabCase = str => {
5-
return str.replace(RX_HYPHENATE, '-$1').toLowerCase()
6-
}
4+
export const kebabCase = value => value.replace(RX_HYPHENATE, '-$1').toLowerCase()
75

86
// Parse a fully qualified version from a string
97
export const parseVersion = version => {
@@ -17,6 +15,9 @@ export const parseFullVersion = version => {
1715
return matches.length > 0 ? matches[0] : ''
1816
}
1917

18+
export const getComponentName = component => kebabCase(component).replace(/{/g, '-{')
19+
export const getCleanComponentName = component => getComponentName(component).replace(/({|})/g, '')
20+
2021
export const parseUrl = value => {
2122
const anchor = document.createElement('a')
2223
anchor.href = value
@@ -93,8 +94,8 @@ export const updateMetaTOC = (tocData = {}, meta = null) => {
9394
componentToc.push(
9495
// Add component sub-headings
9596
...meta.components.map(({ component }) => {
96-
const tag = kebabCase(component).replace('{', '-{')
97-
const hash = `#comp-ref-${tag}`.replace('{', '').replace('}', '')
97+
const tag = getComponentName(component)
98+
const hash = `#comp-ref-${getCleanComponentName(tag)}`
9899
return { label: `&lt;${tag}&gt;`, href: hash }
99100
}),
100101
// Add component import sub-heading

0 commit comments

Comments
 (0)