Skip to content

Commit

Permalink
Merge pull request #550 from stephenplusplus/spp--docs-forcing-master
Browse files Browse the repository at this point in the history
docs - follow a version throughout the site
  • Loading branch information
ryanseys committed May 8, 2015
2 parents b71928d + 72144e8 commit bc2b57c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
6 changes: 5 additions & 1 deletion docs/site/components/docs/docs-services.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
angular.module('gcloud.docs')
.factory('getLinks', function(versions, pages) {
.factory('getLinks', function($rootScope, versions, pages) {
'use strict';

// `version` is the current version being browsed.
return function(version) {
if (!version) {
version = $rootScope.ACTIVE_VERSION || $rootScope.latestVersion;
}

var baseUrl = '#/docs/' + version;
var VERSIONS = pages.VERSIONS;

Expand Down
18 changes: 9 additions & 9 deletions docs/site/components/docs/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,6 @@ angular
return a.constructor ? -1: a.name > b.name ? 1 : -1;
}

function getLinks($route, getLinks) {
return getLinks($route.current.params.version);
}

$routeProvider
.when('/docs', {
redirectTo: '/docs/' + versions[0]
Expand All @@ -271,17 +267,17 @@ angular
.when('/docs/:version', {
controller: 'DocsCtrl',
templateUrl: 'site/components/docs/docs.html',
resolve: { methods: getMethods, links: getLinks }
resolve: { methods: getMethods }
})
.when('/docs/:version/:module', {
controller: 'DocsCtrl',
templateUrl: 'site/components/docs/docs.html',
resolve: { methods: getMethods, links: getLinks }
resolve: { methods: getMethods }
})
.when('/docs/:version/:module/:class', {
controller: 'DocsCtrl',
templateUrl: 'site/components/docs/docs.html',
resolve: { methods: getMethods, links: getLinks }
resolve: { methods: getMethods }
});
})

Expand All @@ -290,22 +286,27 @@ angular

$rootScope.$on('$routeChangeStart', function(event, route) {
var url = $location.path();

if (url.indexOf('/docs/') === -1 || (!route.params || !route.params.version)) {
// This isn't a `docs` route or it's not one that expects a version.
// No need to re-direct request.
return;
}

if (versions.indexOf(route.params.version) === -1) {
// No version specified where one was expected.
// Route to same url with latest version prepended.
event.preventDefault();
$route.reload();
$location.path(url.replace('docs/', 'docs/' + versions[0] + '/'));
return;
}

$rootScope.ACTIVE_VERSION = route.params.version;
});
})

.controller('DocsCtrl', function($location, $scope, $routeParams, methods, $http, links, versions) {
.controller('DocsCtrl', function($location, $scope, $routeParams, methods, $http, versions) {
'use strict';

$scope.isActiveUrl = function(url) {
Expand Down Expand Up @@ -340,7 +341,6 @@ angular
$scope.methods = methods;
$scope.version = $routeParams.version;
$scope.versions = versions;
$scope.links = links;
})

.controller('HistoryCtrl', function($scope, versions) {
Expand Down
4 changes: 2 additions & 2 deletions docs/site/components/subpage/subpage-directive.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
angular
.module('gcloud.subpage', ['gcloud.header'])
.directive('subpage', function($location, $parse, getLinks) {
.directive('subpage', function($rootScope, $location, $parse, getLinks) {
'use strict';

return {
transclude: true,
templateUrl: 'site/components/subpage/subpage.html',
link: function($scope, elem, attrs) {
$scope.title = attrs.title;
$scope.links = getLinks('master');
$scope.links = getLinks();
$scope.headerTemplateUrl = attrs.headerTemplateurl;

if (attrs.isActiveUrl) {
Expand Down
2 changes: 1 addition & 1 deletion docs/site/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h2>One-line npm install</h2>
<div class="container">
<ul class="featuring-links">
<li>
<a href="#/docs/{{latestVersion}}" title="gcloud-node docs" class="btn btn-docs">
<a href="#/docs/{{ACTIVE_VERSION || latestVersion}}" title="gcloud-node docs" class="btn btn-docs">
<img src="site/img/icon-lang-nodejs.svg" alt="Node.js icon" />
Read the Docs
</a>
Expand Down
8 changes: 4 additions & 4 deletions docs/site/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ angular
controller: 'HomeCtrl'
});
})
.controller('HomeCtrl', function($scope, versions) {
.controller('HomeCtrl', function() {
'use strict';

$scope.latestVersion = versions[0];
})
.run(function($rootScope, $location) {
.run(function($rootScope, $location, versions) {
'use strict';

$rootScope.latestVersion = versions[0];

$rootScope.$on('$routeChangeStart', function(event) {
var hash = $location.hash();
if (hash) {
Expand Down

0 comments on commit bc2b57c

Please sign in to comment.