build(docs-infra): include directives etc in class descendants lists (#25768)

PR Close #25768
This commit is contained in:
Pete Bacon Darwin 2018-09-20 12:58:10 +01:00 committed by Alex Rickabaugh
parent ce06a75ebf
commit 15dadb92ef
6 changed files with 40 additions and 12 deletions

View File

@ -8,7 +8,19 @@ describe('Api pages', function() {
it('should show direct and indirect subclasses of a class', () => {
const page = new ApiPage('api/forms/AbstractControlDirective');
expect(page.getDescendants('class')).toEqual(['ControlContainer', 'AbstractFormGroupDirective', 'NgControl']);
expect(page.getDescendants('class')).toEqual([
'ControlContainer',
'AbstractFormGroupDirective',
'NgModelGroup',
'FormGroupName',
'NgForm',
'FormGroupDirective',
'FormArrayName',
'NgControl',
'NgModel',
'FormControlDirective',
'FormControlName'
]);
});
it('should show child interfaces that extend an interface', () => {

View File

@ -3,7 +3,12 @@ module.exports = function filterBy() {
name: 'filterByPropertyValue',
process: function(list, property, value) {
if (!list) return list;
return list.filter(item => item[property] === value);
const values = Array.isArray(value) ? value : [value];
return list.filter(item => values.some(value => compare(item[property], value)));
}
};
};
};
function compare(actual, expected) {
return expected instanceof(RegExp) ? expected.test(actual) : actual === expected;
}

View File

@ -7,8 +7,19 @@ describe('filterByPropertyValue filter', () => {
it('should be called "filterByPropertyValue"', function() { expect(filter.name).toEqual('filterByPropertyValue'); });
it('should filter out items that do not match the given property value', function() {
it('should filter out items that do not match the given property string value', function() {
expect(filter.process([{ a: 1 }, { a: 2 }, { b: 1 }, { a: 1, b: 2 }, { a: null }, { a: undefined }], 'a', 1))
.toEqual([{ a: 1 }, { a: 1, b: 2 }]);
});
it('should filter out items that do not match the given property regex value', function() {
expect(filter.process([{ a: '1' }, { a: '12' }, { b: '1' }, { a: 'a' }, { a: '1', b: '2' }, { a: null }, { a: undefined }], 'a', /\d/))
.toEqual([{ a: '1' }, { a: '12' }, { a: '1', b: '2' }]);
});
it('should filter out items that do not match the given array of property regex/string values', function() {
expect(filter.process([{ a: '1' }, { a: '12' }, { b: '1' }, { a: 'a' }, { a: '1', b: '2' }, { a: null }, { a: undefined }], 'a', [/\d/, 'a']))
.toEqual([{ a: '1' }, { a: '12' }, { a: 'a' }, { a: '1', b: '2' }]);
});
});

View File

@ -6,5 +6,5 @@
{% if doc.isAbstract %}abstract {% endif%}class {$ doc.name $}{$ doc.typeParams | escape $}{$ memberHelper.renderHeritage(doc) $} {{$ memberHelper.renderMembers(doc) $}
}
</code-example>
{$ descendants.renderDescendants(doc, 'class', 'Subclasses') $}
{$ descendants.renderDescendants(doc, 'class', 'Subclasses', true, r/class|directive|pipe|decorator/) $}
</section>

View File

@ -6,5 +6,5 @@ interface {$ doc.name $}{$ doc.typeParams | escape $}{$ memberHelper.renderHerit
}
</code-example>
{$ descendants.renderDescendants(doc, 'interface', 'Child interfaces') $}
{$ descendants.renderDescendants(doc, 'class', 'Class implementations') $}
{$ descendants.renderDescendants(doc, 'class', 'Class implementations', true, r/class|directive|pipe|decorator/) $}
</section>

View File

@ -1,22 +1,22 @@
{% macro renderDescendantList(descendants, docType, recursed) %}
{% macro renderDescendantList(descendants, descendantType, recursed, docTypeMatcher) %}
{% if descendants.length %}
<ul>
{% for descendant in descendants %}
<li>
<code>{$ descendant.name $}</code>
{$ renderDescendantList(descendant.descendants | filterByPropertyValue('docType', docType), docType, recursed) $}
{$ renderDescendantList(descendant.descendants | filterByPropertyValue('docType', docTypeMatcher), docType, recursed, docTypeMatcher) $}
</li>
{% endfor %}
</ul>
{% endif %}
{% endmacro -%}
{%- macro renderDescendants(doc, docType, title='', recursed=true) %}
{% set descendants = doc.descendants | filterByPropertyValue('docType', docType) %}
{%- macro renderDescendants(doc, descendantType, title='', recursed=true, docTypeMatcher=descendantType) %}
{% set descendants = doc.descendants | filterByPropertyValue('docType', docTypeMatcher) %}
{% if descendants.length %}
<div class="descendants {$ docType $}">
<div class="descendants {$ descendantType $}">
{% if title %}<h2>{$ title $}</h2>{% endif %}
{$ renderDescendantList(descendants, docType, recursed) $}
{$ renderDescendantList(descendants, descendantType, recursed, docTypeMatcher) $}
</div>
{% endif %}
{% endmacro %}