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

Commit 52d6a59

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 8bd6619 commit 52d6a59

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
@@ -378,7 +378,16 @@ Doc.prototype = {
378378
dom.h(title(this.name), function() {
379379

380380
notice('deprecated', 'Deprecated API', self.deprecated);
381-
dom.tag('a', {href: 'http://github.com/angular/angular.js/edit/master/' + self.file, class: 'improve-docs btn btn-primary'}, 'Improve this doc');
381+
dom.tag('a', {href: 'http://github.com/angular/angular.js/edit/master/' + self.file, class: 'improve-docs btn btn-primary'}, function(dom) {
382+
dom.tag('i', {class:'icon-edit'}, ' ');
383+
dom.text(' Improve this doc');
384+
});
385+
if (self.section === 'api') {
386+
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) {
387+
dom.tag('i', {class:'icon-zoom-in'}, ' ');
388+
dom.text(' View source');
389+
});
390+
}
382391
if (self.ngdoc != 'overview') {
383392
dom.h('Description', self.description, dom.html);
384393
}
@@ -401,7 +410,7 @@ Doc.prototype = {
401410
//////////////////////////
402411

403412
function notice(name, legend, msg){
404-
if (self[name] == undefined) return;
413+
if (self[name] === undefined) return;
405414
dom.tag('fieldset', {'class':name}, function(dom){
406415
dom.tag('legend', legend);
407416
dom.text(msg);

docs/src/templates/css/docs.css

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@
9595
/* Content */
9696
/* =============================== */
9797

98-
.improve-docs {
98+
.improve-docs, .view-source {
9999
float: right;
100+
margin: 0 5px;
100101
}
101102

102103
.hint {

0 commit comments

Comments
 (0)