From c6dc78183d6da6424605bfeb9acc7b86e1be8424 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Fri, 15 May 2015 13:57:38 +0100 Subject: [PATCH] chore(doc-gen): relax link matching --- docs/dgeni-package/index.js | 6 ++++++ docs/links-package/inline-tag-defs/link.js | 4 ++-- docs/links-package/services/getLInkInfo.js | 8 +++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/dgeni-package/index.js b/docs/dgeni-package/index.js index e858075946..4c473a1ebf 100644 --- a/docs/dgeni-package/index.js +++ b/docs/dgeni-package/index.js @@ -81,6 +81,12 @@ module.exports = new Package('angular', [jsdocPackage, nunjucksPackage, linksPac }) +// Configure links +.config(function(getLinkInfo) { + getLinkInfo.useFirstAmbiguousLink = true; +}) + + // Configure file writing .config(function(writeFilesProcessor) { writeFilesProcessor.outputFolder = 'dist/docs'; diff --git a/docs/links-package/inline-tag-defs/link.js b/docs/links-package/inline-tag-defs/link.js index 58e2dee79a..89272c63ca 100644 --- a/docs/links-package/inline-tag-defs/link.js +++ b/docs/links-package/inline-tag-defs/link.js @@ -11,7 +11,7 @@ var INLINE_LINK = /(\S+)(?:\s+([\s\S]+))?/; * * @property {boolean} relativeLinks Whether we expect the links to be relative to the originating doc */ -module.exports = function linkInlineTagDef(getLinkInfo, createDocMessage) { +module.exports = function linkInlineTagDef(getLinkInfo, createDocMessage, log) { return { name: 'link', description: 'Process inline link tags (of the form {@link some/uri Some Title}), replacing them with HTML anchors', @@ -23,7 +23,7 @@ module.exports = function linkInlineTagDef(getLinkInfo, createDocMessage) { var linkInfo = getLinkInfo(uri, title, doc); if ( !linkInfo.valid ) { - throw new Error(createDocMessage(linkInfo.error, doc)); + log.warn(createDocMessage(linkInfo.error, doc)); } return "" + linkInfo.title + ""; diff --git a/docs/links-package/services/getLInkInfo.js b/docs/links-package/services/getLInkInfo.js index a0874329b5..787ff04338 100644 --- a/docs/links-package/services/getLInkInfo.js +++ b/docs/links-package/services/getLInkInfo.js @@ -28,13 +28,14 @@ module.exports = function getLinkInfo(getDocFromAlias, encodeCodeBlock, log) { var docs = getDocFromAlias(url, currentDoc); - if ( docs.length > 1 ) { + if ( !getLinkInfoImpl.useFirstAmbiguousLink && docs.length > 1 ) { linkInfo.valid = false; + linkInfo.errorType = 'ambiguous'; linkInfo.error = 'Ambiguous link: "' + url + '".\n' + - docs.reduce(function(msg, doc) { return msg + '\n "' + doc.id + '" ('+ doc.docType + ') : (' + doc.area + ')'; }, 'Matching docs: '); + docs.reduce(function(msg, doc) { return msg + '\n "' + doc.id + '" ('+ doc.docType + ') : (' + doc.path + ' / ' + doc.fileInfo.relativePath + ')'; }, 'Matching docs: '); - } else if ( docs.length === 1 ) { + } else if ( docs.length >= 1 ) { linkInfo.url = docs[0].path; linkInfo.title = title || encodeCodeBlock(docs[0].name, true); @@ -57,6 +58,7 @@ module.exports = function getLinkInfo(getDocFromAlias, encodeCodeBlock, log) { } else if ( url.indexOf('/') === -1 && url.indexOf('#') !== 0 ) { linkInfo.valid = false; + linkInfo.errorType = 'missing'; linkInfo.error = 'Invalid link (does not match any doc): "' + url + '"'; } else {