Skip to content

Commit

Permalink
Merge pull request #584 from stephenplusplus/spp--docs-link-to-code-bug
Browse files Browse the repository at this point in the history
docs: fix broken code links - fixes #547
  • Loading branch information
ryanseys committed May 12, 2015
2 parents 6da3e50 + 5838e10 commit c1f135f
Showing 1 changed file with 34 additions and 7 deletions.
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;
}
};
});

0 comments on commit c1f135f

Please sign in to comment.