| 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 . '.xul'; |
|---|
| 25 |
my $path = File::Spec->catfile($self->conf->{dir}, $file); |
|---|
| 26 |
$context->log(info => "writing output to $path"); |
|---|
| 27 |
|
|---|
| 28 |
my $body = $context->templatize($self, '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; |
|---|