Permalink
Browse files

Fix formatting

  • Loading branch information...
1 parent 3ec073d commit faf71a030efc3db5506aefc0111df5de17fbc44b Lee committed Apr 28, 2009
Showing with 20 additions and 14 deletions.
  1. +2 −3 lib/App/Colloqueer.pm
  2. +6 −11 lib/App/Colloqueer/IRC/Formatting.pm
  3. +3 −0 script/colloqueer
  4. +7 −0 t/01_bold.t
  5. +2 −0 t/bold
View
@@ -248,9 +248,6 @@ sub format_messages {
msgs => \@msgs,
self => $from eq $self->server->{nick} ? 1 : 0,
}, \(my $message)) or die $!;
- open my $log, '>>', $ENV{HOME}."/irc.txt";
- print $log "$message\n\n";
- close $log;
my $doc = $self->xml->parse_string($message,{encoding => 'utf8'});
my $results = $self->style_xsl->transform($doc,
XML::LibXSLT::xpath_to_string(
@@ -262,6 +259,7 @@ sub format_messages {
$message =~ s/<span[^\/>]*\/>//gi; # strip empty spans
$message =~ s/'/\\'/g;
$message =~ s/\n//g;
+ print STDERR "$message\n";
return decode_utf8($message);
}
@@ -270,6 +268,7 @@ sub format_event {
$self->tt->process('event.xml', {
event => $event
}, \(my $xml)) or die $!;
+ print STDERR "$xml\n\n";
my $doc = $self->xml->parse_string($xml,{encoding => 'utf8'});
my $results = $self->style_xsl->transform($doc,
XML::LibXSLT::xpath_to_string(
@@ -3,6 +3,7 @@ package App::Colloqueer::IRC::Formatting;
use List::MoreUtils qw/natatime/;
use Moose;
use HTML::Entities;
+ use Data::Dumper;
use feature qw/:5.10/;
@@ -22,7 +23,7 @@ my $FORMAT_SEQUENCE = qr/(
| $UNDERLINE)
/x;
-my @COLORS = ( qw/fff 000 008 080 ff0 800 808 f80
+my @COLORS = ( qw/fff 000 008 080 f00 800 808 f80
ff0 0f0 088 0ff 00f f0f 888 ccc/ );
has 'b' => (
@@ -55,13 +56,7 @@ has 'bg' => (
sub dup {
my $self = shift;
- return App::Colloqueer::IRC::Formatting->new(
- b => $self->b,
- i => $self->i,
- u => $self->u,
- fg => $self->fg,
- bg => $self->bg,
- )
+ return bless { %$self }, ref $self;
}
sub reset {
@@ -137,7 +132,7 @@ sub formatted_string_to_html {
my @formatted_line = parse_formatted_string($_);
my $line;
for (@formatted_line) {
- $line .= '<span style="'.$_->[0]->to_css.'">'.encode_entities($_->[1], '<>&"').'</span>';
+ $line .= '<span style="'.$_->[0]->to_css.'">'.encode_entities($_->[1] || '', '<>&"').'</span>';
}
push @lines, $line;
}
@@ -150,8 +145,8 @@ sub parse_formatted_string {
my $it = natatime 2, ("", split(/$FORMAT_SEQUENCE/, $line));
my $formatting = App::Colloqueer::IRC::Formatting->new;
while (my ($format_sequence, $text) = $it->()) {
- $formatting = $formatting->accumulate($format_sequence);
- push @segments, [ $formatting, $text];
+ my $new_formatting = $formatting->accumulate($format_sequence);
+ push @segments, [ $new_formatting, $text];
}
return @segments;
}
View
@@ -40,6 +40,9 @@ sub irc_public {
if (! $channel) {
$channel = $heap->{app}->add_channel($where->[0]);
}
+ open my $log, '>>', $ENV{HOME}."/irc.txt";
+ print $log "$what\n\n";
+ close $log;
my $msg = App::Colloqueer::Message->new(
nick => $nick,
hostmask => $who,
View
@@ -0,0 +1,7 @@
+use Test::More tests => 2;
+
+use_ok('App::Colloqueer::IRC::Formatting');
+open my $irctext, '<', 't/bold';
+my $html = '<span style="">not bold </span><span style="font-weight: bold">bold </span><span style="">not bold</span>';
+my $output = App::Colloqueer::IRC::Formatting->formatted_string_to_html(<$irctext>);
+ok($output eq $html, 'bolded HTML');
View
2 t/bold
@@ -0,0 +1,2 @@
+not bold bold not bold
+

0 comments on commit faf71a0

Please sign in to comment.