[PATCH 2 of 3 hg-website] download: use sources.js instead of jinja static templates

David Champion dgc at uchicago.edu
Sun Nov 21 12:46:09 CST 2010


# HG changeset patch
# User David Champion <dgc at uchicago.edu>
# Date 1290304387 21600
# Node ID 1c5884f6563b9db3fa3267c94535227f6c80e857
# Parent  7cb309f3e33aa9e2c222482b7d944d91107fcff1
download: use sources.js instead of jinja static templates

See http://mercurial.selenic.com/wiki/BinaryReleasePlan

1. [hg-website] update the main page (templates/base.html and
static/js/download.js) to use sources.js as a dynamic binary release
information source instead of using a jinja template maintained as part
of the web site.  templates/data no longer required; removed.

2. [hg-website-content] update the /downloads page use the sources.js
information also.

This changes some of the detection and package naming, naturally, but
that likely must be addressed in latest.dat files or in the protocol for
creating sources.js.

diff -r 7cb309f3e33a -r 1c5884f6563b .hgsubstate
--- a/.hgsubstate	Sat Nov 20 19:56:37 2010 -0600
+++ b/.hgsubstate	Sat Nov 20 19:53:07 2010 -0600
@@ -1,2 +1,2 @@
-571b7970a0ba32b912ec07acad337b9d9669656b content
+6e7e8b5aa2c317fb1d185265b87d64f054e6c9fa content
 62caa522bc653951b323f79e9e8fd557a1dd2709 rendered
diff -r 7cb309f3e33a -r 1c5884f6563b static/js/download.js
--- a/static/js/download.js	Sat Nov 20 19:56:37 2010 -0600
+++ b/static/js/download.js	Sat Nov 20 19:53:07 2010 -0600
@@ -1,40 +1,69 @@
-function Download() {
-    this.downloads = {};
+function Download (source) {
+	this.version = source[0];
+	this.regex = source[1];
+	this.url = source[2];
+	this.desc = source[3];
 }
 
 Download.prototype = {
+	matches: function (ua) {
+		if (ua.match(this.regex))
+			return true;
+		return false;
+	},
 
-    parse_os: function() {
-        var OSName="Source code";
-        if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
-        if (navigator.appVersion.indexOf("Mac")!=-1) {
-            if (navigator.userAgent.indexOf("10.6")!=-1 || /* firefox */
-                navigator.userAgent.indexOf("10_6") !=-1) { /* chrome */
-                OSName="Mac OS X 10.6";
-            } else {
-                OSName="Mac OS X 10.5";
-            }
-        }
-        if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
-        if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
+	download: function () {
+		//alert(this.url);
+		document.location.href = this.url;
+		return false;
+	},
 
-        return OSName;
-    },
+	attr: function (key) {
+		return this[key];
+	},
 
-    os_detection: function() {
-        document.write(this.parse_os());
-    },
+	write: function (key) {
+		document.write(this[key]);
+	}
+}
 
-    os_link: function() {
-        var os = this.parse_os();
-        if (this.downloads[os]) {
-            document.location.href = this.downloads[os];
-            return false;
-        }
-        return true;
-    },
 
-    register_download:function(type, url) {
-        this.downloads[type] = url;
-    }
-}
+var Downloader = {
+	downloads: [],
+
+	init: function (sources) {
+		for (i in sources) {
+			var source = new Download(sources[i]);
+			this.downloads.push(source);
+		}
+	},
+
+	select: function () {
+		var ua = navigator.userAgent;
+		for (i in this.downloads) {
+			if (this.downloads[i].matches(ua)) {
+				return this.downloads[i];
+			}
+		}
+		return null;
+	},
+
+	listall: function () {
+		// copy the download list
+		var downloads = this.downloads.slice(0);
+		// alpha-sort it by description (case-folded)
+		downloads.sort(function (a, b) {
+			a = a.desc.toLowerCase();
+			b = b.desc.toLowerCase();
+			return (b < a) - (a < b);
+		});
+
+		for (i in downloads) {
+			var dl = downloads[i];
+			document.write('<tr>\n<td>' + dl.desc + '</td>' +
+			               '<td></td>' +
+			               '<td><a href="' + dl.url + '">download</a></td>' +
+			               '</tr>');
+		}
+	}
+};
diff -r 7cb309f3e33a -r 1c5884f6563b templates/base.html
--- a/templates/base.html	Sat Nov 20 19:56:37 2010 -0600
+++ b/templates/base.html	Sat Nov 20 19:53:07 2010 -0600
@@ -1,5 +1,3 @@
-{% from 'data' import downloads %}
-
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
 <html>
