Skip to content

Commit

Permalink
build: dgeni add deprecated marker
Browse files Browse the repository at this point in the history
* Adds a class to property rows in the template that can be used to distinguish between deprecated and stable APIs.

Fixes #3981.
  • Loading branch information
devversion committed Apr 11, 2017
1 parent c38c9c3 commit 5d794b1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
20 changes: 20 additions & 0 deletions tools/dgeni/processors/categorizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ module.exports = function categorizer() {
classDoc.methods.forEach(doc => decorateMethodDoc(doc));
classDoc.properties.forEach(doc => decoratePropertyDoc(doc));

decoratePublicDoc(classDoc);

// Categorize the current visited classDoc into its Angular type.
if (isDirective(classDoc)) {
classDoc.isDirective = true;
Expand All @@ -45,6 +47,7 @@ module.exports = function categorizer() {
**/
function decorateMethodDoc(methodDoc) {
normalizeMethodParameters(methodDoc);
decoratePublicDoc(methodDoc);

// Mark methods with a `void` return type so we can omit show the return type in the docs.
methodDoc.showReturns = methodDoc.returnType && methodDoc.returnType != 'void';
Expand All @@ -55,12 +58,25 @@ module.exports = function categorizer() {
* outputs will be marked. Aliases for the inputs or outputs will be stored as well.
**/
function decoratePropertyDoc(propertyDoc) {
decoratePublicDoc(propertyDoc);

propertyDoc.isDirectiveInput = isDirectiveInput(propertyDoc);
propertyDoc.directiveInputAlias = getDirectiveInputAlias(propertyDoc);

propertyDoc.isDirectiveOutput = isDirectiveOutput(propertyDoc);
propertyDoc.directiveOutputAlias = getDirectiveOutputAlias(propertyDoc);
}

/**
* Decorates public exposed docs. Creates a property with CSS classes that will be
* added to the template.
**/
function decoratePublicDoc(doc) {
// Specific classes that will can added to the Dgeni doc template.
doc.docClasses = [
isDeprecatedDoc(doc) ? 'docs-api-deprecated' : ''
].join(' ');
}
};

/** Function that walks through all inherited docs and collects public methods. */
Expand Down Expand Up @@ -146,6 +162,10 @@ function isDirectiveInput(doc) {
return hasMemberDecorator(doc, 'Input');
}

function isDeprecatedDoc(doc) {
return (doc.tags && doc.tags.tags || []).some(tag => tag.tagName === 'deprecated');
}

function getDirectiveInputAlias(doc) {
return isDirectiveInput(doc) ? doc.decorators.find(d => d.name == 'Input').arguments[0] : '';
}
Expand Down
22 changes: 12 additions & 10 deletions tools/dgeni/templates/class.template.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<h4 class="docs-api-h4 docs-api-class-name">
<code>{$ class.name $}</code>
</h4>
<p class="docs-api-class-description">{$ class.description $}</p>
<div class="{$ class.docClasses $}">
<h4 class="docs-api-h4 docs-api-class-name">
<code>{$ class.name $}</code>
</h4>
<p class="docs-api-class-description">{$ class.description $}</p>

{%- if class.directiveExportAs -%}
<span class="docs-api-h4 docs-api-class-export-label">Exported as:</span>
<span class="docs-api-class-export-name">{$ class.directiveExportAs $}</span>
{%- endif -%}
{%- if class.directiveExportAs -%}
<span class="docs-api-h4 docs-api-class-export-label">Exported as:</span>
<span class="docs-api-class-export-name">{$ class.directiveExportAs $}</span>
{%- endif -%}

{$ propertyList(class.properties) $}
{$ propertyList(class.properties) $}

{$ methodList(class.methods) $}
{$ methodList(class.methods) $}
</div>
2 changes: 1 addition & 1 deletion tools/dgeni/templates/method.template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<table class="docs-api-method-table">
<table class="docs-api-method-table {$ method.docClasses $}">
<thead>
<tr class="docs-api-method-name-row">
<th colspan="2" class="docs-api-method-name-cell">{$ method.name $}</th>
Expand Down
2 changes: 1 addition & 1 deletion tools/dgeni/templates/property.template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tr class="docs-api-properties-row">
<tr class="docs-api-properties-row {$ property.docClasses $}">
<td class="docs-api-properties-name-cell">
{%- if property.isDirectiveInput -%}
<div class="docs-api-input-marker">
Expand Down

0 comments on commit 5d794b1

Please sign in to comment.