| 1 |
package Plagger::Plugin::Publish::Takahashi; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use base qw( Plagger::Plugin ); |
|---|
| 4 |
|
|---|
| 5 |
use File::Copy; |
|---|
| 6 |
|
|---|
| 7 |
sub register { |
|---|
| 8 |
my($self, $context) = @_; |
|---|
| 9 |
$context->register_hook( |
|---|
| 10 |
$self, |
|---|
| 11 |
'publish.feed' => \&feed, |
|---|
| 12 |
'publish.finalize' => \&finalize, |
|---|
| 13 |
); |
|---|
| 14 |
|
|---|
| 15 |
my $dir = $self->conf->{dir}; |
|---|
| 16 |
unless (-e $dir && -d _) { |
|---|
| 17 |
mkdir $dir, 0755 or $context->error("mkdir $dir: $!"); |
|---|
| 18 |
} |
|---|
| 19 |
} |
|---|
| 20 |
|
|---|
| 21 |
sub feed { |
|---|
| 22 |
my($self, $context, $args) = @_; |
|---|
| 23 |
|
|---|
| 24 |
my $file = $args->{feed}->id_safe . '.xul'; |
|---|
| 25 |
my $path = File::Spec->catfile($self->conf->{dir}, $file); |
|---|
| 26 |
$context->log(info => "writing output to $path"); |
|---|
| 27 |
|
|---|
| 28 |
my $body = $self->templatize('takahashi.tt', $args); |
|---|
| 29 |
open my $out, ">:utf8", $path or $context->error("$path: $!"); |
|---|
| 30 |
print $out $body; |
|---|
| 31 |
close $out; |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
sub finalize { |
|---|
| 35 |
my($self, $context, $args) = @_; |
|---|
| 36 |
|
|---|
| 37 |
for my $file (qw( takahashi.js takahashi.css )) { |
|---|
| 38 |
my $js_path = File::Spec->catfile($self->conf->{dir}, $file); |
|---|
| 39 |
copy( File::Spec->catfile($self->assets_dir, $file), $js_path ); |
|---|
| 40 |
} |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
1; |
|---|
| 44 |
|
|---|
| 45 |
=head1 NAME |
|---|
| 46 |
|
|---|
| 47 |
Plagger::Plugin::Publish::Takahashi - produce takahashi output |
|---|
| 48 |
|
|---|
| 49 |
=head1 SYNOPSIS |
|---|
| 50 |
|
|---|
| 51 |
- module: Publish::Takahashi |
|---|
| 52 |
config: |
|---|
| 53 |
dir: /home/miyagawa/takahashi |
|---|
| 54 |
|
|---|
| 55 |
=head1 DESCRIPTION |
|---|
| 56 |
|
|---|
| 57 |
This module creates a Takahashi style presentation in .xul for |
|---|
| 58 |
each feed. |
|---|
| 59 |
|
|---|
| 60 |
The one configuration option is the directory you want the |
|---|
| 61 |
presentation to be created in. A $feedid.xul file will be |
|---|
| 62 |
created for each feed, and the two support takahashi |
|---|
| 63 |
javascript and css support files will be copied into |
|---|
| 64 |
the directory. |
|---|
| 65 |
|
|---|
| 66 |
=head1 AUTHOR |
|---|
| 67 |
|
|---|
| 68 |
Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt> |
|---|
| 69 |
|
|---|
| 70 |
See I<AUTHORS> file for the name of all the contributors. |
|---|
| 71 |
|
|---|
| 72 |
=head1 LICENSE |
|---|
| 73 |
|
|---|
| 74 |
Except where otherwise noted, Plagger is free software; you can |
|---|
| 75 |
redistribute it and/or modify it under the same terms as Perl itself. |
|---|
| 76 |
|
|---|
| 77 |
=head1 SEE ALSO |
|---|
| 78 |
|
|---|
| 79 |
L<http://plagger.org/>, |
|---|
| 80 |
L<http://www.bright-green.com/blog/2005_12_15/a_cute_mozilla_xul_app.html> |
|---|
| 81 |
|
|---|
| 82 |
=cut |
|---|
| 83 |
|
|---|