Skip to content

Commit 72144e8

Browse files
docs - follow a version throughout the site
fixes googleapis#548
1 parent b71928d commit 72144e8

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

docs/site/components/docs/docs-services.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
angular.module('gcloud.docs')
2-
.factory('getLinks', function(versions, pages) {
2+
.factory('getLinks', function($rootScope, versions, pages) {
33
'use strict';
44

55
// `version` is the current version being browsed.
66
return function(version) {
7+
if (!version) {
8+
version = $rootScope.ACTIVE_VERSION || $rootScope.latestVersion;
9+
}
10+
711
var baseUrl = '#/docs/' + version;
812
var VERSIONS = pages.VERSIONS;
913

docs/site/components/docs/docs.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,6 @@ angular
256256
return a.constructor ? -1: a.name > b.name ? 1 : -1;
257257
}
258258

259-
function getLinks($route, getLinks) {
260-
return getLinks($route.current.params.version);
261-
}
262-
263259
$routeProvider
264260
.when('/docs', {
265261
redirectTo: '/docs/' + versions[0]
@@ -271,17 +267,17 @@ angular
271267
.when('/docs/:version', {
272268
controller: 'DocsCtrl',
273269
templateUrl: 'site/components/docs/docs.html',
274-
resolve: { methods: getMethods, links: getLinks }
270+
resolve: { methods: getMethods }
275271
})
276272
.when('/docs/:version/:module', {
277273
controller: 'DocsCtrl',
278274
templateUrl: 'site/components/docs/docs.html',
279-
resolve: { methods: getMethods, links: getLinks }
275+
resolve: { methods: getMethods }
280276
})
281277
.when('/docs/:version/:module/:class', {
282278
controller: 'DocsCtrl',
283279
templateUrl: 'site/components/docs/docs.html',
284-
resolve: { methods: getMethods, links: getLinks }
280+
resolve: { methods: getMethods }
285281
});
286282
})
287283

@@ -290,22 +286,27 @@ angular
290286

291287
$rootScope.$on('$routeChangeStart', function(event, route) {
292288
var url = $location.path();
289+
293290
if (url.indexOf('/docs/') === -1 || (!route.params || !route.params.version)) {
294291
// This isn't a `docs` route or it's not one that expects a version.
295292
// No need to re-direct request.
296293
return;
297294
}
295+
298296
if (versions.indexOf(route.params.version) === -1) {
299297
// No version specified where one was expected.
300298
// Route to same url with latest version prepended.
301299
event.preventDefault();
302300
$route.reload();
303301
$location.path(url.replace('docs/', 'docs/' + versions[0] + '/'));
302+
return;
304303
}
304+
305+
$rootScope.ACTIVE_VERSION = route.params.version;
305306
});
306307
})
307308

308-
.controller('DocsCtrl', function($location, $scope, $routeParams, methods, $http, links, versions) {
309+
.controller('DocsCtrl', function($location, $scope, $routeParams, methods, $http, versions) {
309310
'use strict';
310311

311312
$scope.isActiveUrl = function(url) {
@@ -340,7 +341,6 @@ angular
340341
$scope.methods = methods;
341342
$scope.version = $routeParams.version;
342343
$scope.versions = versions;
343-
$scope.links = links;
344344
})
345345

346346
.controller('HistoryCtrl', function($scope, versions) {

docs/site/components/subpage/subpage-directive.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
angular
22
.module('gcloud.subpage', ['gcloud.header'])
3-
.directive('subpage', function($location, $parse, getLinks) {
3+
.directive('subpage', function($rootScope, $location, $parse, getLinks) {
44
'use strict';
55

66
return {
77
transclude: true,
88
templateUrl: 'site/components/subpage/subpage.html',
99
link: function($scope, elem, attrs) {
1010
$scope.title = attrs.title;
11-
$scope.links = getLinks('master');
11+
$scope.links = getLinks();
1212
$scope.headerTemplateUrl = attrs.headerTemplateurl;
1313

1414
if (attrs.isActiveUrl) {

docs/site/home.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ <h2>One-line npm install</h2>
2424
<div class="container">
2525
<ul class="featuring-links">
2626
<li>
27-
<a href="#/docs/{{latestVersion}}" title="gcloud-node docs" class="btn btn-docs">
27+
<a href="#/docs/{{ACTIVE_VERSION || latestVersion}}" title="gcloud-node docs" class="btn btn-docs">
2828
<img src="site/img/icon-lang-nodejs.svg" alt="Node.js icon" />
2929
Read the Docs
3030
</a>

docs/site/home.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ angular
2020
controller: 'HomeCtrl'
2121
});
2222
})
23-
.controller('HomeCtrl', function($scope, versions) {
23+
.controller('HomeCtrl', function() {
2424
'use strict';
25-
26-
$scope.latestVersion = versions[0];
2725
})
28-
.run(function($rootScope, $location) {
26+
.run(function($rootScope, $location, versions) {
2927
'use strict';
3028

29+
$rootScope.latestVersion = versions[0];
30+
3131
$rootScope.$on('$routeChangeStart', function(event) {
3232
var hash = $location.hash();
3333
if (hash) {

0 commit comments

Comments
 (0)