Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5b05c0d

Browse files
committed
@require in ngdoc now takes reason for dependency
1 parent d19c0ac commit 5b05c0d

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

docs/spec/ngdocSpec.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,16 @@ describe('ngdoc', function(){
229229

230230
describe('@requires', function() {
231231
it('should parse more @requires tag into array', function() {
232-
var doc = new Doc('@requires $service\n@requires $another');
232+
var doc = new Doc('@requires $service for \n`A`\n@requires $another for `B`');
233+
doc.ngdoc = 'service';
233234
doc.parse();
234-
expect(doc.requires).toEqual(['$service', '$another']);
235+
expect(doc.requires).toEqual([
236+
{name:'$service', text:'<p>for \n<code>A</code></p>'},
237+
{name:'$another', text:'<p>for <code>B</code></p>'}]);
238+
expect(doc.html()).toContain('<a href="#!angular.service.$service">$service</a>');
239+
expect(doc.html()).toContain('<a href="#!angular.service.$another">$another</a>');
240+
expect(doc.html()).toContain('<p>for \n<code>A</code></p>');
241+
expect(doc.html()).toContain('<p>for <code>B</code></p>');
235242
});
236243
});
237244

docs/src/ngdoc.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ Doc.prototype = {
157157
description: self.markdown(text.replace(match[0], match[2]))
158158
};
159159
} else if(atName == 'requires') {
160-
self.requires.push(text);
160+
var match = text.match(/^([^\s]*)\s*([\S\s]*)/);
161+
self.requires.push({
162+
name: match[1],
163+
text: self.markdown(match[2])
164+
});
161165
} else if(atName == 'property') {
162166
var match = text.match(/^{(\S+)}\s+(\S+)(\s+(.*))?/);
163167
if (!match) {
@@ -185,6 +189,16 @@ Doc.prototype = {
185189
'This page is currently being revised. It might be incomplete or contain inaccuracies.');
186190
notice('deprecated', 'Deprecated API', self.deprecated);
187191

192+
if (self.ngdoc != 'overview') {
193+
dom.h('Description', self.description, dom.html);
194+
}
195+
dom.h('Dependencies', self.requires, function(require){
196+
dom.tag('code', function(){
197+
dom.tag('a', {href:"#!angular.service." + require.name}, require.name);
198+
});
199+
dom.html(require.text);
200+
});
201+
188202
(self['html_usage_' + self.ngdoc] || function(){
189203
throw new Error("Don't know how to format @ngdoc: " + self.ngdoc);
190204
}).call(self, dom);
@@ -251,8 +265,6 @@ Doc.prototype = {
251265

252266
html_usage_function: function(dom){
253267
var self = this;
254-
dom.h('Description', self.description, dom.html);
255-
dom.h('Dependencies', self.requires);
256268
dom.h('Usage', function(){
257269
dom.code(function(){
258270
dom.text(self.name);
@@ -269,8 +281,6 @@ Doc.prototype = {
269281

270282
html_usage_directive: function(dom){
271283
var self = this;
272-
dom.h('Description', self.description, dom.html);
273-
dom.h('Dependencies', self.requires);
274284
dom.h('Usage', function(){
275285
dom.tag('pre', {'class':"brush: js; html-script: true;"}, function(){
276286
dom.text('<' + self.element + ' ');
@@ -287,8 +297,6 @@ Doc.prototype = {
287297

288298
html_usage_filter: function(dom){
289299
var self = this;
290-
dom.h('Description', self.description, dom.html);
291-
dom.h('Dependencies', self.requires);
292300
dom.h('Usage', function(){
293301
dom.h('In HTML Template Binding', function(){
294302
dom.tag('code', function(){
@@ -319,8 +327,6 @@ Doc.prototype = {
319327

320328
html_usage_formatter: function(dom){
321329
var self = this;
322-
dom.h('Description', self.description, dom.html);
323-
dom.h('Dependencies', self.requires);
324330
dom.h('Usage', function(){
325331
dom.h('In HTML Template Binding', function(){
326332
dom.code(function(){
@@ -359,8 +365,6 @@ Doc.prototype = {
359365

360366
html_usage_validator: function(dom){
361367
var self = this;
362-
dom.h('Description', self.description, dom.html);
363-
dom.h('Dependencies', self.requires);
364368
dom.h('Usage', function(){
365369
dom.h('In HTML Template Binding', function(){
366370
dom.code(function(){
@@ -389,8 +393,6 @@ Doc.prototype = {
389393

390394
html_usage_widget: function(dom){
391395
var self = this;
392-
dom.h('Description', self.description, dom.html);
393-
dom.h('Dependencies', self.requires);
394396
dom.h('Usage', function(){
395397
dom.h('In HTML Template Binding', function(){
396398
dom.code(function(){
@@ -435,8 +437,6 @@ Doc.prototype = {
435437

436438
html_usage_service: function(dom){
437439
var self = this;
438-
dom.h('Description', this.description, dom.html);
439-
dom.h('Dependencies', this.requires);
440440

441441
if (this.param.length) {
442442
dom.h('Usage', function(){

0 commit comments

Comments
 (0)