Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Added `@vue-computed` tag (#59)
- Added rendering system to support more JSDoc templates (#59)
- Rewrote default renderer (#64)
- Added [docstrap](https://github.com/docstrap/docstrap) renderer (#65)

### Removals

Expand Down
93 changes: 89 additions & 4 deletions cypress/integration/renderers/docstrap.spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,102 @@
describe('Renderers: docstrap', () => {
beforeEach(() => {
before(() => {
cy.visit('/../../../example/docs-docstrap/BetterCounter.html');
});

it('should renders props correctly', () => {
cy.get('[data-vue="section-props"]').contains('Props');
cy.get('[data-jsdoc-vuejs="section-props"]').contains('Props').should('have.class', 'subsection-title');
cy.get('[data-jsdoc-vuejs="table-props"]').as('table-props').should('have.class', 'table table-responsive table-hover table-striped');

cy
.get('@table-props')
.find('> thead > tr > th')
.should(($headers) => {
expect($headers).to.have.length(5);
expect($headers.eq(0).text()).to.contains('Name');
expect($headers.eq(1).text()).to.contains('Type');
expect($headers.eq(2).text()).to.contains('Default value');
expect($headers.eq(3).text()).to.contains('Required ?');
expect($headers.eq(4).text()).to.contains('Description');
});

cy
.get('@table-props')
.find('> tbody > tr')
.then(($rows) => {
const $firstRowChildren = $rows.eq(0).children();
const $secondRowChildren = $rows.eq(1).children();

expect($rows).to.have.length(2);

expect($firstRowChildren.eq(0).html()).to.eq('<b>initialCounter</b>');
expect($firstRowChildren.eq(1).html()).to.eq('Number');
expect($firstRowChildren.eq(2).html()).to.eq('-');
expect($firstRowChildren.eq(3).html()).to.eq('<b>Yes</b>');
expect($firstRowChildren.eq(4).html()).to.eq('-');

expect($secondRowChildren.eq(0).html()).to.eq('<b>step</b>');
expect($secondRowChildren.eq(1).html()).to.eq('Number');
expect($secondRowChildren.eq(2).html()).to.eq('<code>1</code>');
expect($secondRowChildren.eq(3).html()).to.eq('No');
expect($secondRowChildren.eq(4).html()).to.eq('Step');
});
});

it('should renders data correctly', () => {
cy.get('[data-vue="section-data"]').contains('Data');
cy.get('[data-jsdoc-vuejs="section-data"]').contains('Data').should('have.class', 'subsection-title');
cy.get('[data-jsdoc-vuejs="table-data"]').as('table-data').should('have.class', 'table table-responsive table-hover table-striped');

cy
.get('@table-data')
.find('> thead > tr > th')
.should(($headers) => {
expect($headers).to.have.length(4);
expect($headers.eq(0).text()).to.contains('Name');
expect($headers.eq(1).text()).to.contains('Type');
expect($headers.eq(2).text()).to.contains('Default value');
expect($headers.eq(3).text()).to.contains('Description');
});

cy
.get('@table-data')
.find('> tbody > tr')
.then(($rows) => {
const $rowChildren = $rows.eq(0).children();

expect($rows).to.have.length(1);

expect($rowChildren.eq(0).html()).to.eq('<b>counter</b>');
expect($rowChildren.eq(1).html()).to.eq('Number');
expect($rowChildren.eq(2).html()).to.eq('-');
expect($rowChildren.eq(3).html()).to.eq('Current counter\'s value');
});
});

it('should renders computed correctly', () => {
cy.get('[data-vue="section-computed"]').contains('Computed');
cy.get('[data-jsdoc-vuejs="section-computed"]').contains('Computed').should('have.class', 'subsection-title');
cy.get('[data-jsdoc-vuejs="table-computed"]').as('table-data').should('have.class', 'table table-responsive table-hover table-striped');

cy
.get('@table-data')
.find('> thead > tr > th')
.should(($headers) => {
expect($headers).to.have.length(3);
expect($headers.eq(0).text()).to.contains('Name');
expect($headers.eq(1).text()).to.contains('Type');
expect($headers.eq(2).text()).to.contains('Description');
});

cy
.get('@table-data')
.find('> tbody > tr')
.then(($rows) => {
const $rowChildren = $rows.eq(0).children();

expect($rows).to.have.length(1);

expect($rowChildren.eq(0).html()).to.eq('<b>message</b>');
expect($rowChildren.eq(1).html()).to.eq('String');
expect($rowChildren.eq(2).html()).to.eq('A message');
});
});
});
46 changes: 40 additions & 6 deletions lib/renderers/docstrap.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,57 @@
const makeTableHead = headers => `<thead><th>${headers.join('</th><th>')}</th></thead>`;
const makeTableBody = (items, cb) => `<tbody>${items.map(item => `<tr>${cb(item).trim()}</tr>`).join('')}</tbody>`;

module.exports = function renderDocstrap(description, props = [], data = [], computed = []) {
let html = description;

html += '</p></div></div>';

// eslint-disable-next-line no-console
console.log('Using docstrap renderer');

if (props.length > 0) {
html += '<h3 data-vue="section-props">Props</h3>';
html += JSON.stringify(props);
html += '<h3 class="subsection-title" data-jsdoc-vuejs="section-props">Props</h3>';
html += '<hr>';
html += '<table class="table table-responsive table-hover table-striped" data-jsdoc-vuejs="table-props">';
html += makeTableHead(['Name', 'Type', 'Default value', 'Required ?', 'Description']);
html += makeTableBody(props, item => `
<td><b>${item.name}</b></td>
<td>${(item.type.names || []).join(', ')}</td>
<td>${typeof item.defaultvalue === 'undefined' ? '-' : `<code>${item.defaultvalue}</code>`}</td>
<td>${item.optional ? 'No' : '<b>Yes</b>'}</td>
<td>${typeof item.description === 'undefined' ? '-' : item.description}</td>
`);
html += '</table>';
}

if (data.length > 0) {
html += '<h3 data-vue="section-data">Data</h3>';
html += JSON.stringify(data);
html += '<h3 class="subsection-title" data-jsdoc-vuejs="section-data">Data</h3>';
html += '<hr>';
html += '<table class="table table-responsive table-hover table-striped" data-jsdoc-vuejs="table-data">';
html += makeTableHead(['Name', 'Type', 'Default value', 'Description']);
html += makeTableBody(data, item => `
<td><b>${item.name}</b></td>
<td>${(item.type.names || []).join(', ')}</td>
<td>${typeof item.defaultvalue === 'undefined' ? '-' : `<code>${item.defaultvalue}</code>`}</td>
<td>${typeof item.description === 'undefined' ? '-' : item.description}</td>
`);
html += '</table>';
}

if (computed.length > 0) {
html += '<h3 data-vue="section-computed">Computed</h3>';
html += JSON.stringify(computed);
html += '<h3 class="subsection-title" data-jsdoc-vuejs="section-computed">Computed</h3>';
html += '<hr>';
html += '<table class="table table-responsive table-hover table-striped" data-jsdoc-vuejs="table-computed">';
html += makeTableHead(['Name', 'Type', 'Description']);
html += makeTableBody(computed, item => `
<td><b>${item.name}</b></td>
<td>${(item.type.names || []).join(', ')}</td>
<td>${typeof item.description === 'undefined' ? '-' : item.description}</td>
`);
html += '</table>';
}

html += '<div class="container-overview"><div><p>';

return html;
};