[Rt-commit] r5853 - in RT-View-ConciseSpreadsheet: .

jesse at bestpractical.com jesse at bestpractical.com
Mon Sep 4 14:50:35 EDT 2006


Author: jesse
Date: Mon Sep  4 14:50:35 2006
New Revision: 5853

Modified:
   RT-View-ConciseSpreadsheet/   (props changed)
   RT-View-ConciseSpreadsheet/META.yml
   RT-View-ConciseSpreadsheet/Makefile.PL
   RT-View-ConciseSpreadsheet/html/ConciseSpreadsheet/Results.tsv

Log:
* Todd Chapman contributed a patch to more correctly quote entites in results.tsv


Modified: RT-View-ConciseSpreadsheet/META.yml
==============================================================================
--- RT-View-ConciseSpreadsheet/META.yml	(original)
+++ RT-View-ConciseSpreadsheet/META.yml	Mon Sep  4 14:50:35 2006
@@ -1,13 +1,15 @@
-name: RT-View-ConciseSpreadsheet
-version: 0.001
-abstract: [One line description of module's purpose here]
+abstract: "[One line description of module's purpose here]"
 author: Jesse Vincent <jesse at bestpractical.com>
-license: perl
 distribution_type: module
-requires:
-  Test::More: 0
-no_index:
-  directory:
+generated_by: Module::Install version 0.63
+license: perl
+name: RT-View-ConciseSpreadsheet
+no_index: 
+  directory: 
     - html
     - inc
-generated_by: Module::Install version 0.37
+    - t
+requires: 
+  Test::More: 0
+  Text::CSV_XS: 0
+version: 0.001

Modified: RT-View-ConciseSpreadsheet/Makefile.PL
==============================================================================
--- RT-View-ConciseSpreadsheet/Makefile.PL	(original)
+++ RT-View-ConciseSpreadsheet/Makefile.PL	Mon Sep  4 14:50:35 2006
@@ -6,5 +6,6 @@
 abstract_from('lib/RT/View/ConciseSpreadsheet.pm');
 license('perl');
 requires('Test::More');
+requires('Text::CSV_XS');
 
 &WriteAll;

Modified: RT-View-ConciseSpreadsheet/html/ConciseSpreadsheet/Results.tsv
==============================================================================
--- RT-View-ConciseSpreadsheet/html/ConciseSpreadsheet/Results.tsv	(original)
+++ RT-View-ConciseSpreadsheet/html/ConciseSpreadsheet/Results.tsv	Mon Sep  4 14:50:35 2006
@@ -1,5 +1,7 @@
 <%INIT>
 
+use Text::CSV_XS;
+
 my $Tickets = RT::Tickets->new($session{'CurrentUser'});
 $Tickets->FromSQL($ARGS{'Query'});
 
@@ -10,9 +12,7 @@
 
 $r->content_type('application/vnd.ms-excel');
 
-my @rows=();
 my @header=();
-my @cols=();
 
 # used to store m->comp output - prevents the output from being 
 # written to the output stream. That's because we are not interested in the
@@ -22,14 +22,6 @@
 foreach my $column (@Format) {
     next if $column->{title} eq 'NEWLINE';
 
-    # Extract the column names from the Format array
-    foreach my $subcol ( @{ $column->{output} } ) {
-        if ( $subcol =~ /^__(.*?)__$/o ) {
-            my $col = $1;
-            push (@cols, $col);
-        }
-    }
-
     # Determine the column titles
     my $title = $column->{title};
     $title =~ s/^__(.*)__$/$1/o;
@@ -45,43 +37,45 @@
     push @header, $title;
 }
 
+my $csv = Text::CSV_XS->new( { sep_char => "\t", binary => 1, eol => "\012" } );
+
+$csv->combine(@header);
+$m->out( $csv->string() );
+
 while ( my $Ticket = $Tickets->Next()) {
-    my $row;
-    foreach my $column (@cols) {
-        my $value = $m->comp({ store => \$mason_output }, 
-                             '/Elements/RT__Ticket/ColumnMap', 
-                             Name => $column, Attr => 'value');
-        if ( $value && ref($value)) {
-            my @x = &{ $value }( $Ticket, 0 );
-            my $i=0;
-            $row->{ $column } = "";
-            foreach my $x (@x) {
-                $row->{ $column } .= ", " if $i > 0; # separating multivalues
-                if (ref ($x)) {
-                    $row->{ $column } .= $$x;
-                } else {                        
-                    $row->{ $column } .= $x;
+    my @row;
+    foreach my $column (@Format) {
+        next if $column->{title} eq 'NEWLINE';
+
+        my $column_value = '';
+
+        foreach my $subcol ( @{ $column->{output} } ) {
+            if ( $subcol =~ /^__(.*?)__$/o ) {
+                my $col = $1;
+                my $value = $m->comp({ store => \$mason_output }, 
+                                     '/Elements/RT__Ticket/ColumnMap', 
+                                     Name => $col, Attr => 'value');
+                if ( $value && ref($value)) {
+                    my @x = &{ $value }( $Ticket, 0 );
+                    $column_value .= join('', map { ref($_) ? $$_ : $_ } @x);
+                } else {
+                    $column_value .=  $value;
                 }
-                $i++;
             }
-        } else {
-            $row->{ $column } =  $value ;
+            else {
+                $column_value .= $subcol;
+            }
         }
-        $row->{ $column } =~ s/, <br>//g;    # ColumnMap adds <br> tags, which we don't want
-    }
-    push @rows, $row;
-}
 
-$m->out(join("\t", @header));
-$m->out("\n");
+        $column_value =~ s{<br(\s+/)?>}{, }g;
+        $column_value =  $scrubber->scrub( $column_value );
+        $column_value =~ s{, $}{}g;    # ColumnMap is putting a trailing br
 
-foreach my $row (@rows) {
-        my @row;
-        foreach my $col(@cols) {
-                push @row, $row->{"$col"};
-        }
-        $m->out(join("\t", at row));
-        $m->out("\n");
+        push @row, $column_value;
+    }
+    $csv->combine(@row);
+    $m->out( $csv->string() );
+    $m->flush_buffer();
 }
 
 $m->abort();
@@ -95,3 +89,7 @@
 $OrderBy => 'id'
 $Order => 'ASC'
 </%ARGS>
+<%once>
+my $scrubber = HTML::Scrubber->new();
+$scrubber->deny(qw[*]);
+</%once>


More information about the Rt-commit mailing list