Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the SVN-Notify CPAN distribution.

Report information
The Basics
Id:
52121
Status:
stalled
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
teguheko [...] gmail.com
Cc:
AdminCc:

BugTracker
Severity:
Important
Broken in:
2.79
Fixed in:
(no value)



Subject: HTML output with CSS inline
In my company, we are using Google apps Gmail interface to receive emails. Using the current output of SVN::Notify::HTML and SVN::Notify::HTML::ColorDiff, the HTML can not be rendered properly because of the nature of the web email. To fix that, the CSS need to be put inline in the HTML tags. I made a patch to receive css-inline parameter. But, the code is still kind of dirty, checking for each HTML string and if the parameter defined, I put the CSS inside the HTML tag. The code was a modification from http://www.jaim.at/2008/09/06/jack-moffitt-power-up-your-commit-e-mails/ Other alternative I can think of is to have a CSS inline converter which will get the HTML output and just convert the embedded CSS to be inline on the fly before sending the email.
Subject: HTML.pm
package SVN::Notify::HTML; # $Id: HTML.pm 4617 2009-03-19 17:04:53Z david $ use strict; use HTML::Entities; use SVN::Notify (); $SVN::Notify::HTML::VERSION = '2.79'; @SVN::Notify::HTML::ISA = qw(SVN::Notify); __PACKAGE__->register_attributes( linkize => 'linkize', css_url => 'css-url=s', wrap_log => 'wrap-log', css_inline => 'css-inline', ); =head1 Name SVN::Notify::HTML - Subversion activity HTML notification =head1 Synopsis Use F<svnnotify> in F<post-commit>: svnnotify --repos-path "$1" --revision "$2" \ --to developers@example.com --handler HTML [options] Use the class in a custom script: use SVN::Notify::HTML; my $notifier = SVN::Notify::HTML->new(%params); $notifier->prepare; $notifier->execute; =head1 Description This subclass of L<SVN::Notify|SVN::Notify> sends HTML formatted email messages for Subversion activity, rather than the default plain text. =head1 Prerequisites In addition to the modules required by SVN::Notify, this class requires: =over =item HTML::Entities =back =head1 Usage To use SVN::Notify::HTML, simply follow the L<instructions|SVN::Notify/Usage> in SVN::Notify, but when using F<svnnotify>, specify C<--handler HTML>. =cut ############################################################################## =head1 Class Interface =head2 Constructor =head3 new my $notifier = SVN::Notify::HTML->new(%params); Constructs and returns a new SVN::Notify object. All parameters supported by SVN::Notity are supported here, but SVN::Notify::HTML supports a few additional parameters: =over =item linkize svnnotify --linkize A boolean attribute to specify whether or not to "linkize" the SVN log message--that is, to turn any URLs or email addresses in the log message into links. =item css_url svnnotify --css-url http://example.com/svnnotify.css URL for a CSS file that will can style the HTML output by SVN::Notify::HTML or its subclasses. Note that the URL will be added to the output via a C<< <link rel="stylesheet"> >> tag I<after> the CSS generated by SVN::Notify::HTML or its subclasses. What that means is that the CSS file specified by C<css_url> need not completely style the HTML, but simply override the default settings. This approach nicely takes advantage of the "cascading" abilities of CSS. =item ticket_map svnnotify --ticket-map '(BUG-(\d+))=http://bugs.example.com/?show=%s' This attribute is inherited from L<SVN::Notify|SVN::Notify>, but its semantics are slightly different: the regular expression passed as the regular expression used for the key should return I<two> matches instead of one: the text to link and the ticket ID itself. For example, '(BUG-(\d+))' will match "BUG-1234567", and "BUG-1234567" will be used for the link text, while "1234567" will be used to fill in the C<ticket_url> format string. The first set of parentheses capture the whole string, while the parentheses around C<\d+> match the number only. Also note that it is wise to use "\b" on either side of the regular expression to insure that you don't get spurious matches. So a better version would be '\b(BUG-(\d+))\b'. As a fallback, if your regular expression returns only a single match string, it will be used both for the link text and for the the ticket URL generated from C<ticket_url>. For example, '\bBUG-(\d+)\b' would make a link only of the number in 'BUG-1234567', as only the number has been captured by the regular expression. But two matches are of course recommended (and likely to work better, as well). You can use more complicated regular expressions if commit messages are likely to format ticket numbers in various ways. For example, this regular expression: \b\[?\s*(Ticket\s*#\s*(\d+))\s*\]?\b' Will match: String Matched Link Text Ticket Number --------------------|--------------------|--------------- [Ticket#1234] [Ticket#1234] 1234 [ Ticket # 1234 ] [ Ticket # 1234 ] 1234 Ticket #1234 Ticket #1234 1234 Ticket # 1234 Ticket #1234 1234 In any of these cases, you can see that the match is successful, properly creates the link text (simply using the text as typed in by the committer, and correctly extracts the ticket number for use in the URL. To learn more about the power of Regular expressions, I highly recommend _Mastering Regular Expressions, Second Edition_, by Jeffrey Friedl. =item wrap_log svnnotify --wrap-log A boolean attribute to specify whether or not to wrap the log message in the output HTML. By default, log messages are I<not> wrapped, on the assumption that they should appear exactly as typed. But if that's not the case, specify this option to wrap the log message. =item css_inline svnnotify --css-inline A boolean attribute to specify whether or not to put the css code inside the HTML tags. This is useful when sending the HTML output to a web based email such as gmail so it can still be able to be rendered nicely. If this option is enabled, the CSS defined in the css_url property will be ignored and will use the generated inline style. =back =cut ############################################################################## =head2 Class Methods =head3 content_type Returns the content type of the notification message, "text/html". Used to set the Content-Type header for the message. =cut sub content_type { 'text/html' } ############################################################################## =head1 Instance Interface =head2 Instance Methods =head3 start_html $notifier->start_html($file_handle); This method starts the HTML of the notification message. It outputs the opening C<< <html> >>, C<< <head> >>, and C<< <body> >> tags. Note that if the C<language> attribute is set to a value, it will be specified in the C<< <html> >> tag. All of the HTML will be passed to any "start_html" output filters. See L<Writing Output Filters|SVN::Notify/"Writing Output Filters"> for details on filters. =cut sub start_html { my ($self, $out) = @_; my $lang = $self->language; my $char = lc $self->encoding; my @html = ( qq{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"\n}, qq{"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\n}, qq{<html xmlns="http://www.w3.org/1999/xhtml"}, ($lang ? qq{ xml:lang="$lang"} : ()), qq{>\n<head><meta http-equiv="content-type" content="text/html; }, qq{charset=$char" />\n}, ( $self->{css_url} ? ( '<link rel="stylesheet" type="text/css" href="', encode_entities($self->{css_url}), qq{" />\n} ) : () ), '<title>', encode_entities($self->subject, '<>&"'), qq{</title>\n</head>\n<body>\n\n} ); print $out @{ $self->run_filters( start_html => \@html ) }; return $self; } ############################################################################## =head3 start_body This method starts the body of the HTML notification message. It first calls C<start_html()>, and then outputs the C<< <style> >> tag, calling C<output_css()> between them. It then outputs an opening C<< <div> >> tag. If the C<header> attribute is set, C<start_body()> outputs it between C<< <div> >> tags with the ID "header". Furthermore, if the header happens to start with the character "E<lt>", C<start_body()> assumes that it contains valid HTML and therefore will not escape it. If a "start_body" output filter has been specified, it will be passed the lines with the C<< <div> >> tag and the header. To filter the CSS, use a "css" filter, and to filter the declaration of the HTML document and its C<< <head> >> section, use a "start_html" filter. See L<Writing Output Filters|SVN::Notify/"Writing Output Filters"> for details on filters. =cut sub start_body { my ($self, $out) = @_; $self->start_html($out); print $out qq{<style type="text/css"><!--\n}; $self->output_css( $out ); print $out qq{--></style>\n}; my @html = ( $self->{css_inline} ? (qq{<div id="msg" style="color:black;">\n}) : (qq{<div id="msg">\n}) ); if (my $header = $self->header) { push @html, ( ( $self->{css_inline} ? '<div id="header" style="color: #fff; background: #636; border: 1px #300 solid; padding: 6px;font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; ">': '<div id="header">'), ( $header =~ /^</ ? $header : encode_entities($header, '<>&"') ), "</div>\n", ); } print $out @{ $self->run_filters( start_body => \@html ) }; return $self; } ############################################################################## =head3 output_css $notifier->output_css($file_handle); This method starts outputs the CSS for the HTML message. It is called by C<start_body()>, and which wraps the output of C<output_css()> in the appropriate C<< <style> >> tags. An output filter named "css" may be added to modify the output of CSS. The filter subroutine name should be C<css> and expect an array reference of lines of CSS. See L<Writing Output Filters|SVN::Notify/"Writing Output Filters"> for details on filters. =cut sub output_css { my ($self, $out) = @_; # We use _css() so that ColorDiff can override it and the filters then # applied only one to all of the CSS. print $out @{ $self->run_filters( css => $self->_css ) }; return $self; } ############################################################################## =head3 output_metadata $notifier->output_metadata($file_handle); This method outputs a definition list containing the meta data of the commit, including the revision number, author (user), and date of the revision. If the C<revision_url> attribute has been set, then the appropriate URL for the revision will be used to turn the revision number into a link. If there are any C<log_message> filters, this method will do no HTML formatting, but redispatch to L<SVN::Notify::output_metadata|SVN::Notify/"output_metadata">. See L<Writing Output Filters|SVN::Notify/"Writing Output Filters"> for details on filters. =cut sub output_metadata { my ($self, $out) = @_; if ( $self->filters_for('metadata') ) { return $self->SUPER::output_metadata($out); } print $out ( $self->{css_inline} ? ( qq{<dl class="meta" style="border: 1px #006 solid; background: #369; padding: 6px; color: #fff; font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;">\n}, qq{<dt style="float: left; width: 6em; font-weight: bold;font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;">Revision:</dt> <dd>} ) : qq{<dl class="meta">\n<dt>Revision</dt> <dd>}); my $rev = $self->revision; if (my $url = $self->revision_url) { $url = encode_entities($url, '<>&"'); # Make the revision number a URL. printf $out ( $self->{css_inline} ? qq{<a style="color: white;font-weight: bold;" href="$url">$rev</a>} : qq{<a href="$url">$rev</a>}), $rev; } else { # Just output the revision number. print $out $rev; } # Output the committer and a URL, if there is one. print $out ( $self->{css_inline} ? qq{</dd>\n<dt style="float: left; width: 6em; font-weight: bold;font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;">Author:</dt> <dd>} : "</dd>\n<dt>Author</dt> <dd>"); my $user = encode_entities($self->user, '<>&"'); if (my $url = $self->author_url) { $url = encode_entities($url, '<>&"'); printf $out ($self->{css_inline} ? qq{<a style="color: white;font-weight: bold" href="$url">$user</a>} : qq{<a href="$url">$user</a>}), $user; } else { # Just output the username print $out $user; } print $out ( "</dd>\n", ($self->{css_inline} ? qq{<dt style="float: left; width: 6em; font-weight: bold;font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;">Date:</dt> <dd>} : '<dt>Date</dt> <dd>'), encode_entities($self->date, '<>&"'), "</dd>\n", "</dl>\n\n" ); return $self; } ############################################################################## =head3 output_log_message $notifier->output_log_message($file_handle); Outputs the commit log message in C<< <pre> >> tags, and the label "Log Message" in C<< <h3> >> tags. If the C<bugzilla_url> attribute is set, then any strings like "Bug 2" or "bug # 567" will be turned into links. If there are any C<log_message> filters, the filters will be assumed to escape the HTML, create inline links, and link ticket URLs. Otherwise, this method will do those things. See L<Writing Output Filters|SVN::Notify/"Writing Output Filters"> for details on filters. =cut sub output_log_message { my ($self, $out) = @_; $self->_dbpnt( "Outputting log message as HTML") if $self->verbose > 1; # Assemble the message. my $filters = $self->filters_for('log_message'); my $msg = $filters ? join( "\n", @{ $self->run_filters( log_message => [ @{ $self->message } ] ) } ) : encode_entities( join( "\n", @{ $self->message } ), '<>&"'); # Turn URLs and email addresses into links. if ($self->linkize) { # These regular expressions modified from "Mastering Regular # Expressions" 2ed., pp 70-75. # Make email links. $msg =~ s{\b(\w[-.\w]*\@[-a-z0-9]+(?:\.[-a-z0-9]+)*\.[-a-z0-9]+)\b} {<a href="mailto:$1">$1</a>}gi; # Make URLs linkable. $msg =~ s{\b([a-z0-9]+://[-a-z0-9]+(?:\.[-a-z0-9]+)*\.[-a-z0-9]+\b(?:/(?:[-a-z0-9_:\@?=+,.!/~*I'%\$]|&amp;)*(?<![.,?!]))?)} {<a href="$1">$1</a>}gi; } # Make Revision links. if (my $url = $self->revision_url) { $url = encode_entities($url, '<>&"'); $msg =~ s{\b((?:rev(?:ision)?\s*#?\s*|r)(\d+))\b}{sprintf qq{<a href="$url">$1</a>}, $2}ige; } # Make ticketing system links. if (my $map = $self->ticket_map) { $self->run_ticket_map ( sub { my ($regex, $url) = @_; $url = encode_entities($url, '<>&"'); $msg =~ s{$regex}{ sprintf qq{<a href="$url">$1</a>}, $2 || $1 }ige; }); } print $out "<h3>Log Message</h3>\n"; if ($filters || $self->wrap_log) { $msg = ($self->{css_inline} ? '<p style="margin: 0 0 1em 0;line-height: 14pt;">' . join( "</p>\n\n<p style=\"margin: 0 0 1em 0;line-height: 14pt;\">", split /\n\s*\n/, $msg ) . '</p>' : '<p>' . join( "</p>\n\n<p>", split /\n\s*\n/, $msg ) . '</p>') if !$filters && $self->wrap_log; print $out ( ($self->{css_inline} ? qq{<div id="logmsg" style="background: #ffc; border: 1px #fa0 solid; padding: 0 1em 0 1em; font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;">\n} : qq{<div id="logmsg">\n}), $msg, qq{</div>\n\n}, ) } else { print $out ($self->{css_inline} ? qq{<pre style="overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px;">$msg</pre>\n\n} : "<pre>$msg</pre>\n\n"); } return $self; } ############################################################################## =head3 output_file_lists $notifier->output_log_message($file_handle); Outputs the lists of modified, added, deleted, files, as well as the list of files for which properties were changed as unordered lists. The labels used for each group are pulled in from the C<file_label_map()> class method and output in C<< <h3> >> tags. If there are any C<file_lists> filters, this method will do no HTML formatting, but redispatch to L<SVN::Notify::output_file_lists|SVN::Notify/"output_file_lists">. See L<Writing Output Filters|SVN::Notify/"Writing Output Filters"> for details on filters. =cut sub output_file_lists { my ($self, $out) = @_; my $files = $self->files or return $self; if ( $self->filters_for('file_lists') ) { return $self->SUPER::output_file_lists($out); } my $map = $self->file_label_map; # Create the lines that will go underneath the above in the message. my %dash = ( map { $_ => '-' x length($map->{$_}) } keys %$map ); foreach my $type (qw(U A D _)) { # Skip it if there's nothing to report. next unless $files->{$type}; # Identify the action and output each file. print $out "<h3>$map->{$type}</h3>\n<ul>\n"; if ($self->with_diff && !$self->attach_diff) { for (@{ $files->{$type} }) { my $file = encode_entities($_, '<>&"'); if ($file =~ m{/$} && $type ne '_') { # Directories don't link, unless it's a prop change. print $out qq{<li>$file</li>\n}; } else { # Strip out letters illegal for IDs. (my $id = $file) =~ s/[^\w_]//g; print $out qq{<li><a href="#$id">$file</a></li>\n}; } } } else { print $out " <li>", encode_entities($_, '<>&"'), "</li>\n" for @{ $files->{$type} }; } print $out "</ul>\n\n"; } } ############################################################################## =head3 end_body $notifier->end_body($file_handle); Closes out the body of the email by outputting the closing C<< </body> >> and C<< </html> >> tags. Designed to be called when the body of the message is complete, and before any call to C<output_attached_diff()>. If the C<footer> attribute is set, C<end_body()> outputs it between C<< <div> >> tags with the ID "footer". Furthermore, if the footer happens to end with the character "E<lt>", C<end_body()> assumes that it contains valid HTML and therefore will not escape it. All of the HTML will be passed to any "end_body" output filters. See L<Writing Output Filters|SVN::Notify/"Writing Output Filters"> for details on filters. =cut sub end_body { my ($self, $out) = @_; $self->_dbpnt( "Ending body") if $self->verbose > 2; my @html; if (my $footer = $self->footer) { push @html, ( ($self->{css_inline} ? '<div id="footer" style="color: #fff; background: #636; border: 1px #300 solid; padding: 6px;font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; ">' : '<div id="footer">'), ( $footer =~ /^</ ? $footer : encode_entities($footer, '<>&"') ), "</div>\n", ); } push @html, "\n</div>" unless $self->with_diff && !$self->attach_diff; push @html, "\n</body>\n</html>\n"; print $out @{ $self->run_filters( end_body => \@html ) }; return $self; } ############################################################################## =head3 output_diff $notifier->output_diff($out_file_handle, $diff_file_handle); Sends the output of C<svnlook diff> to the specified file handle for inclusion in the notification message. The diff is output between C<< <pre> >> tags, and Each line of the diff file is escaped by C<HTML::Entities::encode_entities()>. The diff data will be read from C<$diff_file_handle> and printed to C<$out_file_handle>. If there are any C<diff> filters, this method will do no HTML formatting, but redispatch to L<SVN::Notify::output_diff|SVN::Notify/"output_diff">. See L<Writing Output Filters|SVN::Notify/"Writing Output Filters"> for details on filters. =cut sub output_diff { my ($self, $out, $diff) = @_; if ( $self->filters_for('diff') ) { return $self->SUPER::output_diff($out, $diff); } $self->_dbpnt( "Outputting HTML diff") if $self->verbose > 1; print $out qq{</div>\n<div id="patch"><pre>\n}; my ($length, %seen) = 0; my $max = $self->max_diff_length; while (<$diff>) { if (!$max || ($length += length) < $max) { s/[\n\r]+$//; if (/^(Modified|Added|Deleted|Copied|Property changes on): (.*)/ && !$seen{$2}++) { my $action = $1; my $file = encode_entities($2, '<>&"'); (my $id = $file) =~ s/[^\w_]//g; print $out qq{<a id="$id">$action: $file</a>\n}; } else { print $out ( encode_entities($_, '<>&"'), "\n" ); } } else { print $out "\n\@\@ Diff output truncated at $max characters. \@\@\n"; last; } } print $out "</pre></div>\n"; close $diff or warn "Child process exited: $?\n"; return $self; } ############################################################################## =head2 Accessors In addition to those supported by L<SVN::Notify|SVN::Notify/Accessors>, SVN::Notify::HTML supports the following accessors: =head3 linkize my $linkize = $notifier->linkize; $notifier = $notifier->linkize($linkize); Gets or sets the value of the C<linkize> attribute. =head3 css_url my $css_url = $notifier->css_url; $notifier = $notifier->css_url($css_url); Gets or sets the value of the C<css_url> attribute. =head3 css_inline my $css_inline = $notifier->css_inline; $notifier = $notifier->css_inline($css_inline); Gets or sets the value of the C<css_inline> attribute. =cut ############################################################################## sub _css { return [ q(#msg dl.meta { border: 1px #006 solid; background: #369; ), qq(padding: 6px; color: #fff; }\n), qq(#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }\n), qq(#msg dt:after { content:':';}\n), q(#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: ), qq(verdana,arial,helvetica,sans-serif; font-size: 10pt; }\n), qq(#msg dl a { font-weight: bold}\n), qq(#msg dl a:link { color:#fc3; }\n), qq(#msg dl a:active { color:#ff0; }\n), qq(#msg dl a:visited { color:#cc6; }\n), q(h3 { font-family: verdana,arial,helvetica,sans-serif; ), qq(font-size: 10pt; font-weight: bold; }\n), q(#msg pre { overflow: auto; background: #ffc; ), qq(border: 1px #fa0 solid; padding: 6px; }\n), qq(#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }\n), qq(#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }\n), qq(#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }\n), qq(#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }\n), qq(#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }\n), qq{#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }\n}, qq{#logmsg ul { text-indent: -1em; padding-left: 1em; }}, qq{#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }\n}, qq(#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }\n), qq(#logmsg pre { background: #eee; padding: 1em; }\n), qq(#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}\n), qq(#logmsg dl { margin: 0; }\n), qq(#logmsg dt { font-weight: bold; }\n), qq(#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }\n), qq(#logmsg dd:before { content:'\\00bb';}\n), qq(#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }\n), qq(#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }\n), qq(#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }\n), qq(#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }\n), qq(#logmsg table th.Corner { text-align: left; }\n), qq(#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }\n), q(#header, #footer { color: #fff; background: #636; ), qq(border: 1px #300 solid; padding: 6px; }\n), qq(#patch { width: 100%; }\n), ]; } 1; __END__ =head1 See Also =over =item L<SVN::Notify|SVN::Notify> =back =head1 Author David E. Wheeler <david@kineticode.com> =head1 Copyright and License Copyright (c) 2004-2008 Kineticode, Inc. Some Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut
Subject: ColorDiff.pm
package SVN::Notify::HTML::ColorDiff; # $Id: ColorDiff.pm 4332 2008-09-24 04:33:22Z david $ use strict; use HTML::Entities; use SVN::Notify::HTML (); $SVN::Notify::HTML::ColorDiff::VERSION = '2.79'; @SVN::Notify::HTML::ColorDiff::ISA = qw(SVN::Notify::HTML); =head1 Name SVN::Notify::HTML::ColorDiff - Subversion activity HTML notification with colorized diff =head1 Synopsis Use F<svnnotify> in F<post-commit>: svnnotify --repos-path "$1" --revision "$2" \ --to developers@example.com --handler HTML::ColorDiff [options] Use the class in a custom script: use SVN::Notify::HTML::ColorDiff; my $notifier = SVN::Notify::HTML::ColorDiff->new(%params); $notifier->prepare; $notifier->execute; =head1 Description This subclass of L<SVN::Notify::HTML|SVN::Notify::HTML> sends HTML formatted email messages for Subversion activity, and if the C<with_diff> parameter is specified (but not C<attach_diff>), then a pretty colorized version of the diff will be included, rather than the plain text diff output by SVN::Notify::HTML. =head1 Usage To use SVN::Notify::HTML::ColorDiff, simply follow the L<instructions|SVN::Notify/Usage> in SVN::Notify, but when using F<svnnotify>, specify C<--handler HTML::ColorDiff>. =cut ############################################################################## =head1 Instance Interface =head2 Instance Methods =head3 output_css $notifier->output_css($file_handle); This method starts outputs the CSS for the HTML message. SVN::Notify::HTML::ColorDiff adds extra CSS to its output so that it can nicely style the diff. =cut # We use _css() so that ColorDiff can override it and the filters then applied # only one to all of the CSS. ############################################################################## =head3 output_diff $notifier->output_diff($out_file_handle, $diff_file_handle); Reads the diff data from C<$diff_file_handle> and prints it to C<$out_file_handle> for inclusion in the notification message. The diff is output with nice colorized HTML markup. Each line of the diff file is escaped by C<HTML::Entities::encode_entities()>. If there are any C<diff> filters, this method will do no HTML formatting, but redispatch to L<SVN::Notify::output_diff|SVN::Notify/"output_diff">. See L<Writing Output Filters|SVN::Notify/"Writing Output Filters"> for details on filters. =cut my %types = ( Modified => 'modfile', Added => 'addfile', Deleted => 'delfile', Copied => 'copfile', ); sub output_diff { my ($self, $out, $diff) = @_; if ( $self->filters_for('diff') ) { return $self->SUPER::output_diff($out, $diff); } $self->_dbpnt( "Outputting colorized HTML diff") if $self->verbose > 1; my $in_div; my $in_span = ''; print $out qq{</div>\n<div id="patch">\n<h3>Diff</h3>\n}; my ($length, %seen) = 0; my $max = $self->max_diff_length; while (my $line = <$diff>) { $line =~ s/[\n\r]+$//; next unless $line; if ( $max && ( $length += length $line ) >= $max ) { print $out "</$in_span>" if $in_span; print $out ($self->css_inline ? qq{<span class="lines" style="display:block;padding:0 10px;color:#888;background:#fff;">\@\@ Diff output truncated at $max characters. \@\@\n</span>} : qq{<span class="lines">\@\@ Diff output truncated at $max characters. \@\@\n</span>}); $in_span = ''; last; } else { if ($line =~ /^(Modified|Added|Deleted|Copied): (.*)/) { my $class = $types{my $action = $1}; ++$seen{$2}; my $file = encode_entities($2, '<>&"'); (my $id = $file) =~ s/[^\w_]//g; print $out "</$in_span>" if $in_span; print $out "</span></pre></div>\n" if $in_div; # Dump line, but check it's content. if (<$diff> !~ /^=/) { # Looks like they used --no-diff-added or --no-diff-deleted. ($in_span, $in_div) = ''; print $out ($self->css_inline ? ( qq{<a id="$id"></a>\n<div class="$class" style="border:1px solid #ccc;margin:10px 0;">}, qq{<h4 style="font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;">$action: $file</h4></div>\n}) : (qq{<a id="$id"></a>\n<div class="$class">}, qq{<h4>$action: $file</h4></div>\n})); next; } # Get the revision numbers. my $before = <$diff>; $before =~ s/[\n\r]+$//; if ($before =~ /^\(Binary files differ\)/) { # Just output the whole file div. print $out ($self->css_inline ? ( qq{<a id="$id"></a>\n<div class="binary" style="border:1px solid #ccc;margin:10px 0;"><h4 style="font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;">}, qq{$action: $file</h4>\n}, qq{<pre class="diff" style="color:black;padding:0;line-height:1.2em;margin:0;width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;font-family:'Andale Mono','Courier New',monospace;font-size:9pt;">}, qq{<span style="display:block;padding:0 10px;">\n}, qq{<span style="display:block;padding:0 10px;">$before\n</span></span></pre></div>\n}): ( qq{<a id="$id"></a>\n<div class="binary"><h4>}, qq{$action: $file</h4>\n<pre class="diff"><span>\n}, qq{<span class="cx">$before\n</span></span></pre></div>\n})) ; ($in_span, $in_div) = ''; next; } my ($rev1) = $before =~ /\(rev (\d+)\)$/; my $after = <$diff>; $after =~ s/[\n\r]+$//; my ($rev2) = $after =~ /\(rev (\d+)\)$/; # Output the headers. print $out ($self->css_inline ? ( qq{<a id="$id"></a>\n<div class="$class" style="border:1px solid #ccc;margin:10px 0;">}, qq{<h4 style="font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;">$action: $file}, " ($rev1 => $rev2)</h4>\n") : ( qq{<a id="$id"></a>\n<div class="$class"><h4>$action: $file}, " ($rev1 => $rev2)</h4>\n" )); print $out ($self->css_inline ? ( qq{<pre class="diff" style="color:black;padding:0;line-height:1.2em;margin:0;width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;font-family:'Andale Mono','Courier New',monospace;font-size:9pt;">}, qq{<span style="display:block;padding:0 10px;">\n<span class="info" style="display:block;padding:0 10px;color:#888;background:#fff;">}) : qq{<pre class="diff"><span>\n<span class="info">}) ; $in_div = 1; print $out encode_entities($_, '<>&"'), "\n" for ($before, $after); print $out "</span>"; $in_span = ''; } elsif ($line =~ /^Property changes on: (.*)/ && !$seen{$1}) { # It's just property changes. my $file = encode_entities($1, '<>&"'); (my $id = $file) =~ s/[^\w_]//g; # Dump line. <$diff>; # Output the headers. print $out "</$in_span>" if $in_span; print $out "</span></pre></div>\n" if $in_div; print $out ($self->css_inline ? ( qq{<a id="$id"></a>\n<div class="propset" style="border:1px solid #ccc;margin:10px 0;">}, qq{<h4 style="font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;">}, qq{Property changes: $file</h4>\n}, qq{<pre class="diff" style="color:black;padding:0;line-height:1.2em;margin:0;width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;font-family:'Andale Mono','Courier New',monospace;font-size:9pt;">}, qq{<span style="display:block;padding:0 10px;">\n}) : ( qq{<a id="$id"></a>\n<div class="propset">}, qq{<h4>Property changes: $file</h4>\n<pre class="diff"><span>\n})); $in_div = 1; $in_span = ''; } elsif ($line =~ /^\@\@/) { print $out "</$in_span>" if $in_span; print $out ( ($self->css_inline ? qq{<span class="lines" style="display:block;padding:0 10px;color:#888;background:#fff;">} : qq{<span class="lines">}), encode_entities($line, '<>&"'), "\n</span>", ); $in_span = ''; } elsif ($line =~ /^([-+])/) { my $type = $1 eq '+' ? 'ins' : 'del'; if ($in_span eq $type) { print $out encode_entities($line, '<>&"'), "\n"; } else { my $clr = $type eq 'ins' ? '#dfd' : '#fdd'; print $out "</$in_span>" if $in_span; print $out ( ($self->css_inline ? qq{<$type style="background-color:$clr;text-decoration:none;display:block;padding:0 10px;">} : qq{<$type>}), encode_entities($line, '<>&"'), "\n", ); $in_span = $type; } } else { if ($in_span eq 'cx') { print $out encode_entities($line, '<>&"'), "\n"; } else { print $out "</$in_span>" if $in_span; print $out ( ($self->css_inline ? qq{<span class="cx" style="display:block;padding:0 10px;">} : qq{<span class="cx">}), encode_entities($line, '<>&"'), "\n", ); $in_span = 'span'; } } } } print $out "</$in_span>" if $in_span; print $out "</span></pre>\n</div>\n" if $in_div; print $out "</div>\n"; close $diff or warn "Child process exited: $?\n"; return $self; } ############################################################################## sub _css { my $css = shift->SUPER::_css; push @$css, qq(#patch h4 {font-family: verdana,arial,helvetica,sans-serif;), qq(font-size:10pt;padding:8px;background:#369;color:#fff;), qq(margin:0;}\n), qq(#patch .propset h4, #patch .binary h4 {margin:0;}\n), qq(#patch pre {padding:0;line-height:1.2em;margin:0;}\n), qq(#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;), qq(overflow:auto;}\n), qq(#patch .propset .diff, #patch .binary .diff {padding:10px 0;}\n), qq(#patch span {display:block;padding:0 10px;}\n), qq(#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, ), qq(#patch .binary, #patch .copfile {border:1px solid #ccc;), qq(margin:10px 0;}\n), qq(#patch ins {background:#dfd;text-decoration:none;display:block;), qq(padding:0 10px;}\n), qq(#patch del {background:#fdd;text-decoration:none;display:block;), qq(padding:0 10px;}\n), qq(#patch .lines, .info {color:#888;background:#fff;}\n); return $css; } 1; __END__ =head1 See Also =over =item L<SVN::Notify|SVN::Notify> =item L<SVN::Notify::HTML|SVN::Notify::HTML> =item CVSspam: L<http://www.badgers-in-foil.co.uk/projects/cvsspam/> =back =head1 To Do =over =item * Add inline emphasis just on the text that changed between two lines, like this: L<http://www.badgers-in-foil.co.uk/projects/cvsspam/example.html>. =item * Add links to To Do stuff to the top of the email, as pulled in from the diff. This might be tricky, since the diff is currently output I<after> the message body. Maybe use absolute positioning CSS? =back =head1 =head1 Author David E. Wheeler <david@kineticode.com> =head1 Copyright and License Copyright (c) 2004-2008 Kineticode, Inc. Some Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut
From: Stephen J. Fuhry
Are there any plans to integrate this patch into a future release? I would love to have this feature, but I'd rather not patch up my production server if it will be implemented in a future release anyways.
Subject: Re: [rt.cpan.org #52121] HTML output with CSS inline
Date: Fri, 14 Jan 2011 10:42:49 -0800
To: bug-SVN-Notify@rt.cpan.org
From: "David E. Wheeler" <david@kineticode.com>
On Dec 16, 2010, at 3:57 PM, https://www.google.com/accounts/o8/id?id=AItOawnpGfTTHA19URX26usctWK3ag2xyoaTiPs via RT wrote:
Show quoted text
> Queue: SVN-Notify > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=52121 > > > Are there any plans to integrate this patch into a future release? > > I would love to have this feature, but I'd rather not patch up my > production server if it will be implemented in a future release anyways.
I hadn't planned to, no, because it could pretty easily be implemented as a filter. http://p3rl.org/SVN::Notify::Filter That said, if it makes the display better in Web mail clients, perhaps we should instead just always change it to be inline CSS. Do we really need two different ways of formatting things? I think I'd rather have it all be done in one way. Care to take a stab at implementing that? Patch based on https://svn.kineticode.com/SVN-Notify/trunk Thanks, David
On Fri Jan 14 13:42:57 2011, david@kineticode.com wrote:
Show quoted text
> > Are there any plans to integrate this patch into a future release? > > > > I would love to have this feature, but I'd rather not patch up my > > production server if it will be implemented in a future release
> anyways. > > I hadn't planned to, no, because it could pretty easily be implemented > as a filter. > > http://p3rl.org/SVN::Notify::Filter > > That said, if it makes the display better in Web mail clients, perhaps > we should instead just always change it to be inline CSS. Do we > really need two different ways of formatting things? I think I'd > rather have it all be done in one way. > > Care to take a stab at implementing that? Patch based on > > https://svn.kineticode.com/SVN-Notify/trunk
Now moved here: https://github.com/theory/svn-notify/ Best, David


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.