Show
Ignore:
Timestamp:
05/27/08 21:39:28 (6 months ago)
Author:
tokuhirom
Message:

- make formatter.
- remove creating stuff from core
- added controllers.

Location:
lang/perl/App-Chariot/trunk
Files:
7 added
4 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/App-Chariot/trunk/assets/tmpl/item-parts.tt

    r12554 r12556  
    1                     [% USE Markdown %] 
    2  
    31                    <div class="entry"> 
    42                        <h3 class="entry-header"><a href="[% item.permalink %]">[% item.title %]</a></h3> 
    5                         <div class="entry-content"><div class="entry-body">[% FILTER markdown %][% item.content %][% END %]</div></div> 
     3                        <div class="entry-content"><div class="entry-body">[% format(item.content) %]</div></div> 
    64                        <div class="entry-footer"> 
    75                            <span class="post-footers">[% item.entry.header.date %]</span> 
  • lang/perl/App-Chariot/trunk/config.yaml

    r12554 r12556  
    33css_filename: http://bulknews.typepad.com/test/styles.css 
    44clog_url: ./ 
     5formatter: Hatena 
  • lang/perl/App-Chariot/trunk/lib/App/Chariot.pm

    r12554 r12556  
    1111use XML::RSS; 
    1212use Scalar::Util; 
     13use Module::Find; 
     14my @CONTROLLERS = useall 'App::Chariot::C'; 
    1315 
    1416do { 
     
    4143}; 
    4244 
    43 sub say { print "@_\n" } 
    44  
    4545has dat => ( 
    4646    is => 'rw', 
     
    6161            } 
    6262        ); 
     63    }, 
     64); 
     65 
     66has formatter => ( 
     67    is      => 'ro', 
     68    isa     => 'CodeRef', 
     69    lazy    => 1, 
     70    default => sub { 
     71        my $self      = shift; 
     72        my $formatter = $self->config->formatter; 
     73        $formatter = "App::Chariot::Formatter::$formatter"; 
     74        Class::MOP::load_class($formatter); 
     75        $formatter->meta->get_method('format')->body; 
    6376    }, 
    6477); 
     
    101114sub create { 
    102115    my $self = shift; 
    103     $self->create_index_page(); 
    104     $self->create_rss(); 
    105     $self->create_permalink_pages(); 
    106 } 
    107116 
    108 sub create_dir { 
    109     my $self = shift; 
    110     say "create dir"; 
     117    print "create dir\n"; 
    111118    mkdir $self->config->output_dir; 
    112 } 
    113  
    114 sub create_permalink_pages { 
    115     my ($self, ) = @_; 
    116  
    117     say "create permalink pages"; 
    118     my $ifile = File::Spec->catfile($self->config->assets_dir, 'tmpl', 'item.tt'); 
    119     for my $entry (@{$self->dat->list}) { 
    120         my $cnt = 1; 
    121         for my $item (reverse @{$entry->items->list}) { 
    122             $item->count($cnt); 
    123             $item->entry( $entry ); 
    124             my $ofile = File::Spec->catfile($self->config->output_dir, $item->permalink); 
    125             $self->render( 
    126                 $ifile => $ofile, 
    127                 { 
    128                     item  => $item, 
    129                 }, 
    130             ); 
    131  
    132             $cnt++; 
    133         } 
     119    for my $controller (@CONTROLLERS) { 
     120        $controller->meta->get_method('create')->body->( $self ); 
    134121    } 
    135 } 
    136  
    137 sub create_index_page { 
    138     my ($self, ) = @_; 
    139  
    140     say "create index page"; 
    141     my @list = reverse @{$self->dat->list}; 
    142     my $ifile = File::Spec->catfile($self->config->assets_dir, 'tmpl', 'index.tt'); 
    143     my $ofile = File::Spec->catfile($self->config->output_dir, 'index.html'); 
    144  
    145     $self->render( 
    146         $ifile => $ofile, { 
    147             entries => [ @list[0..($self->config->index_stop)] ], 
    148         } 
    149     ); 
    150 } 
    151  
    152 sub create_rss { 
    153     my $self = shift; 
    154  
    155     say "create rss"; 
    156  
    157     my $ofname = File::Spec->catfile( $self->config->output_dir, $self->config->rss_filename ); 
    158  
    159     my $rss = XML::RSS->new(version => '1.0'); 
    160     $rss->channel( 
    161         title        => $self->config->title, 
    162         link         => $self->config->clog_url, 
    163         description  => $self->config->changelog_description, 
    164     ); 
    165  
    166     my @list = reverse @{$self->dat->list}; 
    167     for my $entry (@list[0..($self->config->index_stop)]) { 
    168         my $cnt = 1; 
    169         for my $item (reverse @{$entry->items->list}) { 
    170             $item->count($cnt); 
    171             $item->entry( $entry ); 
    172  
    173             $rss->add_item( 
    174                 title       => $item->title, 
    175                 link        => $self->config->clog_url . $item->permalink, 
    176                 description => $item->content, 
    177                 content => { 
    178                     encoded => $item->content, 
    179                 }, 
    180             ); 
    181  
    182             $cnt++; 
    183         } 
    184     } 
    185     say "-- save to $ofname"; 
    186     $rss->save($ofname); 
    187122} 
    188123 
     
    190125    my ($self, $ifile, $ofile, $params) = @_; 
    191126 
    192     say "-- render $ifile => $ofile"; 
     127    print "-- render $ifile => $ofile\n"; 
    193128    $self->tt->process( 
    194129        $ifile, 
    195130        { 
    196             conf    => $self->config, 
     131            conf      => $self->config, 
     132            format    => $self->formatter, 
    197133            %$params, 
    198134        }, 
  • lang/perl/App-Chariot/trunk/lib/App/Chariot/Config.pm

    r12554 r12556  
    5858); 
    5959 
     60has formatter => ( 
     61    is      => 'ro', 
     62    isa     => 'Str', 
     63    default => 'Markdown', 
     64); 
     65 
    60661;