| 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.feed' => \&publish_presentation, |
|---|
| 15 |
'publish.init' => \&connect_powerpoint, |
|---|
| 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 |
|
|---|
| 46 |
my $file = File::Spec->catfile( |
|---|
| 47 |
$self->conf->{dir}, Plagger::Util::filename_for($feed, $self->conf->{filename} || '%i.pps'), |
|---|
| 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 |
1; |
|---|
| 70 |
|
|---|
| 71 |
__END__ |
|---|
| 72 |
|
|---|
| 73 |
=head1 |
|---|
| 74 |
|
|---|
| 75 |
Plagger::Plugin::Publish::PowerPoint - publish as PowerPoint slide |
|---|
| 76 |
|
|---|
| 77 |
=head1 SYNOPSIS |
|---|
| 78 |
|
|---|
| 79 |
- module: Publish::PowerPoint |
|---|
| 80 |
config: |
|---|
| 81 |
dir: /home/foobar/plagger |
|---|
| 82 |
filename: %l.pps |
|---|
| 83 |
|
|---|
| 84 |
=head1 CONFIG |
|---|
| 85 |
|
|---|
| 86 |
Accepts C<dir> and C<filename>. See ::Publish::Feed for details. |
|---|
| 87 |
|
|---|
| 88 |
=head1 AUTHOR |
|---|
| 89 |
|
|---|
| 90 |
Kenichi Ishigaki |
|---|
| 91 |
|
|---|
| 92 |
=head1 SEE ALSO |
|---|
| 93 |
|
|---|
| 94 |
C<Plagger>, C<Plagger::Plugin::Publish::Feed>, C<Win32::PowerPoint> |
|---|
| 95 |
|
|---|
| 96 |
=cut |
|---|