aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatias Niemelä2013-08-15 01:09:06 -0400
committerIgor Minar2013-08-23 07:37:51 -0700
commit74ae3edf8614ea8a97580033db0fd145d5260b62 (patch)
treecc709e3ec941f93e66b4c8f0a298d7a78f8bb7b6
parent699f86c535cbc01589d60ea1dc48114a93cd4f19 (diff)
downloadangular.js-74ae3edf8614ea8a97580033db0fd145d5260b62.tar.bz2
chore(ngdocs): fix the version jumper
correct the ordering and make gen-docs prepare the list of versions during the build process
-rw-r--r--docs/component-spec/versionJumpSpec.js101
-rw-r--r--docs/src/ngdoc.js95
-rw-r--r--docs/src/templates/index.html6
-rw-r--r--docs/src/templates/js/docs.js58
4 files changed, 103 insertions, 157 deletions
diff --git a/docs/component-spec/versionJumpSpec.js b/docs/component-spec/versionJumpSpec.js
index 2e74a2ff..4db2d29d 100644
--- a/docs/component-spec/versionJumpSpec.js
+++ b/docs/component-spec/versionJumpSpec.js
@@ -7,21 +7,6 @@ describe('DocsApp', function() {
beforeEach(function() {
module(function($provide) {
- $provide.value('NG_VERSIONS',[
- '1.0.0',
- '1.0.1',
- '1.0.2',
- '1.0.3',
- '1.0.4',
- '1.0.5',
- '1.0.6',
- '1.1.0',
- '1.1.1',
- '1.1.2',
- '1.1.3',
- '1.1.4',
- '2.1.3'
- ]);
$provide.value('$window', window = createMockWindow());
});
inject(function($controller, $rootScope) {
@@ -34,91 +19,11 @@ describe('DocsApp', function() {
});
});
- it('should have the correct version of angular', function() {
- expect(version).toBe($scope.version);
- });
-
- it('should order versions in decending order', function() {
- expect($scope.versions.length).toBeGreaterThan(0);
-
- var one = $scope.versions[0].version;
- var two = $scope.versions[1].version;
-
- expect(one).toBeGreaterThan(two);
- });
-
- it('should list unstable versions at the top of the list', function() {
- expect($scope.versions[0].stable).toBe(false);
- });
-
- it('should list all items below the last stable as stable regardless of version number', function() {
- var limit = $scope.versions.length - 1,
- lastUnstableIndex = 0;
-
- while(lastUnstableIndex <= limit) {
- if($scope.versions[lastUnstableIndex++].stable) break;
- }
-
- for(var i=lastUnstableIndex;i<=limit;i++) {
- expect($scope.versions[i].stable).toBe(true);
- }
- });
-
describe('changing the URL', function() {
- it('should not support the old < 1.0 docs pages', function() {
- window.location = 'old';
-
- $scope.versions.unshift({
- stable : true,
- version : '0.9.10'
- });
- $scope.jumpToDocsVersion('0.9.10');
- expect(window.location).toBe('old');
-
- $scope.versions.unshift({
- stable : true,
- version : '0.10.1'
- });
- $scope.jumpToDocsVersion('0.10.1');
- expect(window.location).toBe('old');
-
- $scope.jumpToDocsVersion('2.1.3');
- expect(window.location).toBe('http://code.angularjs.org/2.1.3/docs');
- });
-
- it('should jump to the older versions of current docs for version >= 1.0.2', function() {
- $scope.jumpToDocsVersion('1.0.1');
- expect(window.location).toBe('http://code.angularjs.org/1.0.1/docs-1.0.1');
-
- $scope.jumpToDocsVersion('1.0.2');
- expect(window.location).toBe('http://code.angularjs.org/1.0.2/docs');
-
- $scope.jumpToDocsVersion('1.1.2');
- expect(window.location).toBe('http://code.angularjs.org/1.1.2/docs');
+ it('should jump to the url provided', function() {
+ $scope.jumpToDocsVersion({ version: '1.0.1', url : 'page123'});
+ expect(window.location).toBe('page123');
});
-
- it('should use the current docs.angularjs.org page when the selected version is the last stable version', function() {
- $scope.versions = [{
- stable : true,
- title : 'test',
- version : '1.1.1'
- }];
-
- $scope.jumpToDocsVersion('1.1.1');
- expect(window.location).toBe('http://docs.angularjs.org');
-
- $scope.versions.unshift({
- stable : true,
- title : 'test2',
- version : '1.2.1'
- });
-
- $scope.jumpToDocsVersion('1.1.1');
- expect(window.location).toBe('http://code.angularjs.org/1.1.1/docs');
- $scope.jumpToDocsVersion('1.2.1');
- expect(window.location).toBe('http://docs.angularjs.org');
- });
-
});
});
diff --git a/docs/src/ngdoc.js b/docs/src/ngdoc.js
index a9f470cc..00aba820 100644
--- a/docs/src/ngdoc.js
+++ b/docs/src/ngdoc.js
@@ -47,8 +47,99 @@ exports.ngVersions = function() {
versions.push(matches[1]);
}
});
- versions.push(exports.ngCurrentVersion().full);
- return versions;
+
+ //match the future version of AngularJS that is set in the package.json file
+ return expandVersions(sortVersionsNatrually(versions), exports.ngCurrentVersion().full);
+
+ function expandVersions(versions, latestVersion) {
+ //copy the array to avoid changing the versions param data
+ //the latest version is not on the git tags list, but
+ //docs.angularjs.org will always point to master as of 1.2
+ versions = versions.concat([latestVersion]);
+
+ var firstUnstable, expanded = [];
+ for(var i=versions.length-1;i>=0;i--) {
+ var version = versions[i],
+ split = version.split('.'),
+ isMaster = version == latestVersion,
+ isStable = split[1] % 2 == 0;
+
+ var title = 'AngularJS - v' + version;
+
+ //anything that is stable before being unstable is a rc1 version
+ //just like with AngularJS 1.2.0rc1 (even though it's apart of the
+ //1.1.5 API
+ if(isMaster || (isStable && !firstUnstable)) {
+ isStable = false;
+ }
+ else {
+ firstUnstable = firstUnstable || version;
+ }
+
+ var docsPath = version < '1.0.2' ? 'docs-' + version : 'docs';
+
+ var url = isMaster ?
+ 'http://docs.angularjs.org' :
+ 'http://code.angularjs.org/' + version + '/' + docsPath;
+
+ expanded.push({
+ version : version,
+ stable : isStable,
+ title : title,
+ group : (isStable ? 'Stable' : 'Unstable'),
+ url : url
+ });
+ };
+
+ return expanded;
+ };
+
+ function sortVersionsNatrually(versions) {
+ var versionMap = {},
+ NON_RC_RELEASE_NUMBER = 999;
+ for(var i = versions.length - 1; i >= 0; i--) {
+ var version = versions[i];
+ var split = version.split(/\.|rc/);
+ var baseVersion = split[0] + '.' + split[1] + '.' + split[2];
+
+ //create a map of RC versions for each version
+ //this way each RC version can be sorted in "natural" order
+ versionMap[baseVersion] = versionMap[baseVersion] || [];
+
+ //NON_RC_RELEASE_NUMBER is used to signal the non-RC version for the release and
+ //it will always appear at the top of the list since the number is so high!
+ versionMap[baseVersion].push(
+ version == baseVersion ? NON_RC_RELEASE_NUMBER : parseInt(version.match(/rc(\d+)/)[1]));
+ };
+
+ //flatten the map so that the RC versions occur in a natural sorted order
+ //and the official non-RC version shows up at the top of the list of sorted
+ //RC versions!
+ var angularVersions = [];
+ sortedKeys(versionMap).forEach(function(key) {
+ var versions = versionMap[key];
+
+ //basic numerical sort
+ versions.sort(function(a,b) {
+ return a - b;
+ });
+
+ versions.forEach(function(v) {
+ angularVersions.push(v == NON_RC_RELEASE_NUMBER ? key : key + 'rc' + v);
+ });
+ });
+
+ return angularVersions;
+ };
+
+ function sortedKeys(obj) {
+ var keys = [];
+ for(var key in obj) {
+ keys.push(key);
+ };
+ keys.sort(true);
+ return keys;
+ };
};
exports.ngCurrentVersion = function() {
diff --git a/docs/src/templates/index.html b/docs/src/templates/index.html
index 0788e415..872ca586 100644
--- a/docs/src/templates/index.html
+++ b/docs/src/templates/index.html
@@ -250,9 +250,9 @@
<div class="span3">
<div class="well">
<div ng-controller="DocsVersionsCtrl">
- <select ng-options="v.version as v.title group by v.group for v in versions"
- ng-model="version"
- ng-change="jumpToDocsVersion(version)"
+ <select ng-options="v as v.title group by v.group for v in docs_versions"
+ ng-model="docs_version"
+ ng-change="jumpToDocsVersion(docs_version)"
class="docs-version-jump">
</select>
</div>
diff --git a/docs/src/templates/js/docs.js b/docs/src/templates/js/docs.js
index 1deea88e..9b38313b 100644
--- a/docs/src/templates/js/docs.js
+++ b/docs/src/templates/js/docs.js
@@ -5,60 +5,10 @@ var docsApp = {
};
docsApp.controller.DocsVersionsCtrl = ['$scope', '$window', 'NG_VERSIONS', 'NG_VERSION', function($scope, $window, NG_VERSIONS, NG_VERSION) {
- $scope.versions = expandVersions(NG_VERSIONS);
- $scope.version = ($scope.version || NG_VERSION).match(/^([\d\.]+\d+\S+)/)[1]; //match only the number
-
- $scope.jumpToDocsVersion = function(value) {
- var isLastStable,
- version,
- versions = $scope.versions;
- for(var i=versions.length-1;i>=0;i--) {
- var v = versions[i];
- if(v.version == value) {
- var next = versions[i - 1];
- isLastStable = v.stable && (!next || next && !next.stable);
- version = v;
- break;
- }
- };
-
- if(version && version.version >= '1.0.0') {
- //the older versions have a different path to the docs within their repo directory
- var docsPath = version.version < '1.0.2' ? 'docs-' + version.version : 'docs';
-
- //the last stable version should redirect to docs.angularjs.org instead of code.angularjs.org
- var url = 'http://' +
- (isLastStable ?
- 'docs.angularjs.org' :
- 'code.angularjs.org/' + version.version + '/' + docsPath);
-
- $window.location = url;
- }
- };
-
- function expandVersions(angularVersions) {
- var unstableVersionStart = 0;
- angularVersions.forEach(function(version) {
- var split = version.split('.');
- unstableVersionStart = split[1] % 2 == 1 ?
- Math.max(unstableVersionStart, parseInt(split[0] + '' + split[1])) :
- unstableVersionStart;
- });
-
- var versions = [];
- for(var i=angularVersions.length-1;i>=0;i--) {
- var version = angularVersions[i];
- var split = version.split('.');
- var stable = parseInt(split[0] + '' + split[1]) < unstableVersionStart;
- versions.push({
- version : version,
- stable : stable,
- title : 'AngularJS - v' + version,
- group : (stable ? 'Stable' : 'Unstable')
- });
- };
-
- return versions;
+ $scope.docs_versions = NG_VERSIONS;
+ $scope.docs_version = NG_VERSIONS[0];
+ $scope.jumpToDocsVersion = function(version) {
+ $window.location = version.url;
};
}];