From 74ae3edf8614ea8a97580033db0fd145d5260b62 Mon Sep 17 00:00:00 2001 From: Matias Niemelä Date: Thu, 15 Aug 2013 01:09:06 -0400 Subject: chore(ngdocs): fix the version jumper correct the ordering and make gen-docs prepare the list of versions during the build process --- docs/src/ngdoc.js | 95 ++++++++++++++++++++++++++++++++++++++++++- docs/src/templates/index.html | 6 +-- docs/src/templates/js/docs.js | 58 ++------------------------ 3 files changed, 100 insertions(+), 59 deletions(-) (limited to 'docs/src') 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 @@
-
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; }; }]; -- cgit v1.2.3