[Rt-commit] rt branch, 4.0-trunk, updated. rt-4.0.12-23-g6584cbe
Alex Vandiver
alexmv at bestpractical.com
Thu May 16 15:43:39 EDT 2013
The branch, 4.0-trunk has been updated
via 6584cbe01d801a712e5b82fe7dbdaa9549b1fba7 (commit)
via 04fa891bc0d8eb4494190501b9bf81cb35f45b9a (commit)
via aa76abca2e26c5d66c793be58c2d075dc2fb4334 (commit)
via f7100a4b9c4f15446c21575af6c77476a41e2b7b (commit)
via b83cb65eca749b21f152cc97f2425a94f6eec414 (commit)
from 8ecdd2bc96b77a5799d9726affaac0da969ecc42 (commit)
Summary of changes:
lib/RT/Transaction.pm | 97 ++++++++++++++---
t/api/transaction-quoting.t | 250 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 330 insertions(+), 17 deletions(-)
create mode 100644 t/api/transaction-quoting.t
- Log -----------------------------------------------------------------
commit 6584cbe01d801a712e5b82fe7dbdaa9549b1fba7
Merge: 8ecdd2b 04fa891
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Thu May 16 15:42:39 2013 -0400
Merge branch '4.0/text-wrap-and-quoting-long-lines' into 4.0-trunk
Conflicts:
lib/RT/Transaction.pm
diff --cc lib/RT/Transaction.pm
index 1832aef,6b10048..84e7010
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@@ -363,43 -363,94 +363,106 @@@ sub Content
}
if ( $args{'Quote'} ) {
+ $content = $self->ApplyQuoteWrap(content => $content,
+ cols => $args{'Wrap'} );
- # What's the longest line like?
- my $max = 0;
- foreach ( split ( /\n/, $content ) ) {
- $max = length if length > $max;
- }
-
- if ( $max > 76 ) {
- require Text::Wrapper;
- my $wrapper = Text::Wrapper->new(
- columns => $args{'Wrap'},
- body_start => ( $max > 70 * 3 ? ' ' : '' ),
- par_start => ''
- );
- $content = $wrapper->wrap($content);
- }
-
- $content =~ s/^/> /gm;
- $content = $self->loc("On [_1], [_2] wrote:", $self->CreatedAsString, $self->CreatorObj->Name)
- . "\n$content\n\n";
+ $content = $self->QuoteHeader . "\n$content\n\n";
}
return ($content);
}
+=head2 QuoteHeader
+
+Returns text prepended to content when transaction is quoted
+(see C<Quote> argument in L</Content>). By default returns
+localized "On <date> <user name> wrote:\n".
+
+=cut
+
+sub QuoteHeader {
+ my $self = shift;
+ return $self->loc("On [_1], [_2] wrote:", $self->CreatedAsString, $self->CreatorObj->Name);
+}
+
+ =head2 ApplyQuoteWrap PARAMHASH
+
+ Wrapper to calculate wrap criteria and apply quote wrapping if needed.
+
+ =cut
+
+ sub ApplyQuoteWrap {
+ my $self = shift;
+ my %args = @_;
+ my $content = $args{content};
+
+ # What's the longest line like?
+ my $max = 0;
+ foreach ( split ( /\n/, $args{content} ) ) {
+ $max = length if length > $max;
+ }
+
+ if ( $max > 76 ) {
+ require Text::Quoted;
+ require Text::Wrapper;
+
+ my $structure = Text::Quoted::extract($args{content});
+ $content = $self->QuoteWrap(content_ref => $structure,
+ cols => $args{cols},
+ max => $max );
+ }
+
+ $content =~ s/^/> /gm; # use regex since string might be multi-line
+ return $content;
+ }
+
+ =head2 QuoteWrap PARAMHASH
+
+ Wrap the contents of transactions based on Wrap settings, maintaining
+ the quote character from the original.
+
+ =cut
+
+ sub QuoteWrap {
+ my $self = shift;
+ my %args = @_;
+ my $ref = $args{content_ref};
+ my $final_string;
+
+ if ( ref $ref eq 'ARRAY' ){
+ foreach my $array (@$ref){
+ $final_string .= $self->QuoteWrap(content_ref => $array,
+ cols => $args{cols},
+ max => $args{max} );
+ }
+ }
+ elsif ( ref $ref eq 'HASH' ){
+ return $ref->{quoter} . "\n" if $ref->{empty}; # Blank line
+
+ my $col = $args{cols} - (length $ref->{quoter});
+ my $wrapper = Text::Wrapper->new( columns => $col );
+
+ # Wrap on individual lines to honor incoming line breaks
+ # Otherwise deliberate separate lines (like a list or a sig)
+ # all get combined incorrectly into single paragraphs.
+
+ my @lines = split /\n/, $ref->{text};
+ my $wrap = join '', map { $wrapper->wrap($_) } @lines;
+ my $quoter = $ref->{quoter};
+
+ # Only add the space if actually quoting
+ $quoter .= ' ' if length $quoter;
+ $wrap =~ s/^/$quoter/mg; # use regex since string might be multi-line
+
+ return $wrap;
+ }
+ else{
+ $RT::Logger->warning("Can't apply quoting with $ref");
+ return;
+ }
+ return $final_string;
+ }
+
=head2 Addresses
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list