@@ -8,16 +6,12 @@
         <link href="/css/styles.css" type="text/css" rel="stylesheet">
         <script type="text/javascript" src="/js/typeface.js"></script>
         <script type="text/javascript" src="/js/optimer_regular.typeface.js"></script>
+        <script type="text/javascript" src="/js/common.js"></script>
+        <script type="text/javascript" src="/sources.js"></script>
         <script type="text/javascript" src="/js/download.js"></script>
-        <script type="text/javascript" src="/js/common.js"></script>
-        <script language="javascript" type="text/javascript">
-        {% set download = downloads[downloads['current']] %}
-         var dl = new Download();
-         dl.register_download('Windows', "{{ download['Windows']}}");
-         dl.register_download('Mac OS X 10.6', "{{ download['Mac OS X 10.6']}}");
-         dl.register_download('Mac OS X 10.5', "{{ download['Mac OS X 10.5']}}");
-         dl.register_download('UNIX', "{{ download['Source code']}}");
-         dl.register_download('Linux', "{{ download['Source code']}}");
+        <script language="javascript">
+          Downloader.init(sources);
+          var dl = Downloader.select();
         </script>
         <link rel="shortcut icon" type="image/x-icon" href="/images/favicon.ico">
 
@@ -58,10 +52,10 @@
                     </div>
                     <div class="col">
                         {% block sidebar %}
-                        <a class="download typeface-js" href="/downloads" onClick="javascript:return dl.os_link();">
+                        <a class="download typeface-js" href="/downloads" onClick="return dl.download();">
                                     <strong>Download now</strong>
-                                    Mercurial <em>{{ downloads['current'] }}</em>
-                                    <span><script language="javascript">dl.os_detection();</script></span>
+                                    Mercurial <em><script language="Javascript">dl.write('version');</script></em>
+                                    <span><script language="javascript">dl.write('desc');</script></span>
                         </a>
                         <dl>
                             <dt>Another OS?<br><em>Get Mercurial for:</em></dt>
