diff options
| author | Vojta Jina | 2011-05-17 22:12:23 +0200 |
|---|---|---|
| committer | Igor Minar | 2011-06-06 22:51:59 -0700 |
| commit | 2e0e732cadd86846b57b7b02b3303a2e0e3b842a (patch) | |
| tree | d18acaed3f04decb5e4305386b32e4a2097ba0f9 | |
| parent | 22f9354c211b032c3da3c8e1320a3fa1106e3ffd (diff) | |
| download | angular.js-2e0e732cadd86846b57b7b02b3303a2e0e3b842a.tar.bz2 | |
Check whether links do exist and throw exception
| -rw-r--r-- | docs/spec/ngdocSpec.js | 37 | ||||
| -rw-r--r-- | docs/src/ngdoc.js | 26 |
2 files changed, 58 insertions, 5 deletions
diff --git a/docs/spec/ngdocSpec.js b/docs/spec/ngdocSpec.js index 68d3700f..e8b8959d 100644 --- a/docs/spec/ngdocSpec.js +++ b/docs/spec/ngdocSpec.js @@ -96,6 +96,13 @@ describe('ngdoc', function(){ expect(doc.description).toContain('<p>before </p><doc:example>' + '<pre class="doc-scenario">\n<>\n</pre></doc:example><p>after</p>'); }); + + it('should store all links', function() { + var doc = new Doc('@description {@link api/angular.link}'); + doc.parse(); + + expect(doc.links).toContain('api/angular.link'); + }); describe('sorting', function(){ function property(name) { @@ -197,7 +204,37 @@ describe('ngdoc', function(){ expect(docs[0].methods).toEqual([methodA, methodB]); expect(docs[0].properties).toEqual([propA, propB]); }); + + describe('links checking', function() { + var docs; + beforeEach(function() { + docs = [new Doc({section: 'api', id: 'fake.id1', links: ['non-existing-link']}), + new Doc({section: 'api', id: 'fake.id2'}), + new Doc({section: 'api', id: 'fake.id3'})]; + }); + + it('should throw exception when any link doesn\'t exist', function() { + expect(function() { + ngdoc.merge(docs); + }).toThrow(); + }); + + it('should say which link doesn\'t exist', function() { + try { + ngdoc.merge(docs); + } catch (e) { + expect(e).toContain('non-existing-link'); + } + }); + it('should say where is the non-existing link', function() { + try { + ngdoc.merge(docs); + } catch (e) { + expect(e).toContain('api/fake.id1'); + } + }); + }); }); //////////////////////////////////////// diff --git a/docs/src/ngdoc.js b/docs/src/ngdoc.js index 869fe4c5..c2f5256a 100644 --- a/docs/src/ngdoc.js +++ b/docs/src/ngdoc.js @@ -29,6 +29,7 @@ function Doc(text, file, line) { this.param = this.param || []; this.properties = this.properties || []; this.methods = this.methods || []; + this.links = this.links || []; } Doc.METADATA_IGNORE = (function(){ var words = require('fs').readFileSync(__dirname + '/ignore.words', 'utf8'); @@ -124,11 +125,16 @@ Doc.prototype = { text = text.replace(/<angular\/>/gm, '<tt><angular/></tt>'); text = text.replace(/{@link\s+([^\s}]+)\s*([^}]*?)\s*}/g, function(_all, url, title){ - var isFullUrl = url.match(IS_URL); - return '<a href="' + (isFullUrl ? '' + url : '#!' + self.sectionHuristic(url)) + '">' - + (url.match(IS_ANGULAR) ? '<code>' : '') + var isFullUrl = url.match(IS_URL), + isAngular = url.match(IS_ANGULAR); + + url = isFullUrl ? url : self.sectionHuristic(url); + self.links.push(url); + + return '<a href="' + (isFullUrl ? '' + url : '#!' + url) + '">' + + (isAngular ? '<code>' : '') + (title || url).replace(/\n/g, ' ') - + (url.match(IS_ANGULAR) ? '</code>' : '') + + (isAngular ? '</code>' : '') + '</a>'; }); text = new Showdown.converter().makeHtml(text); @@ -659,9 +665,12 @@ function indent(text, spaceCount) { ////////////////////////////////////////////////////////// function merge(docs){ - var byName = {}; + var byName = {}, + byFullId = {}; + docs.forEach(function(doc){ byName[doc.name] = doc; + byFullId[doc.section + '/' + doc.id] = doc; }); for(var i=0; i<docs.length;) { if (findParent(docs[i], 'method') || @@ -671,6 +680,13 @@ function merge(docs){ i++; } } + + // check links + docs.forEach(function(doc) { + doc.links.forEach(function(link) { + if (!byFullId[link]) throw 'Not existing link "' + link + '" in ' + doc.section + '/' + doc.id; + }); + }); function findParent(doc, name){ var parentName = doc[name+'Of']; |
