Skip to content

Commit 5d218b0

Browse files
hqhhuangDobromir Hristov
andauthored
Add support to render References with human readable name in plain text (#26)
Co-authored-by: Dobromir Hristov <[email protected]>
1 parent c0ea733 commit 5d218b0

File tree

4 files changed

+76
-3
lines changed

4 files changed

+76
-3
lines changed

src/components/ContentNode.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ function renderNode(createElement, references) {
313313
kind: reference.kind,
314314
role: reference.role,
315315
isActive: node.isActive,
316+
ideTitle: reference.ideTitle,
317+
titleStyle: reference.titleStyle,
316318
},
317319
}, (
318320
titleInlineContent ? renderChildren(titleInlineContent) : titlePlainText

src/components/ContentNode/Reference.vue

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,17 @@ export default {
4646
return this.kind === 'symbol'
4747
&& (this.role === TopicRole.symbol || this.role === TopicRole.dictionarySymbol);
4848
},
49+
isDisplaySymbol({ isSymbolReference, titleStyle, ideTitle }) {
50+
return ideTitle ? (isSymbolReference && titleStyle === 'symbol') : isSymbolReference;
51+
},
4952
refComponent() {
50-
if (this.isInternal) {
51-
return this.isSymbolReference ? ReferenceInternalSymbol : ReferenceInternal;
53+
if (!this.isInternal) {
54+
return ReferenceExternal;
55+
}
56+
if (this.isDisplaySymbol) {
57+
return ReferenceInternalSymbol;
5258
}
53-
return ReferenceExternal;
59+
return ReferenceInternal;
5460
},
5561
urlWithParams({ isInternal }) {
5662
return isInternal ? buildUrl(this.url, this.$route.query) : this.url;
@@ -77,6 +83,14 @@ export default {
7783
required: false,
7884
default: true,
7985
},
86+
ideTitle: {
87+
type: String,
88+
required: false,
89+
},
90+
titleStyle: {
91+
type: String,
92+
required: false,
93+
},
8094
},
8195
};
8296
</script>

tests/unit/components/ContentNode.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,16 @@ describe('ContentNode', () => {
412412
foobar: {
413413
title: 'FooBar',
414414
url: '/foo/bar',
415+
ideTitle: 'IDETitle',
416+
titleStyle: 'symbol',
415417
},
416418
});
417419

418420
const reference = wrapper.find('.content').find(Reference);
419421
expect(reference.exists()).toBe(true);
420422
expect(reference.props('url')).toBe('/foo/bar');
423+
expect(reference.props('ideTitle')).toBe('IDETitle');
424+
expect(reference.props('titleStyle')).toBe('symbol');
421425
expect(reference.isEmpty()).toBe(false);
422426
expect(reference.text()).toBe('FooBar');
423427
});

tests/unit/components/ContentNode/Reference.spec.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,23 @@ describe('Reference', () => {
7878
expect(ref.props('url')).toBe('/documentation/uikit/uiview');
7979
});
8080

81+
it('renders a `ReferenceInternal` for external "symbol" kind references with human readable name', () => {
82+
const wrapper = shallowMount(Reference, {
83+
localVue,
84+
router,
85+
propsData: {
86+
url: '/documentation/uikit/uiview',
87+
kind: 'symbol',
88+
role: TopicRole.symbol,
89+
ideTitle: 'UIView',
90+
},
91+
slots: { default: 'UIView' },
92+
});
93+
const ref = wrapper.find(ReferenceInternal);
94+
expect(ref.exists()).toBe(true);
95+
expect(ref.props('url')).toBe('/documentation/uikit/uiview');
96+
});
97+
8198
it('renders a `ReferenceInternalSymbol` for external "dictionarySymbol" kind references', () => {
8299
const wrapper = shallowMount(Reference, {
83100
localVue,
@@ -94,6 +111,42 @@ describe('Reference', () => {
94111
expect(ref.props('url')).toBe('/documentation/uikit/uiview');
95112
});
96113

114+
it('renders a `ReferenceInternal` for external "dictionarySymbol" kind references with a human readable name', () => {
115+
const wrapper = shallowMount(Reference, {
116+
localVue,
117+
router,
118+
propsData: {
119+
url: '/documentation/uikit/uiview',
120+
kind: 'symbol',
121+
role: TopicRole.dictionarySymbol,
122+
ideTitle: 'UIView',
123+
titleStyle: 'title',
124+
},
125+
slots: { default: 'UIView' },
126+
});
127+
const ref = wrapper.find(ReferenceInternal);
128+
expect(ref.exists()).toBe(true);
129+
expect(ref.props('url')).toBe('/documentation/uikit/uiview');
130+
});
131+
132+
it('renders a `ReferenceInternalSymbol` for external "dictionarySymbol" kind references with `symbol` title style', () => {
133+
const wrapper = shallowMount(Reference, {
134+
localVue,
135+
router,
136+
propsData: {
137+
url: '/documentation/uikit/uiview',
138+
kind: 'symbol',
139+
role: TopicRole.dictionarySymbol,
140+
ideTitle: 'UIView',
141+
titleStyle: 'symbol',
142+
},
143+
slots: { default: 'UIView' },
144+
});
145+
const ref = wrapper.find(ReferenceInternalSymbol);
146+
expect(ref.exists()).toBe(true);
147+
expect(ref.props('url')).toBe('/documentation/uikit/uiview');
148+
});
149+
97150
it('renders a `ReferenceInternal` for references that have a "role" other than "symbol"', () => {
98151
const wrapper = shallowMount(Reference, {
99152
localVue,

0 commit comments

Comments
 (0)