chore(doc-gen): filter unwanted decorators from angular.io docs
Closes https://github.com/angular/angular/issues/3705
This commit is contained in:
parent
2633d2b164
commit
23452bffa0
|
@ -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'
|
||||
];
|
||||
})
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
|
@ -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' } ] }
|
||||
]);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue