Changeset 23

Show
Ignore:
Timestamp:
02/05/06 11:40:36
Author:
sekimura
Message:

fixed a bug overwriting the exiting output_file

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/Publish/PSP.pm

    r19 r23  
    99    $context->register_hook( 
    1010        $self, 
    11         'publish.notify' => \&notify, 
     11        'publish.notify'   => \&notify, 
     12        'publish.finalize' => \&finalize, 
    1213    ); 
    1314} 
     
    1617    my($self, $context, $feed) = @_; 
    1718 
    18     my @items = $feed->entries; 
    19     $self->store_items_as_html($context, $feed, \@items); 
     19    $feed->{title} = $feed->{title} || '(no-title)'; 
     20    $context->log(warn => "Store $feed->{title}"); 
     21    push @{ $self->{__feeds} }, $feed; 
    2022} 
    2123 
    22 sub store_items_as_html { 
    23     my($self, $context, $feed, $items) = @_; 
    24     $feed->{title} = $feed->{title} || '(no-title)'; 
    25     my $body =  $self->templatize($context, $feed, $items); 
    26     $self->do_store_item($context, $feed, $body); 
    27 } 
    2824 
    29 sub do_store_item
    30     my($self, $context, $feed, $body) = @_; 
     25sub finalize
     26    my($self, $context) = @_; 
    3127 
     28    my $body= $self->templatize($context, $self->{__feeds}); 
    3229    my $cfg = $self->conf; 
    3330    my $file= $cfg->{output_file}; 
    34     $context->log(warn => "Store $feed->{title} to $file"); 
    3531 
    3632    open(FH, ">:utf8", $file) or die $!; 
     
    4036 
    4137sub templatize { 
    42     my($self, $context, $feed, $items) = @_; 
     38    my($self, $context, $feeds) = @_; 
    4339    my $tt = $context->template(); 
    44     $tt->process('psp_notify.tt', { 
    45         feed => $feed, 
    46         items => $items, 
    47         cfg  => $self->conf, 
     40    $tt->process('psp.tt', { 
     41        feeds => $feeds, 
    4842        utf8 => sub { encode("utf-8", $_[0]) } 
    4943    }, \my $out) or die $tt->error;