diff --git a/aio/tools/transforms/angular-base-package/rendering/hasValues.js b/aio/tools/transforms/angular-base-package/rendering/hasValues.js new file mode 100644 index 0000000000..7b15501fa2 --- /dev/null +++ b/aio/tools/transforms/angular-base-package/rendering/hasValues.js @@ -0,0 +1,9 @@ +module.exports = function hasValues() { + return { + name: 'hasValues', + process: function(list, property) { + if (!list || !Array.isArray(list)) return false; + return list.some(item => item[property]); + } + }; +}; \ No newline at end of file diff --git a/aio/tools/transforms/angular-base-package/rendering/hasValues.spec.js b/aio/tools/transforms/angular-base-package/rendering/hasValues.spec.js new file mode 100644 index 0000000000..7f22c93e9d --- /dev/null +++ b/aio/tools/transforms/angular-base-package/rendering/hasValues.spec.js @@ -0,0 +1,19 @@ +const factory = require('./hasValues'); + +describe('hasValues filter', () => { + let filter; + + beforeEach(function() { filter = factory(); }); + + it('should be called "hasValues"', function() { expect(filter.name).toEqual('hasValues'); }); + + it('should return true if the specified property is truthy on any item in the list', function() { + expect(filter.process([], 'a')).toEqual(false); + expect(filter.process(0), 'a').toEqual(false); + expect(filter.process({}, 'a')).toEqual(false); + expect(filter.process([{a: 1}], 'a')).toEqual(true); + expect(filter.process([{b: 2}], 'a')).toEqual(false); + expect(filter.process([{a: 1, b: 2}], 'a')).toEqual(true); + expect(filter.process([{b: 2}, {a: 1}], 'a')).toEqual(true); + }); +}); \ No newline at end of file diff --git a/aio/tools/transforms/templates/api/enum.template.html b/aio/tools/transforms/templates/api/enum.template.html index 9c59159b29..0f07f88cbc 100644 --- a/aio/tools/transforms/templates/api/enum.template.html +++ b/aio/tools/transforms/templates/api/enum.template.html @@ -1 +1,14 @@ -{% extends 'class.template.html' -%} \ No newline at end of file +{% import "lib/memberHelpers.html" as memberHelpers -%} +{% extends 'export-base.template.html' -%} + +{% block details %} +
+ +enum {$ doc.name $} {{$ memberHelpers.renderMembers(doc) $} +} + +
+ +{% include "includes/description.html" %} +{$ memberHelpers.renderProperties(doc.properties, 'members', 'member', 'Members', ['Member', 'Value']) $} +{% endblock %} \ No newline at end of file diff --git a/aio/tools/transforms/templates/api/lib/memberHelpers.html b/aio/tools/transforms/templates/api/lib/memberHelpers.html index c278c3c3fc..2fdfb3b6e4 100644 --- a/aio/tools/transforms/templates/api/lib/memberHelpers.html +++ b/aio/tools/transforms/templates/api/lib/memberHelpers.html @@ -135,20 +135,25 @@ {%- endmacro -%} -{%- macro renderProperties(properties, containerClass, propertyClass, headingText) -%} +{%- macro renderProperties(properties, containerClass, propertyClass, headingText, headings) -%} {% set nonInternalProperties = properties | filterByPropertyValue('internal', undefined) %} +{% set hasTypes = properties | hasValues('type') %} {% if nonInternalProperties.length -%}

{$ headingText $}

- + + + {% if hasTypes %}{% endif %} + + {% for property in nonInternalProperties %} - + {% if hasTypes %}{% endif %}
PropertyTypeDescription
{$ headings[0] or 'Property' $}{$ headings[1] or 'Type' $}{$ headings[2] or 'Description' $}
{$ property.name $} {%- if (property.isGetAccessor or property.isReadonly) and not property.isSetAccessor %}Read-only.{% endif %} {% if property.shortDescription %}{$ property.shortDescription | marked $}{% endif %}