Skip to content

Commit 8e69a19

Browse files
authored
feat(renderer): implement minami renderer (#67)
* feat(renderer): add minami renderer * spec(renderer): add spec for minami renderer * chore: update CHANGELOG.md
1 parent 1d5063a commit 8e69a19

File tree

3 files changed

+129
-11
lines changed

3 files changed

+129
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Rewrote default renderer (#64)
1212
- Added [docstrap](https://github.com/docstrap/docstrap) renderer (#65)
1313
- Added [tui](https://github.com/nhnent/tui.jsdoc-template) renderer (#66)
14+
- Added [minami](https://github.com/nijikokun/minami) renderer (#67)
1415

1516
### Removals
1617

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,106 @@
11
describe('Renderers: minami', () => {
2-
beforeEach(() => {
2+
before(() => {
33
cy.visit('/../../../example/docs-minami/BetterCounter.html');
44
});
55

6+
67
it('should renders props correctly', () => {
7-
cy.get('[data-vue="section-props"]').contains('Props');
8+
cy.get('[data-jsdoc-vuejs="section-props"]').contains('Props').should('have.class', 'subsection-title');
9+
cy.get('[data-jsdoc-vuejs="table-props"]').as('table-props').should('have.class', 'params');
10+
11+
cy
12+
.get('@table-props')
13+
.find('> thead > tr > th')
14+
.should(($headers) => {
15+
expect($headers).to.have.length(5);
16+
expect($headers.eq(0).text()).to.contains('Name');
17+
expect($headers.eq(1).text()).to.contains('Type');
18+
expect($headers.eq(2).text()).to.contains('Default value');
19+
expect($headers.eq(3).text()).to.contains('Required ?');
20+
expect($headers.eq(4).text()).to.contains('Description');
21+
});
22+
23+
cy
24+
.get('@table-props')
25+
.find('> tbody > tr')
26+
.then(($rows) => {
27+
const $firstRowChildren = $rows.eq(0).children();
28+
const $secondRowChildren = $rows.eq(1).children();
29+
30+
expect($rows).to.have.length(2);
31+
32+
expect($firstRowChildren.eq(0).html()).to.eq('initialCounter');
33+
expect($firstRowChildren.eq(0).attr('class')).to.eq('name');
34+
expect($firstRowChildren.eq(1).html()).to.eq('Number');
35+
expect($firstRowChildren.eq(2).html()).to.eq('-');
36+
expect($firstRowChildren.eq(3).html()).to.eq('<b>Yes</b>');
37+
expect($firstRowChildren.eq(4).html()).to.eq('-');
38+
39+
expect($secondRowChildren.eq(0).html()).to.eq('step');
40+
expect($secondRowChildren.eq(0).attr('class')).to.eq('name');
41+
expect($secondRowChildren.eq(1).html()).to.eq('Number');
42+
expect($secondRowChildren.eq(2).html()).to.eq('<code>1</code>');
43+
expect($secondRowChildren.eq(3).html()).to.eq('No');
44+
expect($secondRowChildren.eq(4).html()).to.eq('Step');
45+
});
846
});
947

1048
it('should renders data correctly', () => {
11-
cy.get('[data-vue="section-data"]').contains('Data');
49+
cy.get('[data-jsdoc-vuejs="section-data"]').contains('Data').should('have.class', 'subsection-title');
50+
cy.get('[data-jsdoc-vuejs="table-data"]').as('table-data').should('have.class', 'params');
51+
52+
cy
53+
.get('@table-data')
54+
.find('> thead > tr > th')
55+
.should(($headers) => {
56+
expect($headers).to.have.length(4);
57+
expect($headers.eq(0).text()).to.contains('Name');
58+
expect($headers.eq(1).text()).to.contains('Type');
59+
expect($headers.eq(2).text()).to.contains('Default value');
60+
expect($headers.eq(3).text()).to.contains('Description');
61+
});
62+
63+
cy
64+
.get('@table-data')
65+
.find('> tbody > tr')
66+
.then(($rows) => {
67+
const $rowChildren = $rows.eq(0).children();
68+
69+
expect($rows).to.have.length(1);
70+
71+
expect($rowChildren.eq(0).html()).to.eq('counter');
72+
expect($rowChildren.eq(1).html()).to.eq('Number');
73+
expect($rowChildren.eq(2).html()).to.eq('-');
74+
expect($rowChildren.eq(3).html()).to.eq('Current counter\'s value');
75+
});
1276
});
1377

1478
it('should renders computed correctly', () => {
15-
cy.get('[data-vue="section-computed"]').contains('Computed');
79+
cy.get('[data-jsdoc-vuejs="section-computed"]').contains('Computed').should('have.class', 'subsection-title');
80+
cy.get('[data-jsdoc-vuejs="table-computed"]').as('table-data').should('have.class', 'params');
81+
82+
cy
83+
.get('@table-data')
84+
.find('> thead > tr > th')
85+
.should(($headers) => {
86+
expect($headers).to.have.length(3);
87+
expect($headers.eq(0).text()).to.contains('Name');
88+
expect($headers.eq(1).text()).to.contains('Type');
89+
expect($headers.eq(2).text()).to.contains('Description');
90+
});
91+
92+
cy
93+
.get('@table-data')
94+
.find('> tbody > tr')
95+
.then(($rows) => {
96+
const $rowChildren = $rows.eq(0).children();
97+
98+
expect($rows).to.have.length(1);
99+
100+
expect($rowChildren.eq(0).html()).to.eq('message');
101+
expect($rowChildren.eq(0).attr('class')).to.eq('name');
102+
expect($rowChildren.eq(1).html()).to.eq('String');
103+
expect($rowChildren.eq(2).html()).to.eq('A message');
104+
});
16105
});
17106
});

lib/renderers/minami.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,51 @@
1+
const makeTableHead = headers => `<thead><th>${headers.join('</th><th>')}</th></thead>`;
2+
const makeTableBody = (items, cb) => `<tbody>${items.map(item => `<tr>${cb(item).trim()}</tr>`).join('')}</tbody>`;
3+
14
module.exports = function renderMinami(description, props = [], data = [], computed = []) {
25
let html = description;
36

47
// eslint-disable-next-line no-console
58
console.log('Using minami renderer');
6-
79
if (props.length > 0) {
8-
html += '<h3 data-vue="section-props">Props</h3>';
9-
html += JSON.stringify(props);
10+
html += '<h3 class="subsection-title" data-jsdoc-vuejs="section-props">Props</h3>';
11+
html += '<table class="params" data-jsdoc-vuejs="table-props">';
12+
html += makeTableHead(['Name', 'Type', 'Default value', 'Required ?', 'Description']);
13+
html += makeTableBody(props, item => `
14+
<td class="name">${item.name}</td>
15+
<td>${(item.type.names || []).join(', ')}</td>
16+
<td>${typeof item.defaultvalue === 'undefined' ? '-' : `<code>${item.defaultvalue}</code>`}</td>
17+
<td>${item.optional ? 'No' : '<b>Yes</b>'}</td>
18+
<td>${typeof item.description === 'undefined' ? '-' : item.description}</td>
19+
`);
20+
html += '</table>';
1021
}
1122

1223
if (data.length > 0) {
13-
html += '<h3 data-vue="section-data">Data</h3>';
14-
html += JSON.stringify(data);
24+
html += '<h3 class="subsection-title" data-jsdoc-vuejs="section-data">Data</h3>';
25+
html += '<table class="params" data-jsdoc-vuejs="table-data">';
26+
html += makeTableHead(['Name', 'Type', 'Default value', 'Description']);
27+
html += makeTableBody(data, item => `
28+
<td class="name">${item.name}</td>
29+
<td>${(item.type.names || []).join(', ')}</td>
30+
<td>${typeof item.defaultvalue === 'undefined' ? '-' : `<code>${item.defaultvalue}</code>`}</td>
31+
<td>${typeof item.description === 'undefined' ? '-' : item.description}</td>
32+
`);
33+
html += '</table>';
1534
}
1635

1736
if (computed.length > 0) {
18-
html += '<h3 data-vue="section-computed">Computed</h3>';
19-
html += JSON.stringify(computed);
37+
html += '<h3 class="subsection-title" data-jsdoc-vuejs="section-computed">Computed</h3>';
38+
html += '<table class="params" data-jsdoc-vuejs="table-computed">';
39+
html += makeTableHead(['Name', 'Type', 'Description']);
40+
html += makeTableBody(computed, item => `
41+
<td class="name">${item.name}</td>
42+
<td>${(item.type.names || []).join(', ')}</td>
43+
<td>${typeof item.description === 'undefined' ? '-' : item.description}</td>
44+
`);
45+
html += '</table>';
2046
}
2147

48+
html += '<div class="container-overview"><div><p>';
49+
2250
return html;
2351
};

0 commit comments

Comments
 (0)