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

Commit 61fb586

Browse files
revolunetbtford
authored andcommitted
feat(ngDocs): add links to source for API
- add tests - the link points to the gruntUtil.getVersion().number tree on github
1 parent a4ec297 commit 61fb586

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

docs/spec/sourceLinkSpec.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var ngdoc = require('../src/ngdoc.js');
2+
var gruntUtil = require('../../lib/grunt/utils.js');
3+
4+
describe('Docs Links', function() {
5+
6+
describe('links', function() {
7+
var doc;
8+
9+
beforeEach(function() {
10+
doc = new ngdoc.Doc("@ngdoc function\n@name ng.filter:a\n@function");
11+
doc.section = 'api';
12+
doc.file = 'test.js';
13+
doc.line = 42;
14+
doc.parse();
15+
});
16+
17+
it('should have an "improve this doc" button', function() {
18+
expect(doc.html()).
19+
toContain('<a href="http://github.com/angular/angular.js/edit/master/test.js" class="improve-docs btn btn-primary"><i class="icon-edit"> </i> Improve this doc</a>');
20+
});
21+
22+
it('should have an "view source" button', function() {
23+
expect(doc.html()).
24+
toContain('<a href="http://github.com/angular/angular.js/tree/v' + gruntUtil.getVersion().number + '/test.js#L42" class="view-source btn btn-action"><i class="icon-zoom-in"> </i> View source</a>');
25+
});
26+
27+
});
28+
29+
});

docs/src/ngdoc.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,16 @@ Doc.prototype = {
274274
dom.h(title(this.name), function() {
275275

276276
notice('deprecated', 'Deprecated API', self.deprecated);
277-
dom.tag('a', {href: 'http://github.com/angular/angular.js/edit/master/' + self.file, class: 'improve-docs btn btn-primary'}, 'Improve this doc');
277+
dom.tag('a', {href: 'http://github.com/angular/angular.js/edit/master/' + self.file, class: 'improve-docs btn btn-primary'}, function(dom) {
278+
dom.tag('i', {class:'icon-edit'}, ' ');
279+
dom.text(' Improve this doc');
280+
});
281+
if (self.section === 'api') {
282+
dom.tag('a', {href: 'http://github.com/angular/angular.js/tree/v' + gruntUtil.getVersion().number + '/' + self.file + '#L' + self.line, class: 'view-source btn btn-action'}, function(dom) {
283+
dom.tag('i', {class:'icon-zoom-in'}, ' ');
284+
dom.text(' View source');
285+
});
286+
}
278287
if (self.ngdoc != 'overview') {
279288
dom.h('Description', self.description, dom.html);
280289
}
@@ -297,7 +306,7 @@ Doc.prototype = {
297306
//////////////////////////
298307

299308
function notice(name, legend, msg){
300-
if (self[name] == undefined) return;
309+
if (self[name] === undefined) return;
301310
dom.tag('fieldset', {'class':name}, function(dom){
302311
dom.tag('legend', legend);
303312
dom.text(msg);

docs/src/templates/css/docs.css

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ img.AngularJS-small {
8686
/* Content */
8787
/* =============================== */
8888

89-
.improve-docs {
89+
.improve-docs, .view-source {
9090
float: right;
91+
margin: 0 5px;
9192
}
9293

9394
.hint {

0 commit comments

Comments
 (0)