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

Commit c40f208

Browse files
committed
chore(api-builder): let linkDocs links resolve to proper language
The old linkDevGuide required URIs to be given in the form 'ts/latest/guide/architecture' which forced all language versions of the API pages to refer to the ts versions of the doc pages they linked to. This PR fixes that problem. URIs are now given in the form 'guide/architecture' and then rendered properly for each language. Of course, when needed, it is still possible to give a language specific URI.
1 parent edc1b49 commit c40f208

File tree

2 files changed

+47
-21
lines changed

2 files changed

+47
-21
lines changed

gulpfile.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,9 @@ gulp.task('add-example-boilerplate', function() {
403403

404404
// copies boilerplate files to locations
405405
// where an example app is found
406-
gulp.task('_copy-example-boilerplate', copyExampleBoilerplate);
406+
gulp.task('_copy-example-boilerplate', function () {
407+
if (!argv.fast) copyExampleBoilerplate();
408+
});
407409

408410

409411
// copies boilerplate files to locations
@@ -1028,7 +1030,7 @@ function buildApiDocs(targetLanguage) {
10281030
try {
10291031
// Build a specialized package to generate different versions of the API docs
10301032
var package = new Package('apiDocs', [require(path.resolve(TOOLS_PATH, 'api-builder/angular.io-package'))]);
1031-
package.config(function(log, targetEnvironments, writeFilesProcessor, readTypeScriptModules) {
1033+
package.config(function(log, targetEnvironments, writeFilesProcessor, readTypeScriptModules, linkDocsInlineTagDef) {
10321034
log.level = _dgeniLogLevel;
10331035
ALLOWED_LANGUAGES.forEach(function(target) { targetEnvironments.addAllowed(target); });
10341036
if (targetLanguage) {
@@ -1038,7 +1040,9 @@ function buildApiDocs(targetLanguage) {
10381040
// Don't read TypeScript modules if we are not generating API docs - Dart I am looking at you!
10391041
readTypeScriptModules.$enabled = false;
10401042
}
1041-
writeFilesProcessor.outputFolder = targetLanguage + '/latest/api';
1043+
linkDocsInlineTagDef.lang = targetLanguage;
1044+
linkDocsInlineTagDef.vers = 'latest';
1045+
writeFilesProcessor.outputFolder = path.join(targetLanguage, linkDocsInlineTagDef.vers, 'api');
10421046
}
10431047
});
10441048

tools/api-builder/links-package/inline-tag-defs/linkDocs.js

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,59 @@ var path = require('canonical-path');
22
var fs = require("fs");
33
var jsonFile = require('jsonfile');
44

5-
var INLINE_LINK = /(\S+)(?:\s+([\s\S]+))?/;
6-
75
/**
8-
* @dgService linkDevGuideInlineTagDef
6+
* @dgService linkDocsInlineTagDef
97
* @description
10-
* Process inline link tags (of the form {@linkDevGuide some/uri 'Some Title'}), replacing them with HTML anchors.
11-
* The uri should point to a jade page in the DevGuide without the .jade extension ( under public/docs ).
8+
* Process inline link tags (of the form {@linkDocs some/uri 'Some Title'}), replacing them with HTML anchors.
9+
* The uri should point to a jade page in the Docs without the .jade extension ( under public/docs ).
1210
* If the title is omitted an attempt will be made to determine the title of the jade page being pointed to. If not found
1311
* the the title will simply be the last part of the link.
1412
* Examples
15-
* {@linkDevGuide ts/latest/guide/gettingStarted }
16-
* {@linkDevGuide js/latest/guide/gettingStarted 'Javascript version of getting started' }
17-
* {@linkDevGuide ts/latest/guide/gettingStarted title="Typescript version of getting started" }
13+
* {@linkDocs guide/gettingStarted 'QuickStart'}
14+
* {@linkDocs ts/latest/guide/quickstart }
15+
* {@linkDocs js/latest/guide/quickstart 'Javascript version of getting started' }
16+
* {@linkDocs ts/latest/guide/quickstart title="Typescript version of getting started" }
1817
* @kind function
18+
* @property {string} lang Default docs API page language when not explicitly given in URI; one of ts|js|dart.
19+
* @property {string} vers Default docs version. Currently only 'latest'.
1920
*/
20-
module.exports = function linkDevGuideInlineTagDef(parseArgString, createDocMessage, log) {
21-
return {
22-
name: 'linkDevGuide',
23-
description: 'Process inline link tags (of the form {@link some/uri "Some Title"}), replacing them with HTML anchors',
24-
handler: function(doc, tagName, tagDescription) {
21+
module.exports = function linkDocsInlineTagDef(parseArgString, createDocMessage, log) {
22+
var _self = {
23+
name: 'linkDocs',
24+
lang: 'ts',
25+
vers: 'latest',
26+
description: 'Process inline link tags (of the form {@linkDocs some/uri [title=]"Some Title"}), replacing them with HTML anchors',
2527

28+
handler: function(doc, tagName, tagDescription) {
2629
// Parse out the uri and title
2730
var tagArgs = parseArgString(tagDescription);
2831
var unnamedArgs = tagArgs._;
2932
var uri = unnamedArgs[0];
3033
var title = tagArgs.title || (unnamedArgs.length > 1 ? unnamedArgs[1] : null);
3134

35+
// Are there parameters and/or an anchor?
36+
var matches, paramAnchor = '';
37+
if (matches = uri.match(/([^\#\?]*)([\#\?].*)/)) {
38+
uri = matches[1];
39+
paramAnchor = matches[2];
40+
}
41+
42+
// Is this a chapter-relative uri like 'guide/...'?
43+
if (!uri.match(/^(ts|js|dart)/)) {
44+
var lang = _self.lang;
45+
var vers = _self.vers;
46+
var prevUri = uri;
47+
uri = path.join(lang, vers, uri);
48+
log.info('Ajusted linkDocs chapter-relative uri (' + doc.fileInfo.baseName + '): ' + prevUri + ' -> ' + uri);
49+
}
50+
51+
var isValid = false;
3252
var jadePath = path.join('./public/docs', uri + '.jade');
3353
var key = path.basename(jadePath, '.jade');
3454
if ( !fs.existsSync(jadePath)) {
35-
log.warn(createDocMessage('Invalid DevGuide example (unable to locate jade file: "' + jadePath + '")', doc));
55+
log.warn(createDocMessage('Invalid docs link (unable to locate jade file: "' + jadePath + '")', doc));
3656
} else {
57+
isValid = true;
3758
if (!title) {
3859
var jsonFilePath = path.join(path.dirname(jadePath), '_data.json');
3960
if ( fs.existsSync(jsonFilePath)) {
@@ -42,12 +63,13 @@ module.exports = function linkDevGuideInlineTagDef(parseArgString, createDocMess
4263
}
4364
}
4465
}
45-
var url = path.join('/docs', uri + '.html');
66+
var url = path.join('/docs', uri + '.html' + paramAnchor);
4667
title = title || key || url;
4768

48-
return "<a href='" + url + "'>" + title + "</a>";
49-
69+
return isValid ?
70+
'<a href="' + url + '">' + title + '</a>' :
71+
'<span>' + title + '</span>';
5072
}
5173
};
74+
return _self;
5275
};
53-

0 commit comments

Comments
 (0)