Skip to content
This repository has been archived by the owner on Jan 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #83 from roxeteer/master
Browse files Browse the repository at this point in the history
feat(): Support for documenting controllers and capitalized services, prettyprint custom usage examples
  • Loading branch information
m7r committed Apr 14, 2014
2 parents 504c4a2 + f228e1d commit 24a2680
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
7 changes: 7 additions & 0 deletions spec/ngdocSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ describe('ngdoc', function() {
expect(doc.links).toContain('api/angular.link');
});

it('should correctly parse capitalized service names', function(){
var doc = new Doc('@ngdoc service\n@name my.module.Service');
doc.parse();
expect(ngdoc.metadata([doc])[0].shortName).toEqual('my.module.Service');
expect(ngdoc.metadata([doc])[0].moduleName).toEqual('my.module');
});

describe('convertUrlToAbsolute', function() {
var doc;

Expand Down
21 changes: 13 additions & 8 deletions src/ngdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -672,10 +672,8 @@ Doc.prototype = {
*/

if (self.usage) {
dom.tag('pre', function() {
dom.tag('code', function() {
dom.text(self.usage);
});
dom.code(function() {
dom.text(self.usage);
});
} else {
if (restrict.match(/E/)) {
Expand Down Expand Up @@ -847,6 +845,10 @@ Doc.prototype = {
this.html_usage_interface(dom)
},

html_usage_controller: function(dom) {
this.html_usage_interface(dom)
},

method_properties_events: function(dom) {
var self = this;
if (self.methods.length) {
Expand Down Expand Up @@ -929,8 +931,9 @@ Doc.prototype = {
var GLOBALS = /^angular\.([^\.]+)$/,
MODULE = /^([^\.]+)$/,
MODULE_MOCK = /^angular\.mock\.([^\.]+)$/,
MODULE_DIRECTIVE = /^(.+)\.directive:([^\.]+)$/,
MODULE_DIRECTIVE_INPUT = /^(.+)\.directive:input\.([^\.]+)$/,
MODULE_CONTROLLER = /^(.+)\.controllers?:([^\.]+)$/,
MODULE_DIRECTIVE = /^(.+)\.directives?:([^\.]+)$/,
MODULE_DIRECTIVE_INPUT = /^(.+)\.directives?:input\.([^\.]+)$/,
MODULE_CUSTOM = /^(.+)\.([^\.]+):([^\.]+)$/,
MODULE_SERVICE = /^(.+)\.([^\.]+?)(Provider)?$/,
MODULE_TYPE = /^([^\.]+)\..+\.([A-Z][^\.]+)$/;
Expand Down Expand Up @@ -977,13 +980,15 @@ function title(doc) {
return makeTitle(overview ? '' : match[1], '', 'module', match[1]);
} else if (match = text.match(MODULE_MOCK)) {
return makeTitle('angular.mock.' + match[1], 'API', 'module', 'ng');
} else if (match = text.match(MODULE_CONTROLLER) && doc.type === 'controller') {
return makeTitle(match[2], 'controller', 'module', match[1]);
} else if (match = text.match(MODULE_DIRECTIVE)) {
return makeTitle(match[2], 'directive', 'module', match[1]);
} else if (match = text.match(MODULE_DIRECTIVE_INPUT)) {
return makeTitle('input [' + match[2] + ']', 'directive', 'module', match[1]);
} else if (match = text.match(MODULE_CUSTOM)) {
return makeTitle(match[3], match[2], 'module', match[1]);
} else if (match = text.match(MODULE_TYPE)) {
return makeTitle(match[3], doc.ngdoc || match[2], 'module', match[1]);
} else if (match = text.match(MODULE_TYPE) && doc.ngdoc === 'type') {
return makeTitle(match[2], 'type', 'module', module || match[1]);
} else if (match = text.match(MODULE_SERVICE)) {
if (overview) {
Expand Down
7 changes: 7 additions & 0 deletions src/templates/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@
<a href="{{page.url}}" tabindex="2">{{page.shortName}}</a>
</li>

<li class="nav-header section" ng-show="module.controllers">
<a class="guide">controller</a>
</li>
<li ng-repeat="page in module.controllers track by page.url" ng-class="navClass(page)" class="api-list-item expand">
<a href="{{page.url}}" tabindex="2">{{page.shortName}}</a>
</li>

<li class="nav-header section" ng-show="module.filters">
<a class="guide">filter</a>
</li>
Expand Down
28 changes: 23 additions & 5 deletions src/templates/js/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,10 @@ docsApp.controller.DocsController = function($scope, $location, $window, section
GLOBALS = /^angular\.([^\.]+)$/,
MODULE = /^([^\.]+)$/,
MODULE_MOCK = /^angular\.mock\.([^\.]+)$/,
MODULE_DIRECTIVE = /^(.+)\.directive:([^\.]+)$/,
MODULE_DIRECTIVE_INPUT = /^(.+)\.directive:input\.([^\.]+)$/,
MODULE_FILTER = /^(.+)\.filter:([^\.]+)$/,
MODULE_CONTROLLER = /^(.+)\.controllers?:([^\.]+)$/,
MODULE_DIRECTIVE = /^(.+)\.directives?:([^\.]+)$/,
MODULE_DIRECTIVE_INPUT = /^(.+)\.directives?:input\.([^\.]+)$/,
MODULE_FILTER = /^(.+)\.filters?:([^\.]+)$/,
MODULE_CUSTOM = /^(.+)\.([^\.]+):([^\.]+)$/,
MODULE_SERVICE = /^(.+)\.([^\.]+?)(Provider)?$/,
MODULE_TYPE = /^([^\.]+)\..+\.([A-Z][^\.]+)$/;
Expand Down Expand Up @@ -370,6 +371,9 @@ docsApp.controller.DocsController = function($scope, $location, $window, section
match[1] = page.moduleName || match[1];
breadcrumb.push({ name: match[1], url: sectionPath + '/' + match[1] });
breadcrumb.push({ name: match[2] });
} else if (match = partialId.match(MODULE_CONTROLLER)) {
breadcrumb.push({ name: match[1], url: sectionPath + '/' + match[1] });
breadcrumb.push({ name: match[2] });
} else if (match = partialId.match(MODULE_DIRECTIVE)) {
breadcrumb.push({ name: match[1], url: sectionPath + '/' + match[1] });
breadcrumb.push({ name: match[2] });
Expand Down Expand Up @@ -456,13 +460,26 @@ docsApp.controller.DocsController = function($scope, $location, $window, section
module(page.moduleName || match[1], section);
} else if (match = id.match(MODULE_FILTER)) {
module(page.moduleName || match[1], section).filters.push(page);
} else if (match = id.match(MODULE_CONTROLLER) && page.type === 'controller') {
module(page.moduleName || match[1], section).controllers.push(page);
} else if (match = id.match(MODULE_DIRECTIVE)) {
module(page.moduleName || match[1], section).directives.push(page);
} else if (match = id.match(MODULE_DIRECTIVE_INPUT)) {
module(page.moduleName || match[1], section).directives.push(page);
} else if (match = id.match(MODULE_CUSTOM)) {
module(page.moduleName || match[1], section).others.push(page);
} else if (match = id.match(MODULE_TYPE)) {
if (page.type === 'service') {
module(page.moduleName || match[1], section).service(match[3])[page.id.match(/^.+Provider$/) ? 'provider' : 'instance'] = page;
} else {
var m = module(page.moduleName || match[1], section),
listName = page.type + 's';

if (m[listName]) {
m[listName].push(page);
} else {
m.others.push(page);
}
}
} else if (match = id.match(MODULE_TYPE) && page.type === 'type') {
module(page.moduleName || match[1], section).types.push(page);
} else if (match = id.match(MODULE_SERVICE)) {
if (page.type === 'overview') {
Expand All @@ -487,6 +504,7 @@ docsApp.controller.DocsController = function($scope, $location, $window, section
name: name,
url: (NG_DOCS.html5Mode ? '' : '#/') + section + '/' + name,
globals: [],
controllers: [],
directives: [],
services: [],
others: [],
Expand Down

0 comments on commit 24a2680

Please sign in to comment.