Skip to content

Commit

Permalink
Merge pull request #254 from stephenplusplus/spp--docs-restructure
Browse files Browse the repository at this point in the history
docs: re-structure versioning.
  • Loading branch information
silvolu committed Oct 13, 2014
2 parents daf247c + 9917742 commit 714ff88
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 16 deletions.
35 changes: 22 additions & 13 deletions docs/components/docs/docs-services.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
angular.module('gcloud.docs')
.factory('getLinks', function(pages) {
.factory('getLinks', function(versions, pages) {
'use strict';

// `version` is the current version being browsed.
return function(version) {
var baseUrl = '#/docs/' + version;
var VERSIONS = pages.VERSIONS;
var versions;
var match;
if (!version || version === 'master') {
versions = Object.keys(VERSIONS);
match = versions[versions.length - 1];
} else {
match = Object.keys(VERSIONS).filter(semver.satisfies.bind(null, version))[0];

if (version === 'master') {
// Use the most recent release.
version = versions[0];
}
return VERSIONS[match]
.map(function(module) {
if (pages[module]._url) {
pages[module].url = pages[module]._url.replace('{baseUrl}', baseUrl);

// Use semver matching to put all matching modules together.
return Object.keys(VERSIONS)
.reduce(function(acc, potentialVersion) {
if (semver.satisfies(version, potentialVersion)) {
acc = acc.concat(VERSIONS[potentialVersion].map(function(module) {
if (pages[module]._url) {
pages[module].url = pages[module]._url.replace('{baseUrl}', baseUrl);
}
return pages[module];
}));
}
return pages[module];
return acc;
}, [])
.sort(function(moduleA, moduleB) {
// A title matching `gcloud` will come first in the list.
return moduleA.title === 'gcloud' ? -1 : moduleA.title > moduleB.title;
});
};
});
33 changes: 30 additions & 3 deletions docs/components/docs/docs-values.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
angular.module('gcloud.docs')
.value('pages', {

//---------------------------------------------
// Link schema:
//---------------------------------------------
// key: {
// title: 'Display Name for Link',
// _url: '{baseUrl}/module-name',
//
// pages: [
// title: 'Display Name for Sub-Page Link',
// url: '/path-relevant-to-parent-url'
// ]
// }
//---------------------------------------------

gcloud: {
title: 'gcloud',
_url: '{baseUrl}'
Expand Down Expand Up @@ -62,8 +77,20 @@ angular.module('gcloud.docs')
VERSIONS: {
// Give a version with/without a comparator, anything semver:
// https://github.com/npm/node-semver#versions
// List should be in ascending order.
'<=0.7.1': ['gcloud', 'datastore', 'storage'],
'>0.7.1': ['gcloud', 'datastoreWithTransaction', 'pubsub', 'storage']
//
// Multiple keys may be used to match a version.
//
// Example:
// A user is browsing the docs for 0.7.0. If the list below contains the
// keys: "*", ">0.4.0", and "0.7.0", all of the contents will be joined.
//
// Notes on ordering:
// These are sorted alphabetically by `module`.title.
//
// To keep the documentation for the main module, `gcloud`, on top of the
// link list, **make sure the title is `gcloud`**
'*': ['gcloud', 'storage'],
'<0.8.0': ['datastore'],
'>=0.8.0': ['datastoreWithTransaction', 'pubsub']
}
});

0 comments on commit 714ff88

Please sign in to comment.