incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1142768 - /incubator/ooo/site/trunk/lib/view.pm
Date Mon, 04 Jul 2011 19:14:46 GMT
Author: joes
Date: Mon Jul  4 19:14:46 2011
New Revision: 1142768

URL: http://svn.apache.org/viewvc?rev=1142768&view=rev
Log:
experiment with sorter

Modified:
    incubator/ooo/site/trunk/lib/view.pm

Modified: incubator/ooo/site/trunk/lib/view.pm
URL: http://svn.apache.org/viewvc/incubator/ooo/site/trunk/lib/view.pm?rev=1142768&r1=1142767&r2=1142768&view=diff
==============================================================================
--- incubator/ooo/site/trunk/lib/view.pm (original)
+++ incubator/ooo/site/trunk/lib/view.pm Mon Jul  4 19:14:46 2011
@@ -52,6 +52,8 @@ sub single_narrative {
 #		print STDOUT "$ke \n";
 #	}
 
+    $args{content} = sort_tables($args{content});
+
     return Template($template)->render(\%args), html => \%args;
 }
 
@@ -180,6 +182,43 @@ sub breadcrumbs {
     return join " &raquo ", @rv;
 }
 
+sub sort_tables {
+    my @orig = split /\n/, shift;
+    my @out;
+    while (defined(local $_ = shift @orig))  {
+        push @out, $_;
+        /^(\|[v^-]+)+\|)$/ or next;
+        my($col, $direction, $cur);
+        $cur = 0;
+        while (/\G\|([v^-])+/g) {
+            my $data = $1;
+            if ($data =~ tr/v/v/) {
+                $col = $cur;
+                $direction = 1;
+            }
+            elsif ($data =~ tr/^/^/) {
+                $col = $cur;
+                $direction = -1;
+            }
+            $cur++;
+        }
+        unless (defined $col) {
+            push @out, shift @orig while $orig[0] =~ /^\|/;
+            next;
+        }
+        my @rows;
+        push @rows, [split /\s*\|\s*/, shift @orig]
+            while $orig[0] =~ /^\|/;
+        shift @$_ for @rows; # dump empty entry at front
+        @rows = sort { $a->[$col] cmp $b->[$col] } @rows;
+        @rows = reverse @rows if $direction == -1;
+        push @out, join " | ", "", @rows, "";
+    }
+
+    return join "\n", @out, "";
+}
+
+
 
 =head1 LICENSE
 



Mime
View raw message