chore(doc-gen): filter unwanted decorators from angular.io docs

Closes https://github.com/angular/angular/issues/3705
This commit is contained in:
Peter Bacon Darwin 2015-10-17 16:46:19 +01:00
parent 2633d2b164
commit 23452bffa0
3 changed files with 75 additions and 0 deletions

View File

@ -6,6 +6,7 @@ module.exports = new Package('angular.io', [basePackage])
.factory(require('./services/renderMarkdown'))
.processor(require('./processors/addJadeDataDocsProcessor'))
.processor(require('./processors/filterUnwantedDecorators'))
// overrides base packageInfo and returns the one for the 'angular/angular' repo.
.factory(require('./services/packageInfo'))
@ -88,4 +89,12 @@ module.exports = new Package('angular.io', [basePackage])
]));
})
.config(function(filterUnwantedDecorators, log) {
log.level = 'info';
filterUnwantedDecorators.decoratorsToIgnore = [
'CONST',
'IMPLEMENTS',
'ABSTRACT'
];
})

View File

@ -0,0 +1,20 @@
var _ = require('lodash');
module.exports = function filterUnwantedDecorators() {
return {
decoratorsToIgnore: [],
$runAfter: ['processing-docs'],
$runBefore: ['docs-processed'],
$process: function(docs) {
var decoratorsToIgnore = this.decoratorsToIgnore || [];
_.forEach(docs, function(doc) {
if (doc.decorators) {
doc.decorators = _.filter(doc.decorators, function(decorator) {
return decoratorsToIgnore.indexOf(decorator.name) === -1;
});
}
});
return docs;
}
};
}

View File

@ -0,0 +1,46 @@
var mockPackage = require('../mocks/mockPackage');
var Dgeni = require('dgeni');
describe('filterUnwantedDecorators', function() {
var dgeni, injector, processor;
beforeEach(function() {
dgeni = new Dgeni([mockPackage()]);
injector = dgeni.configureInjector();
processor = injector.get('filterUnwantedDecorators');
});
it('should remove decorators specified by name', function() {
var docs = [
{ id: 'doc1', decorators: [ { name: 'A' }, { name: 'B' } ] },
{ id: 'doc2', decorators: [ { name: 'B' }, { name: 'C' } ] },
{ id: 'doc3', decorators: [ { name: 'A' }, { name: 'C' } ] }
];
processor.decoratorsToIgnore = ['D', 'B'];
docs = processor.$process(docs);
expect(docs).toEqual([
{ id: 'doc1', decorators: [ { name: 'A' } ] },
{ id: 'doc2', decorators: [ { name: 'C' } ] },
{ id: 'doc3', decorators: [ { name: 'A' }, { name: 'C' } ] }
]);
});
it('should ignore docs that have no decorators', function() {
var docs = [
{ id: 'doc1', decorators: [ { name: 'A' }, { name: 'B' } ] },
{ id: 'doc2' },
{ id: 'doc3', decorators: [ { name: 'A' }, { name: 'C' } ] }
];
processor.decoratorsToIgnore = ['D', 'B'];
docs = processor.$process(docs);
expect(docs).toEqual([
{ id: 'doc1', decorators: [ { name: 'A' } ] },
{ id: 'doc2' },
{ id: 'doc3', decorators: [ { name: 'A' }, { name: 'C' } ] }
]);
});
});