mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-23 21:35:47 +00:00
Log warning for every non existing link instead of throwing exception
Guess we don't want to stop doc generating process because of non-existing link, so just log warning and continue...
This commit is contained in:
parent
2e0e732cad
commit
8cb84eac68
2 changed files with 18 additions and 19 deletions
|
|
@ -208,31 +208,26 @@ describe('ngdoc', function(){
|
||||||
describe('links checking', function() {
|
describe('links checking', function() {
|
||||||
var docs;
|
var docs;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
|
spyOn(console, 'log');
|
||||||
docs = [new Doc({section: 'api', id: 'fake.id1', links: ['non-existing-link']}),
|
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.id2'}),
|
||||||
new Doc({section: 'api', id: 'fake.id3'})];
|
new Doc({section: 'api', id: 'fake.id3'})];
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw exception when any link doesn\'t exist', function() {
|
it('should log warning when any link doesn\'t exist', function() {
|
||||||
expect(function() {
|
ngdoc.merge(docs);
|
||||||
ngdoc.merge(docs);
|
expect(console.log).toHaveBeenCalled();
|
||||||
}).toThrow();
|
expect(console.log.argsForCall[0][0]).toContain('WARNING:');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should say which link doesn\'t exist', function() {
|
it('should say which link doesn\'t exist', function() {
|
||||||
try {
|
ngdoc.merge(docs);
|
||||||
ngdoc.merge(docs);
|
expect(console.log.argsForCall[0][0]).toContain('non-existing-link');
|
||||||
} catch (e) {
|
|
||||||
expect(e).toContain('non-existing-link');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should say where is the non-existing link', function() {
|
it('should say where is the non-existing link', function() {
|
||||||
try {
|
ngdoc.merge(docs);
|
||||||
ngdoc.merge(docs);
|
expect(console.log.argsForCall[0][0]).toContain('api/fake.id1');
|
||||||
} catch (e) {
|
|
||||||
expect(e).toContain('api/fake.id1');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -126,12 +126,16 @@ Doc.prototype = {
|
||||||
text = text.replace(/{@link\s+([^\s}]+)\s*([^}]*?)\s*}/g,
|
text = text.replace(/{@link\s+([^\s}]+)\s*([^}]*?)\s*}/g,
|
||||||
function(_all, url, title){
|
function(_all, url, title){
|
||||||
var isFullUrl = url.match(IS_URL),
|
var isFullUrl = url.match(IS_URL),
|
||||||
|
// FIXME(vojta) angular link could be api.angular now with sections
|
||||||
isAngular = url.match(IS_ANGULAR);
|
isAngular = url.match(IS_ANGULAR);
|
||||||
|
|
||||||
url = isFullUrl ? url : self.sectionHuristic(url);
|
if (!isFullUrl) {
|
||||||
self.links.push(url);
|
// 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));
|
||||||
|
}
|
||||||
|
|
||||||
return '<a href="' + (isFullUrl ? '' + url : '#!' + url) + '">'
|
return '<a href="' + (isFullUrl ? '' + url : '#!' + self.sectionHuristic(url)) + '">'
|
||||||
+ (isAngular ? '<code>' : '')
|
+ (isAngular ? '<code>' : '')
|
||||||
+ (title || url).replace(/\n/g, ' ')
|
+ (title || url).replace(/\n/g, ' ')
|
||||||
+ (isAngular ? '</code>' : '')
|
+ (isAngular ? '</code>' : '')
|
||||||
|
|
@ -684,7 +688,7 @@ function merge(docs){
|
||||||
// check links
|
// check links
|
||||||
docs.forEach(function(doc) {
|
docs.forEach(function(doc) {
|
||||||
doc.links.forEach(function(link) {
|
doc.links.forEach(function(link) {
|
||||||
if (!byFullId[link]) throw 'Not existing link "' + link + '" in ' + doc.section + '/' + doc.id;
|
if (!byFullId[link]) console.log('WARNING: Non existing link "' + link + '" in ' + doc.section + '/' + doc.id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue