Skip to content

Commit 8c5418b

Browse files
authored
Revert #40 and #683 (#690)
1 parent 43facbe commit 8c5418b

File tree

5 files changed

+95
-96
lines changed

5 files changed

+95
-96
lines changed

src/components/ContentNode.vue

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import CodeVoice from './ContentNode/CodeVoice.vue';
1717
import DictionaryExample from './ContentNode/DictionaryExample.vue';
1818
import EndpointExample from './ContentNode/EndpointExample.vue';
1919
import Figure from './ContentNode/Figure.vue';
20-
import Caption from './ContentNode/Caption.vue';
20+
import FigureCaption from './ContentNode/FigureCaption.vue';
2121
import InlineImage from './ContentNode/InlineImage.vue';
2222
import Reference from './ContentNode/Reference.vue';
2323
import Table from './ContentNode/Table.vue';
@@ -230,8 +230,8 @@ function renderNode(createElement, references) {
230230
if ((title && abstract.length) || abstract.length) {
231231
// if there is a `title`, it should be above, otherwise below
232232
figureContent.splice(title ? 0 : 1, 0,
233-
createElement(Caption, {
234-
props: { title, tag: 'figcaption', centered: !title },
233+
createElement(FigureCaption, {
234+
props: { title, centered: !title },
235235
}, renderChildren(abstract)));
236236
}
237237
return createElement(Figure, { props: { anchor } }, figureContent);
@@ -297,27 +297,18 @@ function renderNode(createElement, references) {
297297
renderChildren(node.inlineContent)
298298
));
299299
}
300-
case BlockType.table: {
301-
const tableChildren = [];
302-
if (node.metadata && node.metadata.anchor && node.metadata.title) {
303-
tableChildren.push(
304-
createElement(Caption,
305-
{ props: { title: node.metadata.title } },
306-
renderChildren(node.metadata.abstract)),
307-
);
300+
case BlockType.table:
301+
if (node.metadata && node.metadata.anchor) {
302+
return renderFigure(node);
308303
}
309-
tableChildren.push(renderTableChildren(
310-
node.rows, node.header, node.extendedData, node.alignments,
311-
));
312-
return createElement(
313-
Table,
314-
{
315-
attrs: { id: node.metadata && node.metadata.anchor },
316-
props: { spanned: !!node.extendedData },
304+
305+
return createElement(Table, {
306+
props: {
307+
spanned: !!node.extendedData,
317308
},
318-
tableChildren,
319-
);
320-
}
309+
}, (
310+
renderTableChildren(node.rows, node.header, node.extendedData, node.alignments)
311+
));
321312
case BlockType.termList:
322313
return createElement('dl', {}, node.items.map(({ term, definition }) => [
323314
createElement('dt', {}, (

src/components/ContentNode/Caption.vue renamed to src/components/ContentNode/FigureCaption.vue

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
-->
1010

1111
<template>
12-
<component :is="tag" class="caption" :class="{ centered }">
12+
<figcaption class="caption" :class="{ centered }">
1313
<template v-if="title">
1414
<strong>{{ title }}</strong>&nbsp;<slot />
1515
</template>
1616
<template v-else>
1717
<slot />
1818
</template>
19-
</component>
19+
</figcaption>
2020
</template>
2121

2222
<script>
2323
export default {
24-
name: 'Caption',
24+
name: 'FigureCaption',
2525
props: {
2626
title: {
2727
type: String,
@@ -31,11 +31,6 @@ export default {
3131
type: Boolean,
3232
default: false,
3333
},
34-
tag: {
35-
type: String,
36-
required: false,
37-
default: () => 'caption',
38-
},
3934
},
4035
};
4136
</script>
@@ -44,7 +39,7 @@ export default {
4439
@import 'docc-render/styles/_core.scss';
4540
4641
.caption {
47-
@include font-styles(documentation-caption);
42+
@include font-styles(documentation-figcaption);
4843
4944
&:last-child {
5045
margin-top: var(--spacing-stacked-margin-large);
@@ -58,8 +53,4 @@ export default {
5853
/deep/ p {
5954
display: inline-block;
6055
}
61-
62-
caption {
63-
margin: 1rem 0;
64-
}
6556
</style>

src/styles/core/typography/_font-styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ $font-styles: (
153153
documentation-code-listing-number: (
154154
large: 12_18_normal_compact_mono,
155155
),
156-
documentation-caption: (
156+
documentation-figcaption: (
157157
large: 14_21,
158158
),
159159
documentation-declaration-link: (

tests/unit/components/ContentNode.spec.js

Lines changed: 68 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import ContentNode from 'docc-render/components/ContentNode.vue';
1616
import DictionaryExample from 'docc-render/components/ContentNode/DictionaryExample.vue';
1717
import EndpointExample from 'docc-render/components/ContentNode/EndpointExample.vue';
1818
import Figure from 'docc-render/components/ContentNode/Figure.vue';
19-
import Caption from 'docc-render/components/ContentNode/Caption.vue';
19+
import FigureCaption from 'docc-render/components/ContentNode/FigureCaption.vue';
2020
import InlineImage from 'docc-render/components/ContentNode/InlineImage.vue';
2121
import Reference from 'docc-render/components/ContentNode/Reference.vue';
2222
import Table from 'docc-render/components/ContentNode/Table.vue';
@@ -112,6 +112,29 @@ describe('ContentNode', () => {
112112
expect(codeListing.props('content')).toEqual(listing.code);
113113
expect(codeListing.isEmpty()).toBe(true);
114114
});
115+
116+
it('renders a `Figure`/`Figcaption` with metadata', () => {
117+
const metadata = {
118+
anchor: '42',
119+
title: 'Listing 42',
120+
abstract: [{
121+
type: 'paragraph',
122+
inlineContent: [{ type: 'text', text: 'blah' }],
123+
}],
124+
};
125+
const wrapper = mountWithItem({ ...listing, metadata });
126+
127+
const figure = wrapper.find(Figure);
128+
expect(figure.exists()).toBe(true);
129+
expect(figure.props('anchor')).toBe(metadata.anchor);
130+
expect(figure.contains(CodeListing)).toBe(true);
131+
132+
const caption = figure.find(FigureCaption);
133+
expect(caption.exists()).toBe(true);
134+
expect(caption.props('title')).toBe(metadata.title);
135+
expect(caption.contains('p')).toBe(true);
136+
expect(caption.text()).toContain('blah');
137+
});
115138
});
116139

117140
describe('with type="endpointExample"', () => {
@@ -691,7 +714,7 @@ describe('ContentNode', () => {
691714
}, {})).not.toThrow();
692715
});
693716

694-
it('renders a `Figure`/`Caption` with metadata', () => {
717+
it('renders a `Figure`/`FigureCaption` with metadata', () => {
695718
const metadata = {
696719
anchor: '42',
697720
title: 'Figure 42',
@@ -711,14 +734,14 @@ describe('ContentNode', () => {
711734
expect(figure.props('anchor')).toBe(metadata.anchor);
712735
expect(figure.contains(InlineImage)).toBe(true);
713736

714-
const caption = wrapper.find(Caption);
737+
const caption = wrapper.find(FigureCaption);
715738
expect(caption.exists()).toBe(true);
716739
expect(caption.contains('p')).toBe(true);
717740
expect(caption.props('title')).toBe(metadata.title);
718741
expect(caption.text()).toContain('blah');
719742
});
720743

721-
it('renders a `Figure`/`Caption` without an anchor, with text under the image', () => {
744+
it('renders a `Figure`/`FigureCaption` without an anchor, with text under the image', () => {
722745
const metadata = {
723746
abstract: [{
724747
type: 'paragraph',
@@ -736,7 +759,7 @@ describe('ContentNode', () => {
736759
expect(figure.props('anchor')).toBeFalsy();
737760
expect(figure.contains(InlineImage)).toBe(true);
738761

739-
const caption = wrapper.find(Caption);
762+
const caption = wrapper.find(FigureCaption);
740763
expect(caption.exists()).toBe(true);
741764
expect(caption.contains('p')).toBe(true);
742765
expect(caption.props('title')).toBeFalsy();
@@ -746,9 +769,9 @@ describe('ContentNode', () => {
746769
expect(figure.html()).toMatchInlineSnapshot(`
747770
<figure-stub>
748771
<inlineimage-stub alt="" variants="[object Object],[object Object]"></inlineimage-stub>
749-
<caption-stub centered="true" tag="figcaption">
772+
<figurecaption-stub centered="true">
750773
<p>blah</p>
751-
</caption-stub>
774+
</figurecaption-stub>
752775
</figure-stub>
753776
`);
754777
});
@@ -768,9 +791,9 @@ describe('ContentNode', () => {
768791
}, references);
769792
expect(wrapper.find(Figure).html()).toMatchInlineSnapshot(`
770793
<figure-stub>
771-
<caption-stub title="foo" tag="figcaption">
794+
<figurecaption-stub title="foo">
772795
<p>blah</p>
773-
</caption-stub>
796+
</figurecaption-stub>
774797
<inlineimage-stub alt="" variants="[object Object],[object Object]"></inlineimage-stub>
775798
</figure-stub>
776799
`);
@@ -793,7 +816,7 @@ describe('ContentNode', () => {
793816
expect(figure.props('anchor')).toBe('foo-figure');
794817
expect(figure.contains(InlineImage)).toBe(true);
795818

796-
expect(wrapper.find(Caption).exists()).toBe(false);
819+
expect(wrapper.find(FigureCaption).exists()).toBe(false);
797820
});
798821

799822
it('renders within a `DeviceFrame`', () => {
@@ -869,7 +892,7 @@ describe('ContentNode', () => {
869892
}, {})).not.toThrow();
870893
});
871894

872-
it('renders a `Figure`/`Caption` with metadata', () => {
895+
it('renders a `Figure`/`FigureCaption` with metadata', () => {
873896
const metadata = {
874897
anchor: 'foo',
875898
abstract: [{
@@ -888,16 +911,15 @@ describe('ContentNode', () => {
888911
expect(figure.props('anchor')).toBe('foo');
889912
expect(figure.contains(BlockVideo)).toBe(true);
890913

891-
const caption = wrapper.find(Caption);
914+
const caption = wrapper.find(FigureCaption);
892915
expect(caption.exists()).toBe(true);
893-
expect(caption.props('tag')).toBe('figcaption');
894916
expect(caption.contains('p')).toBe(true);
895917
expect(caption.props('title')).toBe(metadata.title);
896918
expect(caption.props('centered')).toBe(true);
897919
expect(caption.text()).toContain('blah');
898920
});
899921

900-
it('renders a `Figure`/`Caption` without an anchor, with text under the video', () => {
922+
it('renders a `Figure`/`FigureCaption` without an anchor, with text under the video', () => {
901923
const metadata = {
902924
abstract: [{
903925
type: 'paragraph',
@@ -915,7 +937,7 @@ describe('ContentNode', () => {
915937
expect(figure.props('anchor')).toBeFalsy();
916938
expect(figure.contains(BlockVideo)).toBe(true);
917939

918-
const caption = wrapper.find(Caption);
940+
const caption = wrapper.find(FigureCaption);
919941
expect(caption.exists()).toBe(true);
920942
expect(caption.contains('p')).toBe(true);
921943
expect(caption.props('title')).toBeFalsy();
@@ -925,9 +947,9 @@ describe('ContentNode', () => {
925947
expect(figure.html()).toMatchInlineSnapshot(`
926948
<figure-stub>
927949
<blockvideo-stub identifier="video.mp4"></blockvideo-stub>
928-
<caption-stub centered="true" tag="figcaption">
950+
<figurecaption-stub centered="true">
929951
<p>blah</p>
930-
</caption-stub>
952+
</figurecaption-stub>
931953
</figure-stub>
932954
`);
933955
});
@@ -1350,33 +1372,6 @@ describe('ContentNode', () => {
13501372
expect(table.findAll('tbody tr td').length).toBe(4);
13511373
});
13521374

1353-
it('renders a `Table` with metadata', () => {
1354-
const metadata = {
1355-
anchor: '42',
1356-
title: 'Listing 42',
1357-
abstract: [{
1358-
type: 'paragraph',
1359-
inlineContent: [{ type: 'text', text: 'blah' }],
1360-
}],
1361-
};
1362-
1363-
const wrapper = mountWithItem({
1364-
type: 'table',
1365-
header: TableHeaderStyle.none,
1366-
rows,
1367-
metadata,
1368-
});
1369-
1370-
const table = wrapper.find('.content').find(Table);
1371-
expect(table.exists()).toBe(true);
1372-
expect(table.attributes('id')).toBe(metadata.anchor);
1373-
1374-
const caption = wrapper.find(Caption);
1375-
expect(caption.exists()).toBe(true);
1376-
expect(caption.props('title')).toBe(metadata.title);
1377-
expect(caption.text()).toContain('blah');
1378-
});
1379-
13801375
it('renders header="both" style tables', () => {
13811376
const wrapper = mountWithItem({
13821377
type: 'table',
@@ -1415,6 +1410,35 @@ describe('ContentNode', () => {
14151410
expect(table.findAll('tbody tr td').length).toBe(2);
14161411
});
14171412

1413+
it('renders a `Figure`/`FigureCaption` with metadata', () => {
1414+
const metadata = {
1415+
anchor: '42',
1416+
title: 'Table 42',
1417+
abstract: [{
1418+
type: 'paragraph',
1419+
inlineContent: [{ type: 'text', text: 'blah' }],
1420+
}],
1421+
};
1422+
const wrapper = mountWithItem({
1423+
type: 'table',
1424+
header: TableHeaderStyle.none,
1425+
rows,
1426+
metadata,
1427+
});
1428+
1429+
const figure = wrapper.find(Figure);
1430+
expect(figure.exists()).toBe(true);
1431+
expect(figure.props('anchor')).toBe(metadata.anchor);
1432+
expect(figure.contains(Table)).toBe(true);
1433+
1434+
const caption = figure.find(FigureCaption);
1435+
expect(caption.exists()).toBe(true);
1436+
expect(caption.props('title')).toBe(metadata.title);
1437+
expect(caption.props('centered')).toBe(false);
1438+
expect(caption.contains('p')).toBe(true);
1439+
expect(caption.text()).toContain('blah');
1440+
});
1441+
14181442
describe('and column/row spanning', () => {
14191443
// <table>
14201444
// <tr>

tests/unit/components/ContentNode/Caption.spec.js renamed to tests/unit/components/ContentNode/FigureCaption.spec.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,30 @@
99
*/
1010

1111
import { shallowMount } from '@vue/test-utils';
12-
import Caption from '@/components/ContentNode/Caption.vue';
12+
import FigureCaption from 'docc-render/components/ContentNode/FigureCaption.vue';
1313

14-
describe('Caption', () => {
15-
it('renders a <caption> with the title and slot content', () => {
14+
describe('FigureCaption', () => {
15+
it('renders a <figcaption> with the title and slot content', () => {
1616
const propsData = { title: 'Figure 1' };
1717
const slots = { default: '<p>Blah</p>' };
18-
const wrapper = shallowMount(Caption, { propsData, slots });
18+
const wrapper = shallowMount(FigureCaption, { propsData, slots });
1919

20-
expect(wrapper.is('caption')).toBe(true);
21-
expect(wrapper.text()).toMatch(/Figure 1\sBlah/);
20+
expect(wrapper.is('figcaption')).toBe(true);
21+
expect(wrapper.text()).toBe('Figure 1\u00a0Blah');
2222
});
2323

2424
it('renders a <figcaption> with slot content only', () => {
2525
const slots = { default: '<p>Blah</p>' };
26-
const wrapper = shallowMount(Caption, { slots });
26+
const wrapper = shallowMount(FigureCaption, { slots });
2727

28-
expect(wrapper.is('caption')).toBe(true);
28+
expect(wrapper.is('figcaption')).toBe(true);
2929
expect(wrapper.text()).toBe('Blah');
3030
expect(wrapper.text()).not.toBe('\u00a0Blah');
3131
});
3232

3333
it('renders a <figcaption> centered', () => {
3434
const slots = { default: '<p>Blah</p>' };
35-
const wrapper = shallowMount(Caption, { slots, propsData: { centered: true } });
35+
const wrapper = shallowMount(FigureCaption, { slots, propsData: { centered: true } });
3636
expect(wrapper.classes()).toContain('centered');
3737
});
38-
39-
it('renders a <figcaption> if tag is `figcaption`', () => {
40-
const propsData = { title: 'Figure 1', tag: 'figcaption' };
41-
const wrapper = shallowMount(Caption, { propsData });
42-
43-
expect(wrapper.is('figcaption')).toBe(true);
44-
});
4538
});

0 commit comments

Comments
 (0)