Skip to content

Commit

Permalink
chore(doc-gen): render void attributes in directive usage
Browse files Browse the repository at this point in the history
When a directive doesn't take a value, its name is not included
in the parameters, which previously meant that the directive name
was missing from the Usage section of the docs.

This commit adds the name to the Usage section when it is missing
from the parameters.

Closes angular#14045
  • Loading branch information
Narretz committed Oct 11, 2017
1 parent 35f4e2f commit 4921e3f
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions docs/config/templates/ngdoc/api/directive.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,22 @@ <h2 id="usage">Usage</h2>
</li>
{% endif -%}


{% set hasNameAsParam = false %}

{# when a directive's name is not a parameter (i.e. doesn't take a value),
add the directive name to the list of attributes and/or css classes #}

{%- for param in doc.params %}
{% set hasNameAsParam = true if param.name === doc.name else hasNameAsParam %}
{%- endfor %}

{%- if doc.restrict.attribute -%}
<li>as attribute:
{% code %}
<{$ doc.element $}
{%- for param in doc.params %}
<{$ doc.element $} {%- if not hasNameAsParam %}
{$ lib.directiveParam(doc.name, {}, '', '') $}
{%- endif -%} {%- for param in doc.params %}
{$ lib.directiveParam(param.name, param.type, '="', '"') $}
{%- endfor %}>
...
Expand All @@ -43,10 +54,14 @@ <h2 id="usage">Usage</h2>
{% endif -%}

{%- if doc.restrict.cssClass -%}

<li>as CSS class:
{% code %}
{% set sep = joiner(' ') %}
<{$ doc.element $} class="
{%- if not hasNameAsParam -%}
{$ sep() $}{$ lib.directiveParam(doc.name, {}, '', '') $}
{%- endif -%}
{%- for param in doc.params -%}
{$ sep() $}{$ lib.directiveParam(param.name, param.type, ': ', ';') $}
{%- endfor %}"> ... </{$ doc.element $}>
Expand Down

0 comments on commit 4921e3f

Please sign in to comment.