Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Fix docs usage section for directives with void attributes #16265

Merged
merged 3 commits into from
Oct 18, 2017

Conversation

Narretz
Copy link
Contributor

@Narretz Narretz commented Oct 11, 2017

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Improvement for the docs app

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change?

Please check if the PR fulfills these requirements

Other information:

@Narretz Narretz changed the title Docs usage Fix docs usage section for directives with void attributes Oct 11, 2017
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an e2e test for this?

{%- if doc.restrict.attribute -%}
<li>as attribute:
{% code %}
<{$ doc.element $}
{%- for param in doc.params %}
<{$ doc.element $} {%- if not hasNameAsParam %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that you have used {% - to ignore the whitespace, you may as well start this if block on the next line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like:

        <{$ doc.element $}
          {%- if not hasNameAsParam %}
          {$ lib.directiveParam(param.name, param.type, '="', '"') $}
          {% endif %}
          {%- for param in doc.params %}
          {$ lib.directiveParam(param.name, param.type, '="', '"') $}
          {%- endfor %}>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - I still need to include {%- endif -%} because otherwise there's a blank line after the directive name when hasNameAsParam is true.

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 Attribute / CSS Class usage section of the docs.

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

Closes angular#14045
@Narretz Narretz force-pushed the docs-usage branch 2 times, most recently from 950ad1b to 314c8b9 Compare October 13, 2017 13:33
@Narretz
Copy link
Contributor Author

Narretz commented Oct 13, 2017

Added tests to ensure that the directive name always appears in the usage section, whether it appears in the params or not.

@Narretz Narretz added this to the 1.6.x milestone Oct 13, 2017
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Thanks for the tests. I think they could be clearer if you did:

a) used helpers to find the params and usage elements, to hide the complexity of the CSS mangling from the tests
b) restructured the descriptions of the tests. Perhaps something like:

directive API docs
  when directive name is a param with a value
    should show directive name in params
    should show directive name in usage
  when directive name is a void param
    should not show directive name in params
    should show directive name in usage

@Narretz
Copy link
Contributor Author

Narretz commented Oct 17, 2017

Thanks for the review.

I introduced helpers.
I changed the structure, so that "usage" and "parameters" are separate describes. This made sense to me, because when we introduce more tests it feels logical to have the sections of the page be the top describes, instead of special casing "when directive name is ..." from the beginning.

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! Let's get this in...

One minor nit (but not blocking you merging this):

If one of the tests fails it will look like:

directives parameter section when directive name is a void param should not show the directive name in the parameters.

This doesn't read that well to me. I would drop the inner describe blocks altogether and just have longer it clauses. E.g.

describe('directives', () => {
  describe('parameter section', () => {
    it('should show the directive name only if it is a named param', () => {
       browser.get('build/docs/index.html#!/api/ng/directive/ngInclude');
       expect(getParamNames().getText()).toContain('ngInclude | src');

      browser.get('build/docs/index.html#!/api/ngRoute/directive/ngView');
      expect(getParamNames().getText()).not.toContain('ngView');
    });

Then you would get an error message like:

directives parameter section should show the directive name only if it is a named param

etc

@petebacondarwin
Copy link
Contributor

Don't forget to squash the extra commit :-)

@Narretz Narretz merged commit 69e0968 into angular:master Oct 18, 2017
Narretz added a commit that referenced this pull request Oct 19, 2017
When a directive can be used as an attribute or CSS class, but doesn't take 
a value, its name is not included in the parameters, which previously meant 
that the directive name was missing from the Attribute / CSS Class usage 
section of the docs.

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

Closes #14045
Closes #16265
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants