User: sits    
  Date: 08/06/16 04:32:07

  Modified:    lib/Codestriker/Http HtmlEntityLineFilter.pm
                        DeltaRenderer.pm TabToNbspLineFilter.pm
                        LineBreakLineFilter.pm LineFilter.pm
  Added:       lib/Codestriker/Http HighlightLineFilter.pm
  Log:
  Initial refactoring of line filtering, so that it can accept text in chunks 
rather than line-by-line so that external highlighting can be performed.
  
  
  
  Index: HtmlEntityLineFilter.pm
  ===================================================================
  RCS file: 
/cvsroot/codestriker/codestriker/lib/Codestriker/Http/HtmlEntityLineFilter.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HtmlEntityLineFilter.pm   10 Mar 2008 23:18:03 -0000      1.1
  +++ HtmlEntityLineFilter.pm   16 Jun 2008 11:32:05 -0000      1.2
  @@ -25,9 +25,10 @@
   
   # Escape all HTML entities so that they are displayed correctly.
   sub filter {
  -    my ($self, $text) = @_;
  +    my ($self, $delta) = @_;
       
  -    return HTML::Entities::encode($text);
  +    $delta->{diff_old_lines} = 
HTML::Entities::encode($delta->{diff_old_lines});
  +    $delta->{diff_new_lines} = 
HTML::Entities::encode($delta->{diff_new_lines});
   }
   
   1;
  
  
  
  
  
  Index: DeltaRenderer.pm
  ===================================================================
  RCS file: 
/cvsroot/codestriker/codestriker/lib/Codestriker/Http/DeltaRenderer.pm,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DeltaRenderer.pm  13 Jun 2008 05:55:12 -0000      1.6
  +++ DeltaRenderer.pm  16 Jun 2008 11:32:05 -0000      1.7
  @@ -59,10 +59,10 @@
       @{$self->{line_filters}} = ();
       push @{$self->{line_filters}}, 
Codestriker::Http::HtmlEntityLineFilter->new();
       push @{$self->{line_filters}}, 
Codestriker::Http::TabToNbspLineFilter->new($tabwidth);
  -    push @{$self->{line_filters}}, 
Codestriker::Http::LineBreakLineFilter->new($brmode);
  -    if (defined $lxr_config) {
  -         push @{$self->{line_filters}}, 
Codestriker::Http::LxrLineFilter->new($lxr_config);
  -    }
  +    #push @{$self->{line_filters}}, 
Codestriker::Http::LineBreakLineFilter->new($brmode);
  +    #if (defined $lxr_config) {
  +     #    push @{$self->{line_filters}}, 
