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

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

added Publish::PowerPoint?

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