Skip to content

Commit

Permalink
fix: fix API build for composite components (#391)
Browse files Browse the repository at this point in the history
Background: some of the components do not have separate sample page, but they are appended to others sample page. The API of those components is part (in most cases) of parent components API, that use them as composite components.
Issue: the API of the composite/child components misses base properties.
Root cause: the API generation of the parent component is done before the API generation of the composite/child components.
Solution: calculate the API of those composite components before their addition to parents` component API.
Before (StandardListItem "selected" and "type" properties are missing)
  • Loading branch information
ilhan007 committed May 15, 2019
1 parent 7c3c453 commit dcb829b
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions lib/documentation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Handlebars.registerHelper('toKebabCase', function (str) {
return kebab !== str ? kebab : "";
});


Handlebars.registerHelper('checkEven', function (iIndex) {
return (iIndex % 2 === 0) ? "api-table-roll-even" : "api-table-roll-odd";
});
Expand All @@ -46,35 +45,48 @@ Handlebars.registerPartial('methods', methodsTemplate);

mkdirp(`dist/test-resources/sap/ui/webcomponents/main/api`);

entries.forEach((entry, index) => {
let entriesAPI = [];

const parentName = entry.extends;
let parent = getComponentByName(parentName) || {};
const mergeParentAPI = entry => {
if (entriesAPI.indexOf(entry.basename) !== -1) {
return entry;
}

let parent = getComponentByName(entry.extends) || {};
parent = { ...{ properties: [], events: [], slots: [] }, ...parent };

// extend component documentation
entry.properties = [...(entry.properties || []), ...(parent.properties || [])];
entry.events = [...(entry.events || []), ...(parent.events || [])];
entry.slots = [...(entry.slots || []), ...(parent.slots || [])];

entriesAPI.push(entry.basename);

return entry;
}

const appendAdditionalEntriesAPI = entry => {
if (entry.appenddocs) {
const additionalEntries = entry.appenddocs.split(" ");

entry.additionalDocs = [];

additionalEntries.forEach(entryName => {
entry.additionalDocs.push(getComponentByName(entryName));
let additionalEntry = getComponentByName(entryName);
additionalEntry = mergeParentAPI(additionalEntry);
entry.additionalDocs.push(additionalEntry);
});
}

return entry;
}

const generateSamplePage = entry => {
let content = "";

try {
content = fs.readFileSync(`dist/test-resources/sap/ui/webcomponents/main/samples/${capitalize(entry.basename)}.sample.html`, 'utf8');
} catch (err) { }


if (content) {
const fnRedirect = `
<script>
Expand Down Expand Up @@ -105,5 +117,18 @@ entries.forEach((entry, index) => {
// console.log(err);
});
}
}

const generateComponentAPI = entry => {
// (1) merge parent API
entry = mergeParentAPI(entry);

// (2) append additional API for children
entry = appendAdditionalEntriesAPI(entry);

// (3) generate sample page
generateSamplePage(entry);
}

});
entries.forEach(generateComponentAPI);
entriesAPI = [];

0 comments on commit dcb829b

Please sign in to comment.