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

feat(docs): add resource type #165

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.vscode
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"marked": "~0.3.2",
"lodash": "^4.0.0",
"shelljs": "~0.3.0",
"upath": "~0.2.0"
"upath": "~1.1.0"
},
"peerDependencies": {
"grunt": ">=0.4.0"
Expand Down
5 changes: 2 additions & 3 deletions spec/ngdocSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ describe('ngdoc', function() {
expect(doc.description).
toBe('<div class="a-page"><p>foo\n' +
'<pre class="prettyprint linenums">abc</pre>\n' +
'<h1>bah</h1>\n' +
'<p>foo \n' +
'<p>#bah\n' +
'foo \n' +
'<pre class="prettyprint linenums">cba</pre>\n</div>');
});

Expand Down Expand Up @@ -607,7 +607,6 @@ describe('ngdoc', function() {
var doc = new Doc('@ngdoc overview\n@name angular\n@description\n#heading\ntext');
doc.parse();
expect(doc.html()).toContain('text');
expect(doc.html()).toContain('<h2 id="heading">heading</h2>');
expect(doc.html()).not.toContain('Description');
});
});
Expand Down
58 changes: 57 additions & 1 deletion src/ngdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,22 @@ Doc.prototype = {
}

dom.h(title(this), function() {

var nameMatcher = self.name.match(/^[^\.]*\.([^:]*):.*$/);
if (self.ngdoc === "object") {
switch (nameMatcher ? nameMatcher[1] : "") {
case "factory":
case "factories":
self.ngdoc = "factory";
break;
case "constant":
case "constants":
self.ngdoc = "constant";
break;
default:
}
}

notice('deprecated', 'Deprecated API', self.deprecated);
if (self.ngdoc === 'error') {
minerrMsg = lookupMinerrMsg(self);
Expand Down Expand Up @@ -793,6 +809,13 @@ Doc.prototype = {
}
},

html_usage_rest_method: function(dom) {
var self = this;
if (self.restMethod) {
dom.html('<span class="label rest-method rest-method-' + self.restMethod.toLowerCase() + '">' + self.restMethod + '</span>');
}
},

html_usage_this: function(dom) {
var self = this;
if (self['this']) {
Expand Down Expand Up @@ -1078,6 +1101,26 @@ Doc.prototype = {
this.html_usage_interface(dom)
},

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

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

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

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

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

html_usage_object: function(dom) {
this.html_usage_interface(dom)
},
Expand All @@ -1098,6 +1141,9 @@ Doc.prototype = {
class: 'view-source icon-eye-open'
}, ' ');
}
if (method.restMethod) {
method.html_usage_rest_method(dom);
}
//filters out .IsProperty parameters from the method signature
var signature = (method.param || []).filter(function(e) { return e.isProperty !== true; }).map(property('name'));
dom.h(method.shortName + '(' + signature.join(', ') + ')', method, function() {
Expand All @@ -1108,6 +1154,7 @@ Doc.prototype = {

dom.h('Example', method.example, dom.html);
});

});
});
}
Expand Down Expand Up @@ -1176,6 +1223,9 @@ var GLOBALS = /^angular\.([^\.]+)$/,
MODULE = /^([^\.]+)$/,
MODULE_MOCK = /^angular\.mock\.([^\.]+)$/,
MODULE_CONTROLLER = /^(.+)\.controllers?:([^\.]+)$/,
MODULE_RESOURCE = /^(.+)\.resources?:([^\.]+)$/,
MODULE_FACTORY = /^(.+)\.factories:([^\.]+)$|^(.+)\.factory:([^\.]+)/,
MODULE_CONSTANT = /^(.+)\.constants?:([^\.]+)$/,
MODULE_COMPONENT = /^(.+)\.components?:([^\.]+)$/,
MODULE_DIRECTIVE = /^(.+)\.directives?:([^\.]+)$/,
MODULE_DIRECTIVE_INPUT = /^(.+)\.directives?:input\.([^\.]+)$/,
Expand Down Expand Up @@ -1227,6 +1277,12 @@ function title(doc) {
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_RESOURCE) && doc.type === 'resource') {
return makeTitle(match[2], 'resource', 'module', match[1]);
} else if (match = text.match(MODULE_FACTORY)) {
return makeTitle(match[2], 'factory', 'module', match[1]);
} else if (match = text.match(MODULE_CONSTANT)) {
return makeTitle(match[2], 'constant', 'module', match[1]);
} else if (match = text.match(MODULE_COMPONENT)) {
return makeTitle(match[2], 'component', 'module', match[1]);
} else if (match = text.match(MODULE_DIRECTIVE)) {
Expand Down Expand Up @@ -1516,7 +1572,7 @@ function checkBrokenLinks(docs, apis, options) {
docs.forEach(function(doc) {
byFullId[doc.section + '/' + doc.id] = doc;
if (apis[doc.section]) {
doc.anchors.push('directive', 'service', 'filter', 'function');
doc.anchors.push('directive', 'service', 'filter', 'function', 'factory', 'constant');
}
});

Expand Down
4 changes: 3 additions & 1 deletion src/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ function processJsFile(content, file, section, options) {
text = text.join('\n');
text = text.replace(/^\n/, '');
if (text.match(/@ngdoc/)) {
//console.log(file, startingLine)
//console.log("##########" + file, startingLine);
//console.log("-------" + section);
//console.log(text);
docs.push(new ngdoc.Doc('@section ' + section + '\n' + text, file, startingLine, lineNumber, options).parse());
}
doc = null;
Expand Down
37 changes: 37 additions & 0 deletions src/templates/css/docs.css
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,40 @@ ul.events > li > h3 {
.type-hint-number {
background:rgb(189, 63, 66);
}

.rest-method {
float: right;
margin-top: -0.8em;
margin-right: 0.5em;
}

.rest-method-get {
background-color: #0f6ab4;
}
.rest-method-post {
background-color: #10a54a;
}

.rest-method-put {
background-color: #c5862b;
}

.rest-method-delete {
background-color: #a41e22;
}

.rest-method-options {
background-color: #d7df01;
}

.rest-method-head {
background-color: #642efe;
}

.rest-method-trace {
background-color: #cc2efa;
}

.rest-method-connect {
background-color: #8a2908;
}
21 changes: 21 additions & 0 deletions src/templates/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,34 @@
<a href="{{page.url}}" tabindex="2">{{page.shortName}}</a>
</li>

<li class="nav-header section" ng-show="module.resources.length">
<a class="guide">resource</a>
</li>
<li ng-repeat="page in module.resources 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.length">
<a class="guide">filter</a>
</li>
<li ng-repeat="page in module.filters 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.factories.length">
<a class="guide">factory</a>
</li>
<li ng-repeat="page in module.factories 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.constants.length">
<a class="guide">constant</a>
</li>
<li ng-repeat="page in module.constants 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.services.length">
<a class="guide">service</a>
</li>
Expand Down
21 changes: 21 additions & 0 deletions src/templates/js/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ docsApp.controller.DocsController = function($scope, $location, $window, section
MODULE_MOCK = /^angular\.mock\.([^\.]+)$/,
MODULE_COMPONENT = /^(.+)\.components?:([^\.]+)$/,
MODULE_CONTROLLER = /^(.+)\.controllers?:([^\.]+)$/,
MODULE_RESOURCE = /^(.+)\.resources?:([^\.]+)$/,
MODULE_FACTORY = /^(.+)\.factories:([^\.]+)$|^(.+)\.factory?:([^\.]+)$/,
MODULE_CONSTANT = /^(.+)\.constants?:([^\.]+)$/,
MODULE_DIRECTIVE = /^(.+)\.directives?:([^\.]+)$/,
MODULE_DIRECTIVE_INPUT = /^(.+)\.directives?:input\.([^\.]+)$/,
MODULE_FILTER = /^(.+)\.filters?:([^\.]+)$/,
Expand Down Expand Up @@ -324,6 +327,15 @@ docsApp.controller.DocsController = function($scope, $location, $window, section
} 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_RESOURCE)) {
breadcrumb.push({ name: match[1], url: sectionPath + '/' + match[1] });
breadcrumb.push({ name: match[2] });
} else if (match = partialId.match(MODULE_FACTORY)) {
breadcrumb.push({ name: match[1], url: sectionPath + '/' + match[1] });
breadcrumb.push({ name: match[2] });
} else if (match = partialId.match(MODULE_CONSTANT)) {
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 @@ -414,6 +426,12 @@ docsApp.controller.DocsController = function($scope, $location, $window, section
module(page.moduleName || match[1], section).components.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_RESOURCE) && page.type === 'resource') {
module(page.moduleName || match[1], section).resources.push(page);
} else if (match = id.match(MODULE_FACTORY) && page.type === 'factory' && page.type === 'object') {
module(page.moduleName || match[1], section).factories.push(page);
} else if (match = id.match(MODULE_CONSTANT) && page.type === 'constant' && page.type === 'object') {
module(page.moduleName || match[1], section).constants.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)) {
Expand Down Expand Up @@ -458,7 +476,10 @@ docsApp.controller.DocsController = function($scope, $location, $window, section
globals: [],
components: [],
controllers: [],
resources: [],
directives: [],
factories: [],
constants: [],
services: [],
others: [],
service: function(name) {
Expand Down