Changeset 934

Show
Ignore:
Timestamp:
06/08/06 22:39:27
Author:
miyagawa
Message:

Publish::JavaScript?: code tweak and docs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/Publish/JavaScript.pm

    r104 r934  
    1414} 
    1515 
     16sub init { 
     17    my $self = shift; 
     18    $self->SUPER::init(@_); 
     19 
     20    my $dir = $self->conf->{dir}; 
     21    unless (-e $dir && -d _) { 
     22        mkdir $dir, 0755 or Plagger->context->error("mkdir $dir: $!"); 
     23    } 
     24} 
     25 
    1626sub feed { 
    1727    my($self, $context, $args) = @_; 
    1828 
    19     my $dir = $self->conf->{dir}; 
    20     unless (-e $dir && -d _) { 
    21         mkdir $dir, 0755 or $context->error("mkdir $dir: $!"); 
    22     } 
    23  
    24     my $file = $self->gen_filename($args->{feed}); 
    25     my $path = File::Spec->catfile($dir, $file); 
     29    my $file = $self->gen_filename($args->{feed}, $self->conf->{filename} || '%i.js'); 
     30    my $path = File::Spec->catfile($self->conf->{dir}, $file); 
    2631    $context->log(info => "writing output to $path"); 
    2732 
     
    4348 
    4449sub gen_filename { 
    45     my($self, $feed) = @_; 
     50    my($self, $feed, $file) = @_; 
    4651 
    47     my $file = $self->conf->{filename}; 
    4852    $file =~ s{$format_re}{ 
    4953        $self->safe_filename($formats{$1}->($feed)) 
     
    7074 
    71751; 
     76 
     77__END__ 
     78 
     79=head1 NAME 
     80 
     81Plagger::Plugin::Publish::JavaScript - publish links to entries as JavaScript 
     82 
     83=head1 SYNOPSIS 
     84 
     85  - module: Publish::JavaScript 
     86    config: 
     87      dir: /path/to/www/js 
     88      filename: %t.js 
     89 
     90=head1 DESCRIPTION 
     91 
     92This plugin publishes links to feed entries as an HTML embedable 
     93JavaScript file. The JS file contains document.write() calls, and can 
     94be easily included in any HTML page using: 
     95 
     96  <script src="/path/to/file.js"></script> 
     97 
     98in any place, like Blog sidebar widgets. 
     99 
     100The HTML emitted by the JavaScript code has exactly the same structure 
     101with Movable Type's standard sidebar module, so you can easily style 
     102using CSS. 
     103 
     104=head1 CONFIG 
     105 
     106=over 4 
     107 
     108=item dir 
     109 
     110Directory to save JS files in. 
     111 
     112=item filename 
     113 
     114Filename to be used to create JS files. It defaults to C<%i.js>, but 
     115could be configured using the following formats like strftime: 
     116 
     117=over 8 
     118 
     119=item * %u url 
     120 
     121=item * %l link 
     122 
     123=item * %t title 
     124 
     125=item * %i id 
     126 
     127=back 
     128 
     129=back 
     130 
     131=head1 AUTHOR 
     132 
     133Tatsuhiko Miyagawa 
     134 
     135=head1 SEE ALSO 
     136 
     137L<Plagger>, L<Plagger::Plugin::Publish::MTWidget> 
     138 
     139=cut