Codestriker::Http::LxrLineFilter->new($lxr_config);
  +    #}
   
       bless $self, $type;
   }
  @@ -131,9 +131,34 @@
   
       foreach my $delta (@{ $self->{deltas} }) {
   
  -     # Now process the text so that the display code has minimal work to do.
  -     # Also apply appropriate transformations to the line as required.
  +     # Split the delta into the left and right side so that text filtering
  +     # can be applied.
        my @diff_lines = split /\n/, $delta->{text};
  +     for (my $i = 0; $i <= $#diff_lines; $i++) {
  +         my $data = $diff_lines[$i];
  +
  +         if ($data =~ /^\-(.*)$/o) {
  +             # Line corresponding to old code.
  +             $delta->{diff_old_lines} .= "$1\n";
  +         } elsif ($data =~ /^\+(.*)$/o) {
  +             # Line corresponding to new code.
  +             $delta->{diff_new_lines} .= "$1\n";
  +         } elsif ($data =~ /^\\/) {
  +             # A diff comment such as "No newline at end of file" - ignore 
it.
  +         } else {
  +             # Line corresponding to both sides. Strip the first space off
  +             # the diff for proper alignment.
  +             $data =~ s/^\s//;
  +             $delta->{diff_old_lines} .= "$data\n";
  +             $delta->{diff_new_lines} .= "$data\n";
  +         }
  +     }
  +
  +     # Apply the line filters through the delta text.
  +     $self->_apply_line_filters($delta);
  +     
  +     # Now go through the delta text again to determine what lines are to be
  +     # rendered.
        my $old_linenumber = $delta->{old_linenumber};
        my $new_linenumber = $delta->{new_linenumber};
        @{$self->{lines}} = ();
  @@ -142,25 +167,29 @@
        @{$self->{diff_new_lines}} = ();
        @{$self->{diff_new_lines_numbers}} = ();
        $self->{current_filename} = "";
  +     my $old_index = 0;
  +     my $new_index = 0;
  +     my @filtered_old_lines = split /\n/, $delta->{diff_old_lines};
  +     my @filtered_new_lines = split /\n/, $delta->{diff_new_lines};
        for (my $i = 0; $i <= $#diff_lines; $i++) {
            my $data = $diff_lines[$i];
   
  -         if ($data =~ /^\-(.*)$/o) {
  +         if ($data =~ /^\-/o) {
                # Line corresponding to old code.
  -             push @{ $self->{diff_old_lines} }, $1;
  +             push @{ $self->{diff_old_lines} }, 
$filtered_old_lines[$old_index++];
                push @{ $self->{diff_old_lines_numbers} }, $old_linenumber;
                $old_linenumber++;
            } elsif ($data =~ /^\+(.*)$/o) {
                # Line corresponding to new code.
  -             push @{ $self->{diff_new_lines} }, $1;
  +             push @{ $self->{diff_new_lines} }, 
$filtered_new_lines[$new_index++];
                push @{ $self->{diff_new_lines_numbers} }, $new_linenumber;
                $new_linenumber++;
            } elsif ($data =~ /^\\/) {
                # A diff comment such as "No newline at end of file" - ignore 
it.
            } else {
  -             # Line corresponding to both sides. Strip the first space off
  -             # the diff for proper alignment.
  -             $data =~ s/^\s//;
  +             # Line corresponding to both sides.
  +             $data = $filtered_old_lines[$old_index++];
  +             $new_index++;
                
                # Render what has been currently recorded.
                $self->_render_changes($delta->{filenumber});
  @@ -173,7 +202,6 @@
   
                # Now render the line which is present on both sides.
                my $line = {};
  -             $data = $self->_apply_line_filters($data);
                my $data_class =
                    $self->{mode} == $Codestriker::COLOURED_MODE ? "n" : "msn";
                $line->{old_data} = $data;
  @@ -189,7 +217,7 @@
                push @{$self->{lines}}, $line;
                $old_linenumber++;
                $new_linenumber++;
  -         }
  +     }
   
            # Check if the delta corresponds to a new file.  This is true
            # if there is only one delta for the whole file, there are no
  @@ -200,8 +228,8 @@
            if ($delta->{new_file}) {
                $delta->{new_file_class} =
                    $self->{mode} == $Codestriker::COLOURED_MODE ? "n" : "msn";
  -         }
  -     }
  +        }
  +    }
   
        # Render any remaining diff segments.
        $self->_render_changes($delta->{filenumber});
  @@ -213,7 +241,7 @@
            # Keep track of the current filename being processed.
            $self->{current_filename} = $delta->{filename};
        }
  -    }
  +}    
   }
   
   # Annotate any accumlated diff changes.
  @@ -296,13 +324,13 @@
        
        my $line = {};
        if (defined $old_data) {
  -         $line->{old_data} = $self->_apply_line_filters($old_data);
  +         $line->{old_data} = $old_data;
            $line->{old_data_line} =
                $self->comment_link($filenumber, $old_data_line, 0, 
$old_data_line);
        }
        $line->{old_data_class} = $render_old_colour;
        if (defined $new_data) {
  -         $line->{new_data} = $self->_apply_line_filters($new_data);
  +         $line->{new_data} = $new_data;
            $line->{new_data_line} =
                $self->comment_link($filenumber, $new_data_line, 1, 
$new_data_line);
        }
  @@ -312,16 +340,16 @@
   
       # Apply all of the line filters to the line of text supplied.
       sub _apply_line_filters {
  -     my ($self, $text) = @_;
  +     my ($self, $delta) = @_;
   
        # TODO: perform syntax highlighting.
        foreach my $line_filter (@{$self->{line_filters}}) {
  -         $text = $line_filter->filter($text);
  +         $line_filter->filter($delta);
        }
            
        # Unconditionally add a &nbsp; at the start for better alignment.
        # Fix so count isn't stuffed.
  -     return "&nbsp;" . $text;
  +     # return "&nbsp;" . $text;
       }
   }
   
  
  
  
  
  
  Index: TabToNbspLineFilter.pm
  ===================================================================
  RCS file: 
