Changeset 95

Show
Ignore:
Timestamp:
01/22/07 14:38:39 (2 years ago)
Author:
ingy
Message:
Make doolittle work...
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/core/Kwiki/lib/Kwiki/Pages.pm

    r87 r95  
    2222sub all_ids_newest_first { 
    2323    my $path = $self->hub->config->database_directory; 
    24     if($^O eq "MSWin32") { 
    25         # ~30 times slower then `ls -lt` 
    26         # broken if $path is a symlink 
    27         my $io = io($path); 
    28         map {$_->filename} sort {$b->mtime <=> $a->mtime} $io->all; 
    29     } else { 
    30         map {chomp; $_} `ls -1t $path`; 
    31     } 
     24    grep { not(-d "$path/$_") } map {chomp; $_} `ls -1t $path`; 
    3225} 
    3326 
     
    184177# method is problematic 
    185178sub io { 
    186     Kwiki::io($self->file_path)->file; 
     179    my $r; 
     180    eval { 
     181        $r = Kwiki::io($self->file_path)->file; 
     182    }; 
     183    die "Problem ($@) " . $self->file_path if $@; 
     184    return $r; 
    187185} 
    188186 
  • trunk/src/core/Kwiki/src/doc/Kwiki.pod

    r66 r95  
    102102 
    103103See http://www.perl.com/perl/misc/Artistic.html 
    104  
    105 =cut 
    106  
  • trunk/src/plugins/ingy/Kwiki-Doolittle/lib/Kwiki/Doolittle.pm

    r87 r95  
    11package Kwiki::Doolittle; 
    22use Kwiki::Plugin -Base; 
    3 use Kwiki ':char_classes'; 
    4 use mixin 'Kwiki::Installer'; 
    53 
    64const class_id => 'doolittle'; 
     
    86sub register { 
    97    my $registry = shift; 
    10     $registry->add(action => 'doolittle_index'); 
    11     $registry->add(command => 'doolittle_build_index', 
    12                    description => 'Rebuild document index',); 
    13     $registry->add(hook => 'cgi:set_default_page_name', 
    14                    pre => 'page_name_hook'); 
    15     $registry->add(hook => 'pages:all', post => 'pages_all'); 
    16     $registry->add(hook => 'page:load_content', post => 'load_content'); 
    17     $registry->add(hook => 'archive:fetch', post => 'archive_fetch'); 
    18     $registry->add(hook => 'archive:commit', pre => 'archive_pre_commit'); 
    19     $registry->add(hook => 'archive:commit', post => 'archive_post_commit'); 
    20     $registry->add(hook => 'page:store_content', pre => 'store_content'); 
    21     $registry->add(hook => 'hub:action', post => 'action'); 
     8    $registry->add( preload => 'doolittle' ); 
    229} 
    2310 
    24 sub action { 
    25     my $hook = pop; 
    26     ($self->cgi->action || $self->cgi->page_name) 
    27     ? $hook->returned 
    28     : 'doolittle_index'; 
     11use Kwiki::CGI; 
     12package Kwiki::CGI; 
     13use Kwiki ':char_classes'; 
     14no warnings 'redefine'; 
     15sub set_default_page_name { 
     16    my $page_name = shift; 
     17    $page_name = '' if $page_name and $page_name =~ /[^$ALPHANUM\-]/; 
     18    $page_name ||= $self->hub->config->main_page; 
    2919} 
    30  
    31 sub doolittle_index { 
    32     $self->template->process($self->screen_template, 
    33         content_pane => 'doolittle_content.html'); 
    34 } 
    35  
    36 sub pages_all { 
    37     my $hook = pop; 
    38     grep { 
    39         -l "database/" . $_->id and $_->id ne '.index' 
    40     } $hook->returned; 
    41 } 
    42  
    43 sub handle_doolittle_build_index { 
    44     my $index = io->catfile($self->config->database_directory, ".index"); 
    45     for my $source_file ($index->chomp->getlines) { 
    46         next if $source_file =~ /^(#|\s*$)/; 
    47         next unless -f $source_file; 
    48         unless ($self->extract_pod(io($source_file)->all)) { 
    49             warn "No pod for $source_file\n"; 
    50             next; 
    51         } 
    52         my ($module) = $source_file =~ /.*\/lib\/(.*)$/; 
    53         $module =~ s/\//-/g; 
    54         $module =~ s/\.pm$//; 
    55         my $link_file = $self->config->database_directory . "/$module"; 
    56         next if -e $link_file; 
    57         symlink($source_file, $link_file) 
    58           or die "Can't make symlink for $link_file\n:$!"; 
    59     } 
    60 } 
    61  
    62 sub page_name_hook { 
    63     my $hook = pop; 
    64     $hook->cancel; 
    65     return shift || ''; 
    66 } 
    67  
    68 sub extract_pod { 
    69     my $content = shift; 
    70     return $content; 
    71     $content =~ /.*\n__DATA__\n(?:.*?\n)?(=\w+.*?)(?:\n=cut|\z)(?:.*)\z/s 
    72       or return; 
    73     return $1; 
    74      
    75 } 
    76  
    77 sub store_pod { 
    78     die "FIXME"; 
    79     my ($content, $pod) = @_; 
    80     $content =~ 
    81       s/(.*\n__DATA__\n(?:.*?\n)?)(=\w+.*?)((?:\n=cut|\z)(?:.*)\z)/$1$pod$3/s 
    82         or die; 
    83     return $content; 
    84 } 
    85  
    86 sub archive_pre_commit { 
    87     my $page = shift; 
    88     my $hook = pop; 
    89     my $page_source = readlink($page->file_path) 
    90       or die $!; 
    91     $page->{page_source} = $page_source; 
    92 } 
    93  
    94 sub archive_post_commit { 
    95     my $page = shift; 
    96     my $hook = pop; 
    97     my $link = $page->file_path; 
    98     my $page_source = $page->{page_source}; 
    99     unlink $link 
    100       or die $!; 
    101     symlink($page_source, $link); 
    102 } 
    103  
    104 sub archive_fetch { 
    105     my $hook = pop; 
    106     my $content = $hook->returned; 
    107  
    108     my $local = $self->hub->doolittle; 
    109     my $pod = $local->extract_pod($content) 
    110      or die; 
    111     return $pod; 
    112 } 
    113  
    114 sub load_content { 
    115     my $content = $self->content; 
    116     my $page_name = $self->id; 
    117     my $local = $self->hub->doolittle; 
    118  
    119     my $pod = $local->extract_pod($content) 
    120      or die $local->invalid_doolittle_page($page_name); 
    121     $self->content($pod); 
    122     return $self; 
    123 } 
    124  
    125 sub store_content { 
    126     die "FIXME"; 
    127     my $hook = pop; 
    128     $hook->cancel; 
    129     my $local = $self->hub->doolittle; 
    130     my $file = io($self->file_path)->utf8; 
    131     my $old_content = $file->all; 
    132     my $pod = $self->content; 
    133     if ($pod) { 
    134         $pod =~ s/\r//g; 
    135         $pod =~ s/\n*\z/\n/; 
    136     } 
    137     my $content = $local->store_pod($old_content, $pod); 
    138     unless ($self->force) { 
    139         return if $file->exists and  
    140                   $content eq $old_content; 
    141     } 
    142     $file->print($content); 
    143     return $self; 
    144 } 
    145  
    146 sub invalid_doolittle_page { 
    147     my $name = shift; 
    148     die "Invalid Doolittle source for page '$name'"; 
    149 } 
    150  
    151 __DATA__ 
    152  
    153  
    154 __template/tt2/doolittle_content.html__ 
    155 <h1>Welcome to Doolittle</h1> 
    156 <ul> 
    157 [% FOR page = hub.pages.all %] 
    158 <li>[% page.kwiki_link %]</li> 
    159 [% END %] 
    160 </ul> 
  • trunk/src/plugins/modules.mk

    r94 r95  
    77        Kwiki/DB \ 
    88        Kwiki/Diff \ 
     9        Kwiki/Doolittle \ 
    910        Kwiki/Edit \ 
    1011        Kwiki/Formatter \ 
     
    210211        Kwiki/Ajax/Toolman.pm \ 
    211212        Kwiki/Archive/Rcs.pm \ 
     213        Kwiki/Doolittle/Formatter.pm \ 
    212214        Kwiki/Formatter/Pod.pm \ 
    213215        Kwiki/Pages/Perldoc.pm \