diff --git a/docs/component-spec/versionJumpSpec.js b/docs/component-spec/versionJumpSpec.js index 2e74a2ff7628..4db2d29d6e0a 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 a9f470cce8c0..00aba82099e4 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 0788e4153626..872ca58650d8 100644 --- a/docs/src/templates/index.html +++ b/docs/src/templates/index.html @@ -250,9 +250,9 @@