aboutsummaryrefslogtreecommitdiffstats
path: root/docs/src/ngdoc.js
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 /docs/src/ngdoc.js
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
Diffstat (limited to 'docs/src/ngdoc.js')
-rw-r--r--docs/src/ngdoc.js95
1 files changed, 93 insertions, 2 deletions
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() {