[exim-cvs] Let people select older versions of the documenta…

Top Page
Delete this message
Reply to this message
Author: Exim Git Commits Mailing List
Date:  
To: exim-cvs
Subject: [exim-cvs] Let people select older versions of the documentation
Gitweb: http://git.exim.org/exim-website.git/commitdiff/1fa8d85e79abda7ae7e994d1f30aa0a3693de1ce
Commit:     1fa8d85e79abda7ae7e994d1f30aa0a3693de1ce
Parent:     7e380e72021a4fcc57295367a71f14176343ad23
Author:     Mike Cardwell <github@???>
AuthorDate: Wed Sep 7 15:03:23 2011 +0100
Committer:  Mike Cardwell <github@???>
CommitDate: Wed Sep 7 15:03:23 2011 +0100


    Let people select older versions of the documentation
---
 script/gen.pl          |   16 ++++++++++++++++
 templates/web/docs.css |    3 +++
 templates/web/docs.js  |   10 ++++++++++
 templates/web/docs.xsl |   30 ++++++++++++++++++++++++++----
 4 files changed, 55 insertions(+), 4 deletions(-)


diff --git a/script/gen.pl b/script/gen.pl
index 3cf3acd..f3e0486 100755
--- a/script/gen.pl
+++ b/script/gen.pl
@@ -21,6 +21,7 @@ my $canonical_url = 'http://www.exim.org/';
my %opt = parse_arguments();

 ## Generate the pages
+my %cache; # General cache object
 do_doc( 'spec',   $_ ) foreach @{ $opt{spec}   || [] };
 do_doc( 'filter', $_ ) foreach @{ $opt{filter} || [] };
 do_web() if exists $opt{web};
@@ -332,6 +333,9 @@ sub transform {
     ## Add the current version of Exim to the XML
     $xml->documentElement()->appendTextChild( 'current_version', $opt{latest} );


+    ## Add the old versions of Exim to the XML
+    $xml->documentElement()->appendTextChild( 'old_versions', $_ ) foreach old_docs_versions();
+
     ## Parse the ".xsl" file as XML
     my $xsl = XML::LibXML->new()->parse_file($xsl_path) or die $!;


@@ -350,6 +354,18 @@ sub transform {
     close $out;
 }


+## Look in the docroot for old versions of the documentation 
+sub old_docs_versions {
+   if( !exists $cache{old_docs_versions} ){
+      my @versions;
+      foreach( glob("$opt{docroot}/exim-html-*") ){
+         push @versions, $1 if /-(\d+(?:\.\d+)?)$/ && $1 < $opt{latest} && -d $_;
+      }
+      $cache{old_docs_versions} = [reverse sort {$a<=>$b} @versions];
+   }
+   return @{$cache{old_docs_versions}};
+}
+
 ## error_help
 sub error_help {
     my $msg = shift;
diff --git a/templates/web/docs.css b/templates/web/docs.css
new file mode 100644
index 0000000..9056a73
--- /dev/null
+++ b/templates/web/docs.css
@@ -0,0 +1,3 @@
+body.no-js p.manual_info select {
+    display:    none;
+}
diff --git a/templates/web/docs.js b/templates/web/docs.js
new file mode 100644
index 0000000..8e604bc
--- /dev/null
+++ b/templates/web/docs.js
@@ -0,0 +1,10 @@
+(function($){
+    $('p.manual_info select').each(function(){
+        $(this).change(function(e){
+            if( $(this).val().match(/^[0-9\.]+$/) ){
+                var href = $(this).parent().find('a').attr('href').replace('-current/','-'+$(this).val()+'/');
+                document.location.href=href;
+            }
+        });
+    });
+})(jQuery);
diff --git a/templates/web/docs.xsl b/templates/web/docs.xsl
index 2517496..1b154c6 100644
--- a/templates/web/docs.xsl
+++ b/templates/web/docs.xsl
@@ -11,10 +11,20 @@
     <!-- Title -->
         <xsl:variable name="html.head.title" select="'Documentation for Exim'"/>


-        <!-- Canonical -->
-                <xsl:variable name="html.head.append">
-                        <link rel="canonical" href="http://www.exim.org/docs.html"/>
-                </xsl:variable>
+                
+    <xsl:variable name="html.head.append">
+
+        <!-- Canonical -->
+            <link rel="canonical" href="http://www.exim.org/docs.html"/>
+
+        <!-- CSS -->
+            <link rel="stylesheet" type="text/css" href="docs.css"/>
+    </xsl:variable>
+
+    <!-- JavaScript -->
+        <xsl:variable name="html.body.append">
+            <script type="text/javascript" src="docs.js"/>
+        </xsl:variable>


     <!-- CONTENT -->
         <xsl:template name="content">
@@ -46,6 +56,12 @@


                     <xsl:text> - The master documentation for Exim containing all required detail to install, configure and use Exim. </xsl:text>
                     <span class="changed">Changes to the documentation (normally reflecting changes to the functionality of Exim) are shown on a green background like this segment.</span>
+                    <br/><select name="spec_old_version">
+                        <option value="">View Older Versions</option>
+                        <xsl:for-each select="/content/old_versions">
+                            <option value="{text()}"><xsl:value-of select="text()"/></option>
+                        </xsl:for-each>
+                    </select>
                 </p>


                 <p class="manual_info">
@@ -57,6 +73,12 @@
                     <xsl:text> </xsl:text>
                     <a href="{$docroot}/exim-pdf-current/doc/filter.pdf">(PDF)</a>
                     <xsl:text> - Additional information on the Exim filter language.</xsl:text>
+                    <br/><select name="filter_old_version">
+                        <option value="">View Older Versions</option>
+                        <xsl:for-each select="/content/old_versions">
+                            <option value="{text()}"><xsl:value-of select="text()"/></option>
+                        </xsl:for-each>
+                    </select>
                 </p>


             <!-- HOWTOs -->