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

Commit 4da23bf

Browse files
chalinwardbell
authored andcommitted
chore(api-builder): linkDevGuide -> linkDocs;linkDocs can default the lang
closes #1849 1) Rename linkDevGuide to linkDocs Rename the specialized API docs `@linkDevGuide` tag to `@linkDocs` since it is meant to be used to refer to all angular.io docs, not just the developer guide. 2) 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. chore(api-builder): minor code cleanup
1 parent a8091f5 commit 4da23bf

File tree

5 files changed

+85
-69
lines changed

5 files changed

+85
-69
lines changed

gulpfile.js

+7-3
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
@@ -1066,7 +1068,7 @@ function buildApiDocs(targetLanguage) {
10661068
try {
10671069
// Build a specialized package to generate different versions of the API docs
10681070
var package = new Package('apiDocs', [require(path.resolve(TOOLS_PATH, 'api-builder/angular.io-package'))]);
1069-
package.config(function(log, targetEnvironments, writeFilesProcessor, readTypeScriptModules) {
1071+
package.config(function(log, targetEnvironments, writeFilesProcessor, readTypeScriptModules, linkDocsInlineTagDef) {
10701072
log.level = _dgeniLogLevel;
10711073
ALLOWED_LANGUAGES.forEach(function(target) { targetEnvironments.addAllowed(target); });
10721074
if (targetLanguage) {
@@ -1076,7 +1078,9 @@ function buildApiDocs(targetLanguage) {
10761078
// Don't read TypeScript modules if we are not generating API docs - Dart I am looking at you!
10771079
readTypeScriptModules.$enabled = false;
10781080
}
1079-
writeFilesProcessor.outputFolder = targetLanguage + '/latest/api';
1081+
linkDocsInlineTagDef.lang = targetLanguage;
1082+
linkDocsInlineTagDef.vers = 'latest';
1083+
writeFilesProcessor.outputFolder = path.join(targetLanguage, linkDocsInlineTagDef.vers, 'api');
10801084
}
10811085
});
10821086

tools/api-builder/links-package/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var Package = require('dgeni').Package;
33
module.exports = new Package('links', [])
44

55
.factory(require('./inline-tag-defs/link'))
6-
.factory(require('./inline-tag-defs/linkDevGuide'))
6+
.factory(require('./inline-tag-defs/linkDocs'))
77
.factory(require('./inline-tag-defs/example'))
88
.factory(require('./inline-tag-defs/exampleTabs'))
99
.factory(require('dgeni-packages/links/services/getAliases'))
@@ -12,9 +12,9 @@ module.exports = new Package('links', [])
1212
.factory(require('./services/parseArgString'))
1313
.factory(require('./services/getApiFragmentFileName'))
1414

15-
.config(function(inlineTagProcessor, linkInlineTagDef, linkDevGuideInlineTagDef, exampleInlineTagDef, exampleTabsInlineTagDef) {
15+
.config(function(inlineTagProcessor, linkInlineTagDef, linkDocsInlineTagDef, exampleInlineTagDef, exampleTabsInlineTagDef) {
1616
inlineTagProcessor.inlineTagDefinitions.push(linkInlineTagDef);
17-
inlineTagProcessor.inlineTagDefinitions.push(linkDevGuideInlineTagDef);
17+
inlineTagProcessor.inlineTagDefinitions.push(linkDocsInlineTagDef);
1818
inlineTagProcessor.inlineTagDefinitions.push(exampleInlineTagDef);
1919
inlineTagProcessor.inlineTagDefinitions.push(exampleTabsInlineTagDef);
2020
});

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

-10
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,8 @@ module.exports = function exampleInlineTagDef(getLinkInfo, parseArgString, getAp
4040
};
4141
};
4242

43-
// Examples of what @example and @exampleTabs markup looks like in the angular/angular source.
44-
//*
45-
//* {@example core/application_spec.ts hello-app -title='Sample component' }
46-
//*
47-
//* {@exampleTabs core/application_spec.ts,core/application_spec.ts "hello-app,hello-app2" -titles="Hello app1, Hello app2" }
48-
//*
49-
50-
5143
function quote(str) {
5244
if (str == null || str.length === 0) return str;
5345
str = str.replace("'","'\'");
5446
return "'" + str + "'";
5547
}
56-
57-

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

-53
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
var path = require('canonical-path');
2+
var fs = require("fs");
3+
var jsonFile = require('jsonfile');
4+
5+
/**
6+
* @dgService linkDocsInlineTagDef
7+
* @description
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 ).
10+
* If the title is omitted an attempt will be made to determine the title of the jade page being pointed to. If not found
11+
* the the title will simply be the last part of the link.
12+
* Examples
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" }
17+
* @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'.
20+
*/
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',
27+
28+
handler: function(doc, tagName, tagDescription) {
29+
// Parse out the uri and title
30+
var tagArgs = parseArgString(tagDescription);
31+
var unnamedArgs = tagArgs._;
32+
var uri = unnamedArgs[0];
33+
var title = tagArgs.title || (unnamedArgs.length > 1 ? unnamedArgs[1] : null);
34+
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;
52+
var jadePath = path.join('./public/docs', uri + '.jade');
53+
var key = path.basename(jadePath, '.jade');
54+
if ( !fs.existsSync(jadePath)) {
55+
log.warn(createDocMessage('Invalid docs link (unable to locate jade file: "' + jadePath + '")', doc));
56+
} else {
57+
isValid = true;
58+
if (!title) {
59+
var jsonFilePath = path.join(path.dirname(jadePath), '_data.json');
60+
if ( fs.existsSync(jsonFilePath)) {
61+
var jsonObj = jsonFile.readFileSync(jsonFilePath);
62+
title = jsonObj[key] && jsonObj[key].title;
63+
}
64+
}
65+
}
66+
var url = path.join('/docs', uri + '.html' + paramAnchor);
67+
title = title || key || url;
68+
69+
return isValid ?
70+
'<a href="' + url + '">' + title + '</a>' :
71+
'<span>' + title + '</span>';
72+
}
73+
};
74+
return _self;
75+
};

0 commit comments

Comments
 (0)