diff -r 7cb309f3e33a -r 1c5884f6563b templates/data
--- a/templates/data	Sat Nov 20 19:56:37 2010 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,110 +0,0 @@
-{% set downloads = {
-    'current': '1.7.1',
-    '1.7.1' : {
-        'TortoiseHg for Windows 64bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.1.6.1-hg-1.7.1-x64.msi',
-        'TortoiseHg for Windows 32bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.1.6.1-hg-1.7.1-x86.msi',
-        'Windows': 'http://bitbucket.org/tortoisehg/thg-winbuild/downloads/mercurial-1.7.1.msi',
-        'Mac OS X 10.6': 'http://mercurial.berkwood.com/binaries/Mercurial-1.7.1-py2.6-macosx10.6.zip',
-        'Mac OS X 10.5': 'http://mercurial.berkwood.com/binaries/Mercurial-1.7.1-py2.5-macosx10.5.zip',
-        'Source code': 'http://mercurial.selenic.com/release/mercurial-1.7.1.tar.gz'},
-    '1.7' : {
-        'TortoiseHG for Windows 64bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.1.5-hg-1.7-x64.msi',
-        'TortoiseHG for Windows 32bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.1.5-hg-1.7-x86.msi',
-        'Windows': 'http://bitbucket.org/tortoisehg/thg-winbuild/downloads/mercurial-1.7.0.msi',
-        'Mac OS X 10.6': 'http://mercurial.berkwood.com/binaries/Mercurial-1.7-py2.6-macosx10.6.zip',
-        'Mac OS X 10.5': 'http://mercurial.berkwood.com/binaries/Mercurial-1.7-py2.5-macosx10.5.zip',
-        'Source code': 'http://mercurial.selenic.com/release/mercurial-1.7.tar.gz'},
-    '1.6.4' : {
-        'TortoiseHG for Windows 64bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.1.4-hg-1.6.4-x64.msi',
-        'TortoiseHG for Windows 32bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.1.4-hg-1.6.4-x86.msi',
-        'Windows': 'http://bitbucket.org/tortoisehg/thg-winbuild/downloads/mercurial-1.6.4.msi',
-        'Mac OS X 10.6': 'http://mercurial.berkwood.com/binaries/Mercurial-1.6.4-py2.6-macosx10.6.zip',
-        'Mac OS X 10.5': 'http://mercurial.berkwood.com/binaries/Mercurial-1.6.4-py2.5-macosx10.5.zip',
-        'Source code': 'http://mercurial.selenic.com/release/mercurial-1.6.4.tar.gz'},
-    '1.6.3' : {
-        'TortoiseHG for Windows 64bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.1.3-hg-1.6.3-x64.msi',
-        'TortoiseHG for Windows 32bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.1.3-hg-1.6.3-x86.msi',
-        'Windows': 'http://bitbucket.org/tortoisehg/thg-winbuild/downloads/mercurial-1.6.3.msi',
-        'Mac OS X 10.6': 'http://mercurial.berkwood.com/binaries/Mercurial-1.6.3-py2.6-macosx10.6.zip',
-        'Mac OS X 10.5': 'http://mercurial.berkwood.com/binaries/Mercurial-1.6.3-py2.5-macosx10.5.zip',
-        'Source code': 'http://mercurial.selenic.com/release/mercurial-1.6.3.tar.gz'},
-    '1.6.2' : {
-        'TortoiseHG for Windows 64bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.1.2-hg-1.6.2-x64.msi',
-        'TortoiseHG for Windows 32bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.1.2-hg-1.6.2-x86.msi',
-        'Windows': 'http://bitbucket.org/tortoisehg/thg-winbuild/downloads/mercurial-1.6.2.msi',
-        'Mac OS X 10.6': 'http://mercurial.berkwood.com/binaries/Mercurial-1.6.2-py2.6-macosx10.6.zip',
-        'Mac OS X 10.5': 'http://mercurial.berkwood.com/binaries/Mercurial-1.6.2-py2.5-macosx10.5.zip',
-        'Source code': 'http://mercurial.selenic.com/release/mercurial-1.6.2.tar.gz'},
-    '1.6.1' : {
-        'TortoiseHG for Windows 64bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.2-hg-1.6.1-x64.msi',
-        'TortoiseHG for Windows 32bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.2-hg-1.6.1-x86.msi',
-        'Windows': 'http://bitbucket.org/tortoisehg/thg-winbuild/downloads/mercurial-1.6.1.msi',
-        'Mac OS X 10.6': 'http://mercurial.berkwood.com/binaries/Mercurial-1.6.1-py2.6-macosx10.6.zip',
-        'Mac OS X 10.5': 'http://mercurial.berkwood.com/binaries/Mercurial-1.6.1-py2.5-macosx10.5.zip',
-        'Source code': 'http://mercurial.selenic.com/release/mercurial-1.6.1.tar.gz'},
-    '1.6' : {
-        'TortoiseHG for Windows 64bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.1-hg-1.6-x64.msi',
-        'TortoiseHG for Windows 32bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.1-hg-1.6-x86.msi',
-        'Windows': 'http://bitbucket.org/tortoisehg/thg-winbuild/downloads/mercurial-1.6.0.msi',
-        'Mac OS X 10.6': 'http://mercurial.berkwood.com/binaries/Mercurial-1.6-py2.6-macosx10.6.zip',
-        'Mac OS X 10.5': 'http://mercurial.berkwood.com/binaries/Mercurial-1.6-py2.5-macosx10.5.zip',
-        'Source code': 'http://mercurial.selenic.com/release/mercurial-1.6.tar.gz'},
-    '1.5.4' : {
-        'TortoiseHG for Windows 64bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.0.4-hg-1.5.4-x64.msi',
-        'TortoiseHG for Windows 32bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.0.4-hg-1.5.4-x86.msi',
-        'Windows': 'http://bitbucket.org/tortoisehg/thg-winbuild/downloads/mercurial-1.5.4.msi',
-        'Mac OS X 10.6': 'http://mercurial.berkwood.com/binaries/Mercurial-1.5.4-py2.6-macosx10.6.zip',
-        'Mac OS X 10.5': 'http://mercurial.berkwood.com/binaries/Mercurial-1.5.4-py2.5-macosx10.5.zip',
-        'Source code': 'http://mercurial.selenic.com/release/mercurial-1.5.4.tar.gz'},
-    '1.5.3' : {
-        'TortoiseHG for Windows 64bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.0.3-hg-1.5.3-x64.msi',
-        'TortoiseHG for Windows 32bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.0.3-hg-1.5.3-x86.msi',
-        'Windows': 'http://bitbucket.org/tortoisehg/thg-winbuild/downloads/mercurial-1.5.3.msi',
-        'Mac OS X 10.6': 'http://mercurial.berkwood.com/binaries/Mercurial-1.5.3-py2.6-macosx10.6.zip',
-        'Mac OS X 10.5': 'http://mercurial.berkwood.com/binaries/Mercurial-1.5.3-py2.5-macosx10.5.zip',
-        'Source code': 'http://mercurial.selenic.com/release/mercurial-1.5.3.tar.gz'},
-    '1.5.2' : {
-        'TortoiseHG for Windows 64bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.0.2-hg-1.5.2-x64.msi',
-        'TortoiseHG for Windows 32bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.0.2-hg-1.5.2-x86.msi',
-        'Windows': 'http://bitbucket.org/tortoisehg/thg-winbuild/downloads/mercurial-1.5.2.msi',
-        'Mac OS X 10.6': 'http://mercurial.berkwood.com/binaries/Mercurial-1.5.2-py2.6-macosx10.6.zip',
-        'Mac OS X 10.5': 'http://mercurial.berkwood.com/binaries/Mercurial-1.5.2-py2.5-macosx10.5.zip',
-        'Source code': 'http://mercurial.selenic.com/release/mercurial-1.5.2.tar.gz'},
-    '1.5' : {
-        'TortoiseHG for Windows 64bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.0-hg-1.5-x64.msi',
-        'TortoiseHG for Windows 32bit': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-1.0-hg-1.5-x86.msi',
-        'Windows': 'http://bitbucket.org/tortoisehg/thg-winbuild/downloads/mercurial-1.5.0.msi',
-        'Mac OS X 10.6': 'http://mercurial.berkwood.com/binaries/Mercurial-1.5-py2.6-macosx10.6.zip',
-        'Mac OS X 10.5': 'http://mercurial.berkwood.com/binaries/Mercurial-1.5-py2.5-macosx10.5.zip',
-        'Source code': 'http://mercurial.selenic.com/release/mercurial-1.5.tar.gz'},
-    '1.4.3' : {
-        'Windows (TortoiseHg)': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-0.9.3-hg-1.4.3.exe',
-        'Windows': 'http://bitbucket.org/tortoisehg/thg-winbuild/downloads/mercurial-1.4.3.exe',
-        'Mac OS X 10.6': 'http://mercurial.berkwood.com/binaries/Mercurial-1.4.3-py2.6-macosx10.6.zip',
-        'Mac OS X 10.5': 'http://mercurial.berkwood.com/binaries/Mercurial-1.4.3-py2.5-macosx10.5.zip',
-        'Source code': 'http://mercurial.selenic.com/release/mercurial-1.4.3.tar.gz'},
-    '1.4.2': {
-        'Windows (TortoiseHg)': 'http://bitbucket.org/tortoisehg/stable/downloads/tortoisehg-0.9.2-1-hg-1.4.2.exe',
-        'Windows': 'http://bitbucket.org/tortoisehg/thg-winbuild/downloads/mercurial-1.4.2.exe',
-        'Mac OS X 10.6': 'http://mercurial.berkwood.com/binaries/Mercurial-1.4.2-py2.6-macosx10.6.zip',
-        'Mac OS X 10.5': 'http://mercurial.berkwood.com/binaries/Mercurial-1.4.2-py2.5-macosx10.5.zip',
-        'Source code': 'http://mercurial.selenic.com/release/mercurial-1.4.2.tar.gz'},
-    '1.4.1': {
-        'Windows (TortoiseHg)': 'http://bitbucket.org/tortoisehg/stable/downloads/TortoiseHg-0.9.1.1-hg-1.4.1.exe',
-        'Windows': 'http://mercurial.berkwood.com/binaries/Mercurial-1.4.1.exe',
-        'Mac OS X 10.6': 'http://mercurial.berkwood.com/binaries/Mercurial-1.4.1-py2.6-macosx10.6.zip',
-        'Mac OS X 10.5': 'http://mercurial.berkwood.com/binaries/Mercurial-1.4.1-py2.5-macosx10.5.zip',
-        'Source code': 'http://mercurial.selenic.com/release/mercurial-1.4.1.tar.gz'},
-    '1.4': {
-        'Windows (TortoiseHg)': 'http://bitbucket.org/tortoisehg/stable/downloads/TortoiseHg-0.9-hg-1.4.exe',
-        'Windows': 'http://mercurial.berkwood.com/binaries/Mercurial-1.4.exe',
-        'Mac OS X 10.6': 'http://mercurial.berkwood.com/binaries/Mercurial-1.4-py2.6-macosx10.6.zip',
-        'Mac OS X 10.5': 'http://mercurial.berkwood.com/binaries/Mercurial-1.4-py2.5-macosx10.5.zip',
-        'Source code': 'http://mercurial.selenic.com/release/mercurial-1.4.tar.gz'},
-    '1.3.1': {
-        'Windows (TortoiseHg)': 'http://bitbucket.org/tortoisehg/stable/downloads/TortoiseHg-0.8.1-hg-1.3.1.exe',
-        'Windows': 'http://mercurial.berkwood.com/binaries/Mercurial-1.3.1.exe',
-        'Mac OS X 10.6': 'http://mercurial.berkwood.com/binaries/Mercurial-1.3.1-py2.6-macosx10.6.zip',
-        'Mac OS X 10.5': 'http://mercurial.berkwood.com/binaries/Mercurial-1.3.1-py2.5-macosx10.5.zip',
-        'Source code': 'http://mercurial.selenic.com/release/mercurial-1.3.1.tar.gz'}}
-%}




More information about the Mercurial-devel mailing list