Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions docs/site/components/docs/docs-directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,43 @@ angular.module('gcloud.docs')
};
})

.directive('docsCodeLink', function($compile) {
.directive('docsCodeLink', function() {
'use strict';

var GITHUB_BASE = 'https://github.com/GoogleCloudPlatform/gcloud-node/blob/';
var GITHUB_BASE = 'https://github.com/GoogleCloudPlatform/gcloud-node/blob';

function getFilenameFromConstructor(constructor) {
switch (constructor) {
case 'DatastoreRequest':
return 'request.js';
default:
return 'index.js';
}
}

return {
template: '<a href="' + GITHUB_BASE + '{{version}}/lib/' +
'{{module ? module + \'/\' : \'\'}}{{class}}.js' +
'{{method.lineNumLink}}">' +
'(code on GitHub)' +
'</a>'
template: '<a href="{{link}}">(code on GitHub)</a>',

link: function($scope) {
var method = $scope.method;
var module = $scope.module;
var version = $scope.version;

var lineNumLink = method.lineNumLink;
var fileName = $scope.class + '.js';

if (method.data.ctx.hasOwnProperty('constructor')) {
fileName = getFilenameFromConstructor(method.data.ctx.constructor);
}

fileName = fileName.toLowerCase();

$scope.link =
GITHUB_BASE +
'/' + version +
'/lib' +
(module ? '/' + module : '') +
'/' + fileName + lineNumLink;
}
};
});