Skip to content

Commit 56bc620

Browse files
docs: fix broken code links - fixes googleapis#547
1 parent 06aade6 commit 56bc620

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

docs/site/components/docs/docs-directives.js

+34-7
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,43 @@ angular.module('gcloud.docs')
1111
};
1212
})
1313

14-
.directive('docsCodeLink', function($compile) {
14+
.directive('docsCodeLink', function() {
1515
'use strict';
1616

17-
var GITHUB_BASE = 'https://github.com/GoogleCloudPlatform/gcloud-node/blob/';
17+
var GITHUB_BASE = 'https://github.com/GoogleCloudPlatform/gcloud-node/blob';
18+
19+
function getFilenameFromConstructor(constructor) {
20+
switch (constructor) {
21+
case 'DatastoreRequest':
22+
return 'request.js';
23+
default:
24+
return 'index.js';
25+
}
26+
}
1827

1928
return {
20-
template: '<a href="' + GITHUB_BASE + '{{version}}/lib/' +
21-
'{{module ? module + \'/\' : \'\'}}{{class}}.js' +
22-
'{{method.lineNumLink}}">' +
23-
'(code on GitHub)' +
24-
'</a>'
29+
template: '<a href="{{link}}">(code on GitHub)</a>',
30+
31+
link: function($scope) {
32+
var method = $scope.method;
33+
var module = $scope.module;
34+
var version = $scope.version;
35+
36+
var lineNumLink = method.lineNumLink;
37+
var fileName = $scope.class + '.js';
38+
39+
if (method.data.ctx.hasOwnProperty('constructor')) {
40+
fileName = getFilenameFromConstructor(method.data.ctx.constructor);
41+
}
42+
43+
fileName = fileName.toLowerCase();
44+
45+
$scope.link =
46+
GITHUB_BASE +
47+
'/' + version +
48+
'/lib' +
49+
(module ? '/' + module : '') +
50+
'/' + fileName + lineNumLink;
51+
}
2552
};
2653
});

docs/site/components/docs/docs.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ <h3 class="sub-heading">
7474
ng-hide="singleMethod && method.name !== singleMethod">
7575
<h2 ng-if="method.name[0].toUpperCase() === method.name[0]">
7676
{{method.name}}
77-
<span class="view-code-link" docs-code-link></span>
77+
<span docs-code-link class="view-code-link"></span>
7878
</h2>
7979
<h3
8080
class="method-heading"
@@ -85,7 +85,7 @@ <h2 ng-if="method.name[0].toUpperCase() === method.name[0]">
8585
<span>#</span>
8686
{{method.name}}
8787
</a>
88-
<span class="view-code-link" docs-code-link></span>
88+
<span docs-code-link class="view-code-link"></span>
8989
</h3>
9090
<p ng-if="method.description" ng-bind-html="method.description"></p>
9191
<div ng-show="method.name[0].toUpperCase() === method.name[0]"

0 commit comments

Comments
 (0)