From dd7fdb87ac594d63b92b22ca3869059c92a60fbb Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Fri, 6 Feb 2009 23:45:03 -0500 Subject: [PATCH] add download link on full code listings --- .htaccess | 2 +- dip3.css | 2 +- dip3.js | 11 ++++++++++- humansize.py | 23 +++++++++++++++++++++++ your-first-python-program.html | 7 +++++-- 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/.htaccess b/.htaccess index a6b38a2..119ec12 100644 --- a/.htaccess +++ b/.htaccess @@ -3,6 +3,6 @@ FileETag MTime Size Options -Indexes DirectoryIndex index.html AddType text/plain .txt -AddType text/plain .py +AddType application/x-python .py AddType image/x-icon .ico AddDefaultCharset utf-8 diff --git a/dip3.css b/dip3.css index c8eac31..1688d99 100644 --- a/dip3.css +++ b/dip3.css @@ -15,7 +15,7 @@ pre{white-space:pre-wrap;padding-left:2.154em;line-height:1.75;border-left:1px d pre,kbd,code,samp{font-family:Consolas,Inconsolata,Monaco,monospace;font-size:medium;word-spacing:0} pre a{padding:0.4375em 0;border:0} pre a:hover{border:0} -.widgets,.widgets a{font-size:small} +.widgets,.widgets a,.download{font-size:small} .widgets a{color:#1b67c9;text-decoration:underline;padding:0} kbd{font-weight:bold} .prompt{color:#667}/*the neighbor of the beast*/ diff --git a/dip3.js b/dip3.js index b9df45f..7c996d7 100644 --- a/dip3.js +++ b/dip3.js @@ -60,7 +60,16 @@ for (var i = arPre.length - 1; i >= 0; i--) { id = "autopre" + i; elmPre.id = id; } - elmPre.innerHTML = '
[hide] [open in new window]
' + elmPre.innerHTML + '
'; + var usDownload = ''; + var elmDownload = elmPre.previousSibling; + while (elmDownload && (elmDownload.nodeType != 1)) { + elmDownload = elmDownload.previousSibling; + } + if (elmDownload && (elmDownload.nodeName.toLowerCase() == 'p') && (elmDownload.className == 'download')) { + usDownload = ' ' + elmDownload.innerHTML; + elmDownload.parentNode.removeChild(elmDownload); + } + elmPre.innerHTML = '
[hide] [open in new window]' + usDownload + '
' + elmPre.innerHTML + '
'; } } diff --git a/humansize.py b/humansize.py index e41db15..cd92778 100644 --- a/humansize.py +++ b/humansize.py @@ -40,3 +40,26 @@ def approximate_size(size, a_kilobyte_is_1024_bytes=True): if __name__ == "__main__": print(approximate_size(1000000000000, False)) print(approximate_size(1000000000000)) + +# Copyright (c) 2009, Mark Pilgrim, All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. diff --git a/your-first-python-program.html b/your-first-python-program.html index 4d3bd2c..eb9985e 100644 --- a/your-first-python-program.html +++ b/your-first-python-program.html @@ -4,7 +4,7 @@ Your first Python program - Dive into Python 3 - +