Skip to content

Commit 5838e10

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

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
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
});

0 commit comments

Comments
 (0)