Changeset 1618

Show
Ignore:
Timestamp:
08/29/06 01:37:43
Author:
miyagawa
Message:

factored out Plagger::Util::summarize to Summarize::Simple default plugin

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/hackathon-summary/plagger/lib/Plagger.pm

    r1551 r1618  
    293293    } 
    294294    $self->autoload_plugin({ module => 'Summary::Auto' }); 
     295    $self->autoload_plugin({ module => 'Summary::Simple' }); 
    295296 
    296297    for my $feed ($self->subscription->feeds) { 
  • branches/hackathon-summary/plagger/lib/Plagger/Plugin/Summary/Auto.pm

    r1556 r1618  
    2323            text  => $args->{entry}->body, 
    2424        }); 
    25  
    26         unless (defined $summary) { 
    27             $summary = Plagger::Util::summarize($args->{entry}->body); 
    28         } 
    29         $args->{entry}->summary($summary); 
     25        $args->{entry}->summary($summary) if defined $summary; 
    3026    } 
    3127} 
  • branches/hackathon-summary/plagger/lib/Plagger/Util.pm

    r1607 r1618  
    22use strict; 
    33our @ISA = qw(Exporter); 
    4 our @EXPORT_OK = qw( strip_html dumbnail decode_content extract_title load_uri mime_type_of filename_for summarize ); 
     4our @EXPORT_OK = qw( strip_html dumbnail decode_content extract_title load_uri mime_type_of filename_for ); 
    55 
    66use Encode (); 
     
    208208} 
    209209 
    210 sub summarize { 
    211     my($text) = @_; 
    212     $text = Plagger::Text->new_from_text($text) unless ref $text; 
    213  
    214     if ($text->is_html) { 
    215         # HTML: grab first block paragraph, or until first <br /> 
    216         my $html = $text->data; 
    217         if ($html =~ m|^\s*<(\w*)\s*[^>]*>(.*?)</\1>|s && $HTML::Tagset::isBodyElement{lc($1)}) { 
    218             return "<$1>$2</$1>"; 
    219         } elsif ($html =~ m!^(.*?)<br\s*/?>!s) { 
    220             return $1; 
    221         } else { 
    222             return $html; 
    223         } 
    224     } else { 
    225         # text: substring with 255 bytes 
    226         if (length($text) > 255) { 
    227             return substr($text, 0, 255) . "..."; 
    228         } else { 
    229             return $text; 
    230         } 
    231     } 
    232 } 
    233  
    2342101;