Changeset 1624

Show
Ignore:
Timestamp:
02/03/05 15:17:33 (4 years ago)
Author:
whmoseley
Message:

Fix generation of the docs table of contents.
Add Storable cache for the docs/index.html page
Make bin/build smarter about what needs to be built

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/swish_website/Plugin/My/POD.pm

    r1616 r1624  
    55use base 'Template::Plugin'; 
    66 
    7 use vars '@pod_toc'; 
    8  
    97my %split_by = map {"head".$_ => 1} 1..4; 
    108 
     
    1210 
    1311# *Much* of this is based on (or copied from) Stas' DocSet 0.17 
     12# This takes a pod file and uses Pod::POM to split it into sections, builds a table 
     13# of contents and generates the HTML. 
     14# 
     15# Will also cache the page's OVERVIEW 
     16#  
    1417# I'm not sure why spaces need to be removed from links.  Pod::POM doesn't remove them. 
     18# Escaping of links and hrefs and name tags needs to be checked.  There was just a discussion 
     19# on the TT list about escaping hrefs.  Then the xhtml validation rejected % and spaces, 
     20# so no replace all non-word chars with an underscore. 
     21# 
     22# Todo: 
     23#   might be nice to cache links to make sure there's no duplicates 
     24#   and also need a way to cross validate links (but can use an external link checker) 
    1525 
    1626sub new { 
    1727    my ( $class, $context, $content ) = @_; 
    1828 
    19     # How's this for a hack? 
    20     return \@pod_toc if $content eq 'toc'; 
    2129 
    2230    # Grab pod index variable 
    2331    my $stash = $context->stash; 
    24     my $page = $stash->get( ['page', 0, 'id', 0 ] ); 
    25  
    26     my $parser = Pod::POM->new( warn => 0 );  # Need to fetch template.name for warnings 
    27  
     32    my $page = $stash->get( 'page.id' ); 
     33    my $template_name = $stash->get( 'template.name' ); 
     34 
     35    my $warn = sub { warn "[$template_name]: @_\n" }; 
     36    # $warn = 0;  # disable warnings 
     37 
     38    my $parser = Pod::POM->new( warn => $warn );    # Make this a coderef to report name 
    2839    my $pom = $parser->parse_text( $content ); 
    2940 
    30     combine_verbatim_sections_hack( $pom ); 
    31  
    32     my @sections = $pom->head1;  # get pod into sections 
    33  
    34     my %data = ( pom => $pom ); 
     41    combine_verbatim_sections_hack( $pom );     # merge sequential <pre> sections into one 
     42 
     43 
     44    my @sections = $pom->head1;                 # get pod into sections 
     45 
     46 
     47    # Structure for returning info to template 
     48 
     49    my %data = ( 
     50        pom         => $pom , 
     51        view        => 'My::Pod::View::HTML', 
     52        sections    => \@sections, 
     53        podparts    => [ slice_by_head(@sections) ], 
     54        toc         => fetch_toc( \@sections ), 
     55    ); 
    3556 
    3657 
     
    4162    } 
    4263 
    43     $data{sections} = \@sections; 
    44  
    45     $data{podparts} = [ slice_by_head(@sections) ]; 
    46  
    47     $data{toc} = fetch_toc( \@sections ); 
    48  
    49  
    50     # Look for an overview 
    51  
    52     push @pod_toc, { 
    53         page    => $page, 
    54         title   => $data{title}, 
    55         abstract => fetch_abstract( $data{sections} ), 
     64 
     65    # Cache this page and overview for creating a table of contents page 
     66    # the bin/build script passes in the hash reference 
     67 
     68    if ( my $cache = $stash->get( 'toc_cache' ) ) { 
     69        $cache->{ $template_name } = { 
     70            page    => $page, 
     71            title   => $data{title}, 
     72            abstract => fetch_abstract( $data{sections} ), 
     73        }; 
    5674    }; 
    5775 
    5876 
    59     $data{view} = 'My::Pod::View::HTML'; 
    60  
    61  
    6277    return \%data; 
    6378} 
     79 
     80 
     81 
     82#----------------------------------------------------------------------------- 
    6483 
    6584sub slice_by_head { 
  • trunk/swish_website/bin/build

    r1611 r1624  
    44use FindBin '$Bin'; 
    55 
     6 
    67#======================================================================= 
    78# Sat Jan  8 06:56:06 PST 2005 - moseley 
     
    1011# script written by Peter Karman.  Peter made it look to simple, so 
    1112# I rewrote it to make it much more complex. 
     13# 
     14# The script exits true (zero) if ANY files are processed. 
     15# 
     16# Maintains a cache of table of contents from the pod files so that 
     17# only changes need to be updated (docs/index.html knows when to get generated) 
    1218# 
    1319# This roughly follows the examples in the Badger book, chapter 11. 
     
    1824#   might be off in time 
    1925# 
     26#   Currenly, the download dirs are defined in lib/config/site. 
     27#   Means can't easily check to see if those pages need to be updated. 
     28#   Since they don't change often, just do a -all run once a day (to catch 
     29#   the swish-daily updates). 
     30# 
    2031#   -src sucks as a name.  Is that the location of the source html files? 
    2132#   No, it's the top-level directory because it expects lib and src 
     
    2839# List of pod files relative to INCLUDE_PATH 
    2940# swish.css is needed for stand-alone html docs. 
     41 
     42 
     43use vars '$exit_value'; 
     44$exit_value = 1;  # no files processed yet. 
    3045 
    3146my @pod_files = qw( 
     
    133148    -ignore         = add regex of files to skip. 
    134149 
     150 
     151    Script exits false (1) if no files are actually processed. 
     152    Exits false even if -all -dryrun is used. 
     153    Exits true is at least one file was processed. 
    135154EOF 
    136     exit 1
     155    exit 2
    137156    }; 
    138157 
     
    176195 
    177196 
     197 
     198# Build everything here 
     199 
     200 
     201 
    178202my $generator = DocBuilder->new( $config ); 
    179203 
     
    186210 
    187211 
    188 exit
     212exit $exit_value
    189213 
    190214 
     
    207231use Template; 
    208232use Template::Constants qw( :debug ); 
     233use Storable;  # cache 
    209234 
    210235sub new { 
     
    356381# Start off using Peter's existing work.  Much easier that way... 
    357382#------------------------------------------------------------------------ 
     383# 
    358384 
    359385sub pods { 
    360386    my ( $self, $pod_files, $key ) = @_; 
    361387 
     388 
    362389    # Add source directory to INCLUDE_PATH 
    363390 
     
    367394    unshift @$include_path, $src_dir; 
    368395 
     396 
     397 
     398    # Fetch toc cache from disk 
     399    my $cache_file = File::Spec->catfile( $self->topdir, 'toc_cache.storable' ); 
     400    my $toc_cache; 
     401 
     402    eval { $toc_cache = retrieve( $cache_file ) }; 
     403    warn "Cache file [$cache_file] not found\n" if $@; 
     404    $toc_cache = {} unless ref $toc_cache eq 'HASH'; 
     405 
     406 
     407    # Create sub-cache for this source, if doesn't exist 
     408    # When processing a pod file the POD plugin will update its own cache entry 
     409    # in the hash. 
     410 
     411    my $this_toc_cache = $toc_cache->{$key} ||= {}; 
     412 
     413 
     414 
     415 
     416 
    369417    # set where the docs should be written 
    370418    my $out_prefix = $key eq 'swishsrc' ? 'docs' : 'devel/devel_docs'; 
     
    372420    my $version = $self->get_swish_version( $src_dir ); 
    373421 
     422 
     423    my $update_index = 0; 
     424 
    374425    for my $in_file ( @$pod_files ) { 
    375426 
    376427        my $out_file = basename( $in_file ); 
    377428 
    378         my $doc_type; 
    379  
    380         # Change pods to .html -- remove  
     429 
     430        # Change pods to .html 
     431 
     432        my $doc_type = ''; 
    381433        if ( $out_file =~ /\.(pod|pm|pl|cgi)/ ) { 
     434            $doc_type = 'pod'; 
    382435            ($out_file) = map { s/\.in$//; s/\.(pod|pm|pl)$//; lc($_).'.html' } ($out_file); 
    383             $doc_type = 'pod'; 
    384436        } 
     437 
     438        # Force processing of every pod if there's not cache entry for it. 
     439        # And force index.html if any pods were processed 
     440        # Note that '$in_file' ends up as template.name and is key used by POD plugin 
     441        my $all = $config->all || 0; 
     442        $config->{all} = 1 if $out_file eq 'index.html' && $update_index; 
     443        $config->{all} = 1 if $doc_type eq 'pod' && !$this_toc_cache->{$in_file}; 
     444 
    385445 
    386446        # Set destination directory 
     
    393453        my $vars = { 
    394454            this => { 
    395                 type    => $doc_type, 
    396                 page_id => basename( $out_file ), 
    397                 podfile => 1, 
    398                 abslinks => $abslinks, 
     455                type        => $doc_type, 
     456                page_id     => basename( $out_file ), 
     457                podfile     => 1, 
     458                abslinks    => $abslinks, 
    399459                swish_version => $version, 
    400460            }, 
    401             mode    => 0644, 
     461            mode        => 0644, 
     462            toc_cache   => $this_toc_cache,  # processing a pod updates this hash 
     463            pod_files   => $pod_files,       # this is used to generate the toc 
    402464        }; 
    403465 
    404         $self->process_file( $in_file, $out_file, $vars ); 
    405     } 
     466        my $processed = $self->process_file( $in_file, $out_file, $vars ); 
     467 
     468        $update_index++ if $doc_type eq 'pod' && $processed;  # need to update the index  
     469                                                # if any pod files processed 
     470                                                # might be better for POD plugin to set flag 
     471 
     472        $config->{all} = $all;  # reset (guess I need a set method) 
     473    } 
     474 
     475    # Write out cache 
     476    store $toc_cache, $cache_file; 
     477 
    406478 
    407479    shift @$include_path;  # remove source dir. 
     
    461533# generate_website() 
    462534#   Recurses $topsrc/src generating output to $dest 
    463 #   Time stamps are checked unless $config->all 
    464535#   output files match perms on input file 
    465536# 
     
    509580    $self->process_file( $_, $_ ) for @files; 
    510581 
    511     $self->website( $_ ) for @dirs; 
     582    $self->website( $_ ) for @dirs;  # Recurse 
    512583} 
    513584 
     
    519590#   $options  - hash ref of options to add to $vars 
    520591# 
     592# returns: 
     593#   true if processed the file (didn't skip for some reason) 
     594# 
    521595# Checks that input file is newer than output file 
    522596#------------------------------------------------------------------------- 
     
    550624        $self->logfile('Copy', $in_file, (stat $inpath)[7]); 
    551625        return if $self->config->dryrun; 
     626 
     627        $main::exit_value = 0; 
    552628 
    553629        copy( $inpath, $outpath ); 
     
    582658 
    583659    $self->logfile('Process', $in_file, length $capture || (stat $outpath)[7]); 
    584     return if $self->config->dryrun; 
     660    return 1 if $self->config->dryrun; 
     661 
     662    $main::exit_value = 0; 
    585663 
    586664    my $mode = $options->{mode} || ( stat $inpath)[2]; 
    587665 
    588666    chmod( $mode , $outpath ); 
     667 
     668    return 1;  # return true if processed a file 
    589669 
    590670} 
  • trunk/swish_website/lib/config/map

    r1614 r1624  
    182182        page    = { 
    183183            daily       = { 
    184                 name    = 'Swish-Daily' 
     184                name    = 'swish-daily' 
    185185                tooltip = 'Daily snapshots from CVS' 
    186186            } 
     
    192192 
    193193            cvs         = { 
    194                 name        = 'CVS info' 
     194                name        = 'cvs info' 
    195195                tooltip     = 'How to build Swish-e from CVS' 
    196196            } 
    197197 
    198198            view_cvs    = { 
    199                 name        = 'View CVS
     199                name        = 'view cvs
    200200                external    = 'http://cvs.sourceforge.net/viewcvs.py/swishe/' 
    201201                tooltip     = 'Go to the SourceForge.net Swish-e CVS Repository' 
     
    211211        page    = { 
    212212            old     = { 
    213                 name    = 'Archives' 
     213                name    = 'archives' 
    214214                tooltip = 'Previous versions' 
    215215            } 
    216216 
    217217            daily = { 
    218                 name    = 'Daily Builds' 
     218                name    = 'daily builds' 
    219219                tooltip = 'Daily packages from CVS' 
    220220                file    = 'devel/daily.html' 
  • trunk/swish_website/lib/pod_toc/index.html

    r1616 r1624  
    55%] 
    66 
    7 [% USE toc = POD('toc') %] 
    87 
    98<!-- noindex --> 
     
    1514 
    1615<ul class="toc"> 
    17 [% FOREACH item = toc %] 
     16[% FOREACH pod = pod_files %] 
     17 
     18    [% SET item = toc_cache.$pod %] 
     19    [% NEXT UNLESS item %] 
     20 
    1821    <li class="top-level"> 
    1922        <a href="[% item.page %]">[% item.title %]</a>