/cvsroot/codestriker/codestriker/lib/Codestriker/Http/TabToNbspLineFilter.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TabToNbspLineFilter.pm    10 Mar 2008 23:18:04 -0000      1.1
  +++ TabToNbspLineFilter.pm    16 Jun 2008 11:32:05 -0000      1.2
  @@ -28,9 +28,9 @@
   }
   
   # Convert tabs to the appropriate number of &nbsp; entities.
  -sub filter {
  +sub _filter {
       my ($self, $text) = @_;
  -    
  +
       my $tabwidth = $self->{tabwidth};
       1 while $text =~ s/\t+/'&nbsp;' x
        (length($&) * $tabwidth - length($`) % $tabwidth)/eo;
  @@ -38,4 +38,12 @@
       return $text;
   }
   
  +# Convert tabs to the appropriate number of &nbsp; entities.
  +sub filter {
  +    my ($self, $delta) = @_;
  +    
  +    $delta->{diff_old_lines} = $self->_filter($delta->{diff_old_lines});
  +    $delta->{diff_new_lines} = $self->_filter($delta->{diff_new_lines});
  +}
  +
   1;
  
  
  
  
  
  Index: LineBreakLineFilter.pm
  ===================================================================
  RCS file: 
/cvsroot/codestriker/codestriker/lib/Codestriker/Http/LineBreakLineFilter.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LineBreakLineFilter.pm    10 Mar 2008 23:18:04 -0000      1.1
  +++ LineBreakLineFilter.pm    16 Jun 2008 11:32:05 -0000      1.2
  @@ -28,17 +28,25 @@
   }
   
   # Convert the spaces appropriately for line-breaking.
  -sub filter {
  +sub _filter {
       my ($self, $text) = @_;
       
       if ($self->{brmode} == $Codestriker::LINE_BREAK_ASSIST_MODE) {
        $text =~ s/^(\s+)/my $sp='';for(my 
$i=0;$i<length($1);$i++){$sp.='&nbsp;'}$sp;/ge;
       }
       else {
  -     $text =~ s/\s/&nbsp;/g;
  +     $text =~ s/ /&nbsp;/g;
       }
   
       return $text;
   }
   
  +# Convert the spaces appropriately for line-breaking.
  +sub filter {
  +    my ($self, $delta) = @_;
  +    
  +    $delta->{diff_old_lines} = $self->_filter($delta->{diff_old_lines});
  +    $delta->{diff_new_lines} = $self->_filter($delta->{diff_new_lines});
  +}
  +
   1;
  
  
  
  
  
  Index: LineFilter.pm
  ===================================================================
  RCS file: 
/cvsroot/codestriker/codestriker/lib/Codestriker/Http/LineFilter.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LineFilter.pm     10 Mar 2008 23:18:04 -0000      1.1
  +++ LineFilter.pm     16 Jun 2008 11:32:05 -0000      1.2
  @@ -19,10 +19,9 @@
   }
   
   sub filter {
  -    my ($self, $text) = @_;
  +    my ($self, $delta) = @_;
       
       # Default is a no-op.
  -    return $text;
   }
   
   1;
  
  
  
  
  
  Index: HighlightLineFilter.pm
  ===================================================================
  RCS file: HighlightLineFilter.pm
  diff -N HighlightLineFilter.pm
  --- /dev/null 1 Jan 1970 00:00:00 -0000
  +++ HighlightLineFilter.pm    16 Jun 2008 11:32:05 -0000      1.1
  @@ -0,0 +1,47 @@
  
+###############################################################################
  +# Codestriker: Copyright (c) 2001, 2002 David Sitsky.  All rights reserved.
  +# [EMAIL PROTECTED]
  +#
  +# This program is free software; you can redistribute it and modify it under
  +# the terms of the GPL.
  +
  +# Line filter for converting tabs to the appropriate number of &nbsp;
  +# entities.
  +
  +package Codestriker::Http::HighlightLineFilter;
  +
  +use strict;
  +
  +use Codestriker::Http::LineFilter;
  +
  [EMAIL PROTECTED]::Http::HighlightLineFilter::ISA =
  +    ("Codestriker::Http::LineFilter");
  +
  +# Take the desired tabwidth as a parameter.
  +sub new {
  +    my ($type, $highlight) = @_;
  +
  +    my $self = Codestriker::Http::LineFilter->new();
  +    $self->{highlight} = $highlight;
  +
  +    return bless $self, $type;
  +}
  +
  +# Convert tabs to the appropriate number of &nbsp; entities.
  +sub _filter {
  +    my ($self, $text) = @_;
  +
  +     
  +
  +    return $text;
  +}
  +
  +# Convert tabs to the appropriate number of &nbsp; entities.
  +sub filter {
  +    my ($self, $delta) = @_;
  +    
  +    $delta->{diff_old_lines} = $self->_filter($delta->{diff_old_lines});
  +    $delta->{diff_new_lines} = $self->_filter($delta->{diff_new_lines});
  +}
  +
  +1;
  
  
  

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Codestriker-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/codestriker-commits

Reply via email to