root/trunk/plagger/lib/Plagger/Plugin/Publish/PSP.pm

Revision 316 (checked in by miyagawa, 15 years ago)
  • Adding Publish::OPML
  • Added templatize method to $context
Line 
1 package Plagger::Plugin::Publish::PSP;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 our $VERSION = '0.10';
6
7 sub register {
8     my($self, $context) = @_;
9     $context->register_hook(
10         $self,
11         'publish.feed' => \&add_feed,
12         'publish.finalize' => \&finalize,
13     );
14 }
15
16 sub add_feed {
17     my($self, $context, $args) = @_;
18     push @{ $self->{__feeds} }, $args->{feed};
19 }
20
21
22 sub finalize {
23     my($self, $context) = @_;
24
25     my $body = $self->templatize($context, $self->{__feeds});
26     my $file = $self->conf->{output_file};
27
28     $context->log(info => "Output HTML to $file");
29     open my $out, ">:utf8", $file or $context->error("$file: $!");
30     print $out $body;
31     close $out;
32 }
33
34 sub templatize {
35     my($self, $context, $feeds) = @_;
36     my $tt = $context->template();
37     $tt->process('psp.tt', {
38         feeds => $feeds,
39     }, \my $out) or $context->error($tt->error);
40     $out;
41 }
42
43 1;
44
Note: See TracBrowser for help on using the browser.