Skip to content

Commit

Permalink
docs: show generated docs when there are no dummy files (#2437)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus authored Jul 5, 2017
1 parent 968948a commit ac8967c
Showing 1 changed file with 75 additions and 67 deletions.
142 changes: 75 additions & 67 deletions scripts/docs/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ Builder.prototype.build = function() {
return json;
});


var gapicVersions = docs.reduce((grouped, doc) => {
var gapicVersion = doc.id.match(/[/_](v[^\/]*)/);

if (gapicVersion) {
gapicVersion = gapicVersion[1];
grouped[gapicVersion] = grouped[gapicVersion] || [];

mkdir('-p', `${self.dir}/${gapicVersion}`);

if (stringIncludes(doc.id, 'doc_')) {
grouped[gapicVersion] = grouped[gapicVersion] || [];
grouped[gapicVersion].push(doc);
} else if (stringIncludes(doc.id, '_client')) {
// Move client file to a separate path.
Expand All @@ -122,7 +122,78 @@ Builder.prototype.build = function() {
docs = docs.filter(doc => !stringIncludes(doc.source, 'doc_'));

for (var gapicVersion in gapicVersions) {
var gapicFiles = gapicVersions[gapicVersion];
var gapicDataTypes = gapicVersions[gapicVersion];
var dataTypesMarkup = '';

if (gapicDataTypes.length > 0) {
dataTypesMarkup = `
<tr>
<td>
<a ui-sref="docs.service({
serviceId: '{{docs.services[0].type}}/{{service.path.split('/').shift()}}/data_types'
})">Data Types</a>
</td>
<td>
Data types for {{docs.services[0].title}} {{service.path.split('/').shift()}}.
</td>
</tr>
`;

var dataTypesFile = {
name: 'Data Types',
methods: [],
path: `${gapicVersion}/data_types.json`,
description: `
<table class="table">
<thead>
<tr>
<th>Class</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="method in service.methods" ng-if="method.name">
<td>
<a ui-sref="docs.service({ method: method.id })" class="skip-external-link">
{{method.name}}
</a>
</td>
<td>
<span ng-bind-html="method.description">
{{method.description}}
</span>
<span ng-if="!method.description && method.name.includes('Request')">
The request for {{method.name}}.
</span>
<span ng-if="!method.description && method.name.includes('Response')">
The response for {{method.name}}.
</span>
</td>
</tr>
</tbody>
</table>
`
};

/*jshint loopfunc:true*/
gapicDataTypes.forEach(gapicDataType => {
if (!dataTypesFile.id) {
var idParts = gapicDataType.id.split('/');
idParts.pop();
idParts.pop();
idParts.push('data_types');
dataTypesFile.id = idParts.join('/');
}

dataTypesFile.methods = dataTypesFile.methods
.concat(gapicDataType.methods);
});

if (!is.empty(dataTypesFile.methods)) {
this.write(`${gapicVersion}/data_types.json`, dataTypesFile);
docs.push(dataTypesFile);
}
}

this.write(`${gapicVersion}/index.json`, {
name: gapicVersion,
Expand Down Expand Up @@ -151,74 +222,11 @@ Builder.prototype.build = function() {
Create a {{client.title}} to interact with the {{docs.services[0].title}} API.
</td>
</tr>
<tr>
<td>
<a ui-sref="docs.service({
serviceId: '{{docs.services[0].type}}/{{service.path.split('/').shift()}}/data_types'
})">Data Types</a>
</td>
<td>
Data types for {{docs.services[0].title}} {{service.path.split('/').shift()}}.
</td>
</tr>
${dataTypesMarkup}
</tbody>
</table>
`
});

var dataTypesFile = {
name: 'Data Types',
methods: [],
path: `${gapicVersion}/data_types.json`,
description: `
<table class="table">
<thead>
<tr>
<th>Class</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="method in service.methods" ng-if="method.name">
<td>
<a ui-sref="docs.service({ method: method.id })" class="skip-external-link">
{{method.name}}
</a>
</td>
<td>
<span ng-bind-html="method.description">
{{method.description}}
</span>
<span ng-if="!method.description && method.name.includes('Request')">
The request for {{method.name}}.
</span>
<span ng-if="!method.description && method.name.includes('Response')">
The response for {{method.name}}.
</span>
</td>
</tr>
</tbody>
</table>
`
};

/*jshint loopfunc:true*/
gapicFiles.forEach(gapicFile => {
if (!dataTypesFile.id) {
var idParts = gapicFile.id.split('/');
idParts.pop();
idParts.pop();
idParts.push('data_types');
dataTypesFile.id = idParts.join('/');
}

dataTypesFile.methods = dataTypesFile.methods.concat(gapicFile.methods);
});

if (!is.empty(dataTypesFile.methods)) {
this.write(`${gapicVersion}/data_types.json`, dataTypesFile);
docs.push(dataTypesFile);
}
}

var types = parser.createTypesDictionary(docs);
Expand Down

0 comments on commit ac8967c

Please sign in to comment.