Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tools/api-builder/links-package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ module.exports = new Package('links', [])
.factory(require('dgeni-packages/links/services/getDocFromAlias'))
.factory(require('./services/getLinkInfo'))
.factory(require('./services/parseArgString'))
.factory(require('./services/moduleScopeLinkDisambiguator'))
.factory(require('./services/deprecatedDocsLinkDisambiguator'))
.factory(require('./services/getApiFragmentFileName'))

.config(function(inlineTagProcessor, linkInlineTagDef, linkDevGuideInlineTagDef, exampleInlineTagDef, exampleTabsInlineTagDef) {
inlineTagProcessor.inlineTagDefinitions.push(linkInlineTagDef);
inlineTagProcessor.inlineTagDefinitions.push(linkDevGuideInlineTagDef);
inlineTagProcessor.inlineTagDefinitions.push(exampleInlineTagDef);
inlineTagProcessor.inlineTagDefinitions.push(exampleTabsInlineTagDef);
})

.config(function(getLinkInfo, moduleScopeLinkDisambiguator, deprecatedDocsLinkDisambiguator) {
getLinkInfo.disambiguators.push(moduleScopeLinkDisambiguator);
getLinkInfo.disambiguators.push(deprecatedDocsLinkDisambiguator);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var _ = require('lodash');

module.exports = function deprecatedDocsLinkDisambiguator() {
return function(url, title, currentDoc, docs) {
if (docs.length != 2) return docs;

var filteredDocs = _.filter(docs, function(doc) {
return !doc.fileInfo.relativePath.match(/\/(\w+)-deprecated\//);
});

return filteredDocs.length > 0 ? filteredDocs : docs;
};
};
15 changes: 14 additions & 1 deletion tools/api-builder/links-package/services/getLinkInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ var path = require('canonical-path');
* @return {Object} The link information
*
* @property {boolean} relativeLinks Whether we expect the links to be relative to the originating doc
* @property {array<function(url, title, currentDoc, ambiguousDocs) : array} disambiguators a collection of functions
* that attempt to resolve ambiguous links. Each disambiguator returns a new collection of docs with
* unwanted ambiguous docs removed (see moduleScopeLinkDisambiguator service for an example).
*/
module.exports = function getLinkInfo(getDocFromAlias, encodeCodeBlock, log) {

return function getLinkInfoImpl(url, title, currentDoc) {
getLinkInfoImpl.disambiguators = [];

return getLinkInfoImpl;

function getLinkInfoImpl(url, title, currentDoc) {
var linkInfo = {
url: url,
type: 'url',
Expand All @@ -27,6 +34,11 @@ module.exports = function getLinkInfo(getDocFromAlias, encodeCodeBlock, log) {

var docs = getDocFromAlias(url, currentDoc);

// Give each disambiguator a chance to reduce the number of ambiguous docs
docs = getLinkInfoImpl.disambiguators.reduce(function(docs, disambiguator) {
return disambiguator(url, title, currentDoc, docs);
}, docs);

if ( !getLinkInfoImpl.useFirstAmbiguousLink && docs.length > 1 ) {

linkInfo.valid = false;
Expand Down Expand Up @@ -68,4 +80,5 @@ module.exports = function getLinkInfo(getDocFromAlias, encodeCodeBlock, log) {

return linkInfo;
};

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var _ = require('lodash');

module.exports = function moduleScopeLinkDisambiguator() {
return function(url, title, currentDoc, docs) {
if (docs.length > 1) {
// filter out target docs that are not in the same module as the source doc
var filteredDocs = _.filter(docs, function(doc) {
return doc.moduleDoc === currentDoc.moduleDoc;
});
// if all target docs are in a different module then just return the full collection of ambiguous docs
return filteredDocs.length > 0 ? filteredDocs : docs;
}
return docs;
};
};