mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-04-12 02:50:58 +00:00
Check whether links do exist and throw exception
This commit is contained in:
parent
22f9354c21
commit
2e0e732cad
2 changed files with 58 additions and 5 deletions
|
|
@ -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');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
|
|
|
|||
Loading…
Reference in a new issue