diff --git a/docs/app/e2e/api-docs/directive-pages.scenario.js b/docs/app/e2e/api-docs/directive-pages.scenario.js new file mode 100644 index 000000000000..cec2d484545d --- /dev/null +++ b/docs/app/e2e/api-docs/directive-pages.scenario.js @@ -0,0 +1,58 @@ +'use strict'; + +describe('directives', function() { + + describe('parameter section', function() { + + it('should show the directive name only if it is a param (attribute) with a value', function() { + 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'); + }); + }); + + describe('usage section', function() { + + it('should show the directive name if it is a param (attribute) with a value', function() { + browser.get('build/docs/index.html#!/api/ng/directive/ngInclude'); + + expect(getUsageAs('element', 'ng-include').isPresent()).toBe(true); + expect(getUsageAs('attribute', 'ng-include').isPresent()).toBe(true); + expect(getUsageAs('CSS class', 'ng-include').isPresent()).toBe(true); + }); + + it('should show the directive name if it is a void param (attribute)', function() { + browser.get('build/docs/index.html#!/api/ngRoute/directive/ngView'); + + expect(getUsageAs('element', 'ng-view').isPresent()).toBe(true); + expect(getUsageAs('attribute', 'ng-view').isPresent()).toBe(true); + expect(getUsageAs('CSS class', 'ng-view').isPresent()).toBe(true); + }); + }); +}); + +function getParamNames() { + var argsSection = element(by.className('input-arguments')); + + var paramNames = argsSection.all(by.css('tr td:nth-child(1)')); + + return paramNames; +} + +// Based on the type of directive usage, the directive name will show up in the code block +// with a specific class +var typeClassMap = { + element: 'tag', + attribute: 'atn', + 'CSS class': 'atv' +}; + +function getUsageAs(type, directiveName) { + var usage = element(by.className('usage')); + + var as = usage.element(by.cssContainingText('li', 'as ' + type)); + + return as.element(by.cssContainingText('span.' + typeClassMap[type], directiveName)); +} diff --git a/docs/config/templates/ngdoc/api/directive.template.html b/docs/config/templates/ngdoc/api/directive.template.html index fd9c9972f1c1..0a3480eee988 100644 --- a/docs/config/templates/ngdoc/api/directive.template.html +++ b/docs/config/templates/ngdoc/api/directive.template.html @@ -29,10 +29,23 @@

Usage

{% 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 -%}
  • as attribute: {% code %} <{$ doc.element $} + {%- if not hasNameAsParam %} + {$ lib.directiveParam(doc.name, {}, '', '') $} + {%- endif -%} {%- for param in doc.params %} {$ lib.directiveParam(param.name, param.type, '="', '"') $} {%- endfor %}> @@ -43,10 +56,14 @@

    Usage

    {% endif -%} {%- if doc.restrict.cssClass -%} +
  • 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 %}"> ...