From 05beca135789250f6f6bf2bad8068f7ebae9ab31 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Fri, 8 Jul 2016 11:02:08 +0100 Subject: [PATCH 1/3] chore(api-builder): enable configurable link disambuators --- .../links-package/services/getLinkInfo.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/api-builder/links-package/services/getLinkInfo.js b/tools/api-builder/links-package/services/getLinkInfo.js index a180984c69..c0dad0025a 100644 --- a/tools/api-builder/links-package/services/getLinkInfo.js +++ b/tools/api-builder/links-package/services/getLinkInfo.js @@ -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 1 ) { linkInfo.valid = false; @@ -68,4 +80,5 @@ module.exports = function getLinkInfo(getDocFromAlias, encodeCodeBlock, log) { return linkInfo; }; + }; \ No newline at end of file From 9ab3a39ab6de21c1364b7ccff869494e84946a56 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Fri, 8 Jul 2016 11:02:36 +0100 Subject: [PATCH 2/3] chore(api-builder): add a service to disambiguate docs by module --- tools/api-builder/links-package/index.js | 5 +++++ .../services/moduleScopeLinkDisambiguator.js | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tools/api-builder/links-package/services/moduleScopeLinkDisambiguator.js diff --git a/tools/api-builder/links-package/index.js b/tools/api-builder/links-package/index.js index 3036c2441b..09b3f85743 100644 --- a/tools/api-builder/links-package/index.js +++ b/tools/api-builder/links-package/index.js @@ -10,6 +10,7 @@ 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/getApiFragmentFileName')) .config(function(inlineTagProcessor, linkInlineTagDef, linkDevGuideInlineTagDef, exampleInlineTagDef, exampleTabsInlineTagDef) { @@ -17,4 +18,8 @@ module.exports = new Package('links', []) inlineTagProcessor.inlineTagDefinitions.push(linkDevGuideInlineTagDef); inlineTagProcessor.inlineTagDefinitions.push(exampleInlineTagDef); inlineTagProcessor.inlineTagDefinitions.push(exampleTabsInlineTagDef); +}) + +.config(function(getLinkInfo, moduleScopeLinkDisambiguator) { + getLinkInfo.disambiguators.push(moduleScopeLinkDisambiguator); }); diff --git a/tools/api-builder/links-package/services/moduleScopeLinkDisambiguator.js b/tools/api-builder/links-package/services/moduleScopeLinkDisambiguator.js new file mode 100644 index 0000000000..ec1758fe99 --- /dev/null +++ b/tools/api-builder/links-package/services/moduleScopeLinkDisambiguator.js @@ -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; + }; +}; From d726c1e27bf58e4efa211feb5c124227485b7be3 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Fri, 8 Jul 2016 11:28:11 +0100 Subject: [PATCH 3/3] chore(api-builder): add a service to disambiguate docs that are deprecated --- tools/api-builder/links-package/index.js | 4 +++- .../services/deprecatedDocsLinkDisambiguator.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tools/api-builder/links-package/services/deprecatedDocsLinkDisambiguator.js diff --git a/tools/api-builder/links-package/index.js b/tools/api-builder/links-package/index.js index 09b3f85743..de99cc39ce 100644 --- a/tools/api-builder/links-package/index.js +++ b/tools/api-builder/links-package/index.js @@ -11,6 +11,7 @@ module.exports = new Package('links', []) .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) { @@ -20,6 +21,7 @@ module.exports = new Package('links', []) inlineTagProcessor.inlineTagDefinitions.push(exampleTabsInlineTagDef); }) -.config(function(getLinkInfo, moduleScopeLinkDisambiguator) { +.config(function(getLinkInfo, moduleScopeLinkDisambiguator, deprecatedDocsLinkDisambiguator) { getLinkInfo.disambiguators.push(moduleScopeLinkDisambiguator); + getLinkInfo.disambiguators.push(deprecatedDocsLinkDisambiguator); }); diff --git a/tools/api-builder/links-package/services/deprecatedDocsLinkDisambiguator.js b/tools/api-builder/links-package/services/deprecatedDocsLinkDisambiguator.js new file mode 100644 index 0000000000..3db79ffbd6 --- /dev/null +++ b/tools/api-builder/links-package/services/deprecatedDocsLinkDisambiguator.js @@ -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; + }; +};