mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
Bit of refactoring
This commit is contained in:
parent
864da8b553
commit
7fe46e8d7e
2 changed files with 22 additions and 25 deletions
|
|
@ -192,15 +192,15 @@ describe('ngdoc', function(){
|
|||
|
||||
describe('merge', function(){
|
||||
it('should merge child with parent', function(){
|
||||
var parent = new Doc({name:'angular.service.abc'});
|
||||
var methodA = new Doc({name:'methodA', methodOf:'angular.service.abc'});
|
||||
var methodB = new Doc({name:'methodB', methodOf:'angular.service.abc'});
|
||||
var propA = new Doc({name:'propA', propertyOf:'angular.service.abc'});
|
||||
var propB = new Doc({name:'propB', propertyOf:'angular.service.abc'});
|
||||
var parent = new Doc({id: 'angular.service.abc', name: 'angular.service.abc', section: 'api'});
|
||||
var methodA = new Doc({name: 'methodA', methodOf: 'angular.service.abc'});
|
||||
var methodB = new Doc({name: 'methodB', methodOf: 'angular.service.abc'});
|
||||
var propA = new Doc({name: 'propA', propertyOf: 'angular.service.abc'});
|
||||
var propB = new Doc({name: 'propB', propertyOf: 'angular.service.abc'});
|
||||
var docs = [methodB, methodA, propB, propA, parent]; // keep wrong order;
|
||||
ngdoc.merge(docs);
|
||||
expect(docs.length).toEqual(1);
|
||||
expect(docs[0].name).toEqual('angular.service.abc');
|
||||
expect(docs[0].id).toEqual('angular.service.abc');
|
||||
expect(docs[0].methods).toEqual([methodA, methodB]);
|
||||
expect(docs[0].properties).toEqual([propA, propB]);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -669,36 +669,33 @@ function indent(text, spaceCount) {
|
|||
|
||||
//////////////////////////////////////////////////////////
|
||||
function merge(docs){
|
||||
// TODO(vojta) refactor to use only byFullId hash map
|
||||
var byName = {},
|
||||
byFullId = {};
|
||||
var byFullId = {};
|
||||
|
||||
docs.forEach(function(doc){
|
||||
byName[doc.name] = doc;
|
||||
docs.forEach(function (doc) {
|
||||
byFullId[doc.section + '/' + doc.id] = doc;
|
||||
});
|
||||
for(var i=0; i<docs.length;) {
|
||||
if (findParent(docs[i], 'method') ||
|
||||
findParent(docs[i], 'property')) {
|
||||
|
||||
for(var i = 0; i < docs.length;) {
|
||||
var doc = docs[i];
|
||||
|
||||
// check links - do they exist ?
|
||||
doc.links.forEach(function(link) {
|
||||
if (!byFullId[link]) console.log('WARNING: Non existing link "' + link + '" in ' + doc.section + '/' + doc.id);
|
||||
});
|
||||
|
||||
// merge into parents
|
||||
if (findParent(doc, 'method') || findParent(doc, 'property')) {
|
||||
docs.splice(i, 1);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// check links
|
||||
// TODO(vojta) refactor to reuse the loop above
|
||||
docs.forEach(function(doc) {
|
||||
doc.links.forEach(function(link) {
|
||||
if (!byFullId[link]) console.log('WARNING: Non existing link "' + link + '" in ' + doc.section + '/' + doc.id);
|
||||
});
|
||||
});
|
||||
|
||||
function findParent(doc, name){
|
||||
var parentName = doc[name+'Of'];
|
||||
function findParent(doc, name) {
|
||||
var parentName = doc[name + 'Of'];
|
||||
if (!parentName) return false;
|
||||
|
||||
var parent = byName[parentName];
|
||||
var parent = byFullId['api/' + parentName];
|
||||
if (!parent)
|
||||
throw new Error("No parent named '" + parentName + "' for '" +
|
||||
doc.name + "' in @" + name + "Of.");
|
||||
|
|
|
|||
Loading…
Reference in a new issue