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

Revision 1432 (checked in by charsbar, 14 years ago)

remove $VERSION from several plugins

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 package Plagger::Plugin::Publish::PowerPoint;
2
3 use strict;
4 use base qw( Plagger::Plugin );
5
6 use Win32::PowerPoint;
7 use Encode;
8 use File::Path;
9
10 sub register {
11     my($self, $context) = @_;
12     $context->register_hook(
13         $self,
14         'publish.init' => \&connect_powerpoint,
15         'publish.feed' => \&publish_presentation,
16     );
17 }
18
19 sub publish_presentation {
20     my ($self, $context, $args) = @_;
21
22     my $feed = $args->{feed};
23
24     $self->{powerpoint}->new_presentation;
25
26     foreach my $entry ($feed->entries) {
27
28         my $title_text = $entry->title_text;
29         my $body_text  = $entry->body_text;
30
31         $title_text =~ s/^\s+//mg;
32         $body_text  =~ s/^\s+//mg;
33
34         $self->{powerpoint}->new_slide;
35         $self->{powerpoint}->add_text(
36             encode('shift_jis',$title_text),
37             { size => 30, bold => 1, height => 50, link => $entry->permalink },
38         );
39         $self->{powerpoint}->add_text(
40             encode('shift_jis',$body_text),
41             { size => 20 },
42         );
43     }
44
45     # generate file path;
46     my $file = File::Spec->catfile(
47         $self->conf->{dir}, $self->gen_filename($feed)
48     );
49
50     $context->log(info => "save feed for " . $feed->link . " to $file");
51
52     $self->{powerpoint}->save_presentation($file);
53     $self->{powerpoint}->close_presentation;
54 }
55
56 sub connect_powerpoint {
57     my ($self, $context, $args) = @_;
58
59     my $dir = $self->conf->{dir} || '.';
60     unless (-e $dir && -d _) {
61         $context->log(debug => "make dir");
62         mkpath($dir, 0755) or $context->error("mkdir $dir: $!");
63     }
64
65     $context->log(debug => "hello, PowerPoint");
66     $self->{powerpoint} = Win32::PowerPoint->new;
67 }
68
69 # stolen from ::Publish::Feed
70
71 my %formats = (
72     'u' => sub { my $s = $_[0]->url;  $s =~ s!^https?://!!; $s },
73     'l' => sub { my $s = $_[0]->link; $s =~ s!^https?://!!; $s },
74     't' => sub { $_[0]->title },
75     'i' => sub { $_[0]->id },
76 );
77
78 my $format_re = qr/%(u|l|t|i)/;
79
80 sub gen_filename {
81     my($self, $feed) = @_;
82
83     my $file = $self->conf->{filename} || '%i.pps';
84     $file =~ s{$format_re}{
85         $self->safe_filename($formats{$1}->($feed))
86     }egx;
87     $file;
88 }
89
90 sub safe_filename {
91     my($self, $path) = @_;
92     $path =~ s![^\w\s]+!_!g;
93     $path =~ s!\s+!_!g;
94     $path;
95 }
96
97 1;
98
99 __END__
100
101 =head1
102
103 Plagger::Plugin::Publish::PowerPoint - publish as PowerPoint slide
104
105 =head1 SYNOPSYS
106
107   - module: Publish::PowerPoint
108     config:
109       dir: /home/foobar/plagger
110       filename: %l.pps
111
112 =head1 CONFIG
113
114 Accepts C<dir> and C<filename>. See ::Publish::Feed for details.
115
116 =head1 AUTHOR
117
118 Kenichi Ishigaki
119
120 =head1 SEE ALSO
121
122 C<Plagger>, C<Plagger::Plugin::Publish::Feed>, C<Win32::PowerPoint>
123
124 =cut
Note: See TracBrowser for help on using the browser.