From 2e0e732cadd86846b57b7b02b3303a2e0e3b842a Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Tue, 17 May 2011 22:12:23 +0200 Subject: Check whether links do exist and throw exception --- docs/spec/ngdocSpec.js | 37 +++++++++++++++++++++++++++++++++++++ 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('
before
\n<>\n
after
'); }); + + 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(/' : '')
+ var isFullUrl = url.match(IS_URL),
+ isAngular = url.match(IS_ANGULAR);
+
+ url = isFullUrl ? url : self.sectionHuristic(url);
+ self.links.push(url);
+
+ return ''
+ + (isAngular ? '' : '')
+ (title || url).replace(/\n/g, ' ')
- + (url.match(IS_ANGULAR) ? '' : '')
+ + (isAngular ? '' : '')
+ '';
});
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