概要: Plagger::Plugin::Publish::Template を改造した。
自分で作った Plagger::Plugin::Publish::Template /post/50888701357 の feed メソッドを改造して テンプレート変数をいじれるようにした。
で、編集内容。
sub feed { my($self, $context, $args) = @_; my $file = Plagger::Util::filename_for($args->{feed}, $self->conf->{filename} || '%i.txt'); my $path = File::Spec->catfile($self->conf->{dir}, $file); $context->log(info => "writing output to $path"); # 変数の展開 my $variables = { feed => $args->{'feed'} }; my $vars = $self->conf->{'variable'} || {}; for my $key ( keys %{ $vars } ) { my $result = eval $vars->{$key}; if ( $@ ) { $context->error( $@ ); } else { $variables->{$key} = $result; } } my $body = $self->templatize( $self->conf->{'template'} , $variables ); open my $out, ">:utf8", $path or $context->error("$path: $!"); print $out $body; close $out; } plugins: - module: Publish::Template rule: expression: require Plagger::Date; 1; config: template: template.tt filename: output.txt dir: /path/to/output/dir variable: now: Plagger::Date->now conf: $self->conf
こんな感じで設定で変数をいじれるようにした。 で、変数をいじるのに必要なモジュールは Rule::Expression で読み込めばいいと思う。
Windows で diff どうやってとったらいいかよく分からないというか調べるのが面倒なので、 変更箇所をそのままアップしてみる。
開発環境整えないとまずいな。
追記
明らかに変なコード書いてたので修正。