Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 75f37b7

Browse files
chalinfilipesilva
authored andcommitted
chore: Dart API doc gen cleanup and refactoring (#2641)
- gulp task: don’t copy over internal libraries. - Adjust anchor hrefs rather than use `<base href>` in generated API pages. The net effect is the same.
1 parent 870ce12 commit 75f37b7

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

gulpfile.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,14 +1381,14 @@ function buildApiDocsForDart() {
13811381
dabInfo.ngDartDocPath = path.join(ngPathFor('dart'), relDartDocApiDir);
13821382
// Exclude API entries for developer/internal libraries. Also exclude entries for
13831383
// the top-level catch all "angular2" library (otherwise every entry appears twice).
1384-
dabInfo.excludeLibRegExp = new RegExp(/^(?!angular2)|\.testing|_|codegen|^angular2$/);
1384+
dabInfo.excludeLibRegExp = new RegExp(/^(?!angular2)|testing|_|codegen|^angular2$/);
13851385

13861386
try {
13871387
checkAngularProjectPath(ngPathFor('dart'));
13881388
var destPath = dabInfo.ngIoDartApiDocPath;
13891389
var sourceDirs = fs.readdirSync(dabInfo.ngDartDocPath)
1390-
.filter((name) => !name.match(/^index/))
1391-
.map((name) => path.join(dabInfo.ngDartDocPath, name));
1390+
.filter(name => !name.match(/^index|^(?!angular2)|testing|codegen/))
1391+
.map(name => path.join(dabInfo.ngDartDocPath, name));
13921392
log.info(`Building Dart API pages for ${sourceDirs.length} libraries`);
13931393

13941394
return copyFiles(sourceDirs, [destPath]).then(() => {
@@ -1398,7 +1398,6 @@ function buildApiDocsForDart() {
13981398
const tmpDocsPath = path.resolve(path.join(process.env.HOME, 'tmp/docs.json'));
13991399
if (argv.dumpDocsJson) fs.writeFileSync(tmpDocsPath, JSON.stringify(apiEntries, null, 2));
14001400
dab.createApiDataAndJadeFiles(apiEntries);
1401-
14021401
}).catch((err) => {
14031402
console.error(err);
14041403
});

tools/dart-api-builder/dab.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ module.exports = function dabFactory(ngIoProjPath) {
135135
assert(depth === 1 || depth == 2, 'depth ' + depth);
136136
const jadeFilePath = path.resolve(outFileNoExtn + '.jade');
137137
const breadcrumbs = $('header > nav ol.breadcrumbs');
138-
fs.writeFileSync(jadeFilePath, apiEntryJadeTemplate(depth, breadcrumbs, div));
138+
fs.writeFileSync(jadeFilePath, apiEntryJadeTemplate($, depth, breadcrumbs, div));
139139
// In case harp cached the .html version, remove it since it will be generated.
140140
try {
141141
fs.unlinkSync(path.resolve(outFileNoExtn + '.html'));
@@ -197,17 +197,29 @@ module.exports = function dabFactory(ngIoProjPath) {
197197
return _self;
198198
};
199199

200+
function _adjustAnchorHref($, $elt, hrefPathPrefix) {
201+
if (!hrefPathPrefix) return;
202+
$elt.find('a[href]').each((i, e) => {
203+
let href = $(e).attr('href')
204+
// Do nothing to absolute or external links
205+
if (href.match(/^\/|^[a-z]+:/)) return;
206+
$(e).attr('href', `${hrefPathPrefix}/${href}`);
207+
});
208+
}
209+
200210
function _indentedEltHtml($elt, i, filterFnOpt) {
201211
let lines = $elt.html().split('\n');
202212
if (filterFnOpt) lines = lines.filter(filterFnOpt);
203213
const indent = ' '.substring(0,i);
204214
return lines.map((line) => `${indent}| ${line}`).join('\n');
205215
}
206216

207-
function apiEntryJadeTemplate(baseHrefDepth, $breadcrumbs, $mainDiv) {
217+
function apiEntryJadeTemplate($, baseHrefDepth, $breadcrumbs, $mainDiv) {
208218
const baseHref = path.join(...Array(baseHrefDepth).fill('..'));
209219
// TODO/investigate: for some reason $breadcrumbs.html() is missing the <ol></ol>. We add it back in the template below.
220+
_adjustAnchorHref($, $breadcrumbs, baseHref);
210221
const breadcrumbs = _indentedEltHtml($breadcrumbs, 6, (line) => !line.match(/^\s*$/));
222+
_adjustAnchorHref($, $mainDiv, baseHref);
211223
const mainDivHtml = _indentedEltHtml($mainDiv, 4);
212224
// WARNING: since the following is Jade, indentation is significant.
213225
const result = `
@@ -217,8 +229,8 @@ include ${baseHref}/../_util-fns
217229
218230
block head-extra
219231
// generated Dart API page template: head-extra
220-
//- <base> is required because all the links in dartdoc generated pages are "pseudo-absolute"
221-
base(href="${baseHref}")
232+
//- <base> is no longer required
233+
//- base(href="${baseHref}")
222234
223235
block breadcrumbs
224236
// generated Dart API page template: breadcrumbs

0 commit comments

Comments
 (0)