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

Commit

Permalink
feat(ngDocs): add links to source for API
Browse files Browse the repository at this point in the history
 - add tests
 - the link points to the gruntUtil.getVersion().number tree on github
  • Loading branch information
revolunet authored and btford committed Jul 11, 2013
1 parent 8bd6619 commit 52d6a59
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
29 changes: 29 additions & 0 deletions docs/spec/sourceLinkSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var ngdoc = require('../src/ngdoc.js');
var gruntUtil = require('../../lib/grunt/utils.js');

describe('Docs Links', function() {

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

beforeEach(function() {
doc = new ngdoc.Doc("@ngdoc function\n@name ng.filter:a\n@function");
doc.section = 'api';
doc.file = 'test.js';
doc.line = 42;
doc.parse();
});

it('should have an "improve this doc" button', function() {
expect(doc.html()).
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>');
});

it('should have an "view source" button', function() {
expect(doc.html()).
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>');
});

});

});
13 changes: 11 additions & 2 deletions docs/src/ngdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,16 @@ Doc.prototype = {
dom.h(title(this.name), function() {

notice('deprecated', 'Deprecated API', self.deprecated);
dom.tag('a', {href: 'http://github.com/angular/angular.js/edit/master/' + self.file, class: 'improve-docs btn btn-primary'}, 'Improve this doc');
dom.tag('a', {href: 'http://github.com/angular/angular.js/edit/master/' + self.file, class: 'improve-docs btn btn-primary'}, function(dom) {
dom.tag('i', {class:'icon-edit'}, ' ');
dom.text(' Improve this doc');
});
if (self.section === 'api') {
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) {
dom.tag('i', {class:'icon-zoom-in'}, ' ');
dom.text(' View source');
});
}
if (self.ngdoc != 'overview') {
dom.h('Description', self.description, dom.html);
}
Expand All @@ -401,7 +410,7 @@ Doc.prototype = {
//////////////////////////

function notice(name, legend, msg){
if (self[name] == undefined) return;
if (self[name] === undefined) return;
dom.tag('fieldset', {'class':name}, function(dom){
dom.tag('legend', legend);
dom.text(msg);
Expand Down
3 changes: 2 additions & 1 deletion docs/src/templates/css/docs.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@
/* Content */
/* =============================== */

.improve-docs {
.improve-docs, .view-source {
float: right;
margin: 0 5px;
}

.hint {
Expand Down

0 comments on commit 52d6a59

Please sign in to comment.