diff options
| -rw-r--r-- | docs/spec/ngdocSpec.js | 20 | ||||
| -rw-r--r-- | docs/src/ngdoc.js | 58 |
2 files changed, 42 insertions, 36 deletions
diff --git a/docs/spec/ngdocSpec.js b/docs/spec/ngdocSpec.js index 090b20ab..cb11c1a5 100644 --- a/docs/spec/ngdocSpec.js +++ b/docs/spec/ngdocSpec.js @@ -104,6 +104,23 @@ describe('ngdoc', function(){ expect(doc.links).toContain('api/angular.link'); }); + describe('convertUrlToAbsolute', function() { + var doc; + + beforeEach(function() { + doc = new Doc({section: 'section'}); + }); + + it('should not change absolute url', function() { + expect(doc.convertUrlToAbsolute('guide/index')).toEqual('guide/index'); + }); + + it('should prepend current section to relative url', function() { + expect(doc.convertUrlToAbsolute('angular.widget')).toEqual('section/angular.widget'); + }); + + }); + describe('sorting', function(){ function property(name) { return function(obj) {return obj[name];}; @@ -366,7 +383,10 @@ describe('ngdoc', function(){ 'external{@link http://angularjs.org}\n\n' + 'external{@link ./static.html}\n\n' + '{@link angular.directive.ng:foo ng:foo}'); + + doc.section = 'api'; doc.parse(); + expect(doc.description). toContain('foo <a href="#!api/angular.foo"><code>angular.foo</code></a>'); expect(doc.description). diff --git a/docs/src/ngdoc.js b/docs/src/ngdoc.js index e1ffb858..70e393a8 100644 --- a/docs/src/ngdoc.js +++ b/docs/src/ngdoc.js @@ -57,36 +57,25 @@ Doc.prototype = { return words.join(' '); }, - - /* - * This function is here to act as a huristic based translator from the old style urls to - * the new style which use sections. + /** + * Converts relative urls (without section) into absolute + * Absolute url means url with section + * + * @example + * - if the link is inside any api doc: + * angular.widget -> api/angular.widget + * + * - if the link is inside any guid doc: + * intro -> guide/intro + * + * @param {string} url Absolute or relative url + * @returns {string} Absolute url */ - sectionHuristic: function (url){ - // if we are new styl URL with section/id then just return; + convertUrlToAbsolute: function(url) { if (url.match(/\//)) return url; - var match = url.match(/(\w+)(\.(.*))?/); - var section = match[1]; - var id = match[3] || 'index'; - switch(section) { - case 'angular': - section = 'api'; - id = 'angular.' + id; - break; - case 'api': - case 'cookbook': - case 'guide': - case 'intro': - case 'tutorial': - break; - default: - id = section + '.' + id; - section = 'intro'; - } - var newUrl = section + '/' + (id || 'index'); - console.log('WARNING:', 'found old style url', url, 'at', this.file, this.line, - 'converting to', newUrl); - return newUrl; + + // remove this after + return this.section + '/' + url; }, markdown: function (text) { @@ -126,16 +115,13 @@ Doc.prototype = { text = text.replace(/{@link\s+([^\s}]+)\s*([^}]*?)\s*}/g, function(_all, url, title){ var isFullUrl = url.match(IS_URL), - // FIXME(vojta) angular link could be api.angular now with sections - isAngular = url.match(IS_ANGULAR); + // FIXME(vojta) angular link could be api/angular now with sections + isAngular = url.match(IS_ANGULAR), + absUrl = isFullUrl ? url : self.convertUrlToAbsolute(url); - if (!isFullUrl) { - // TODO(vojta) there could be relative link, but not angular - // do we want to store all links (and check even the full links like http://github.com ? - self.links.push(self.sectionHuristic(url)); - } + if (!isFullUrl) self.links.push(absUrl); - return '<a href="' + (isFullUrl ? '' + url : '#!' + self.sectionHuristic(url)) + '">' + return '<a href="' + (isFullUrl ? '' + url : '#!' + absUrl) + '">' + (isAngular ? '<code>' : '') + (title || url).replace(/\n/g, ' ') + (isAngular ? '</code>' : '') |
