Changeset 1624
- Timestamp:
- 02/03/05 15:17:33 (4 years ago)
- Files:
-
- trunk/swish_website/Plugin/My/POD.pm (modified) (3 diffs)
- trunk/swish_website/bin/build (modified) (17 diffs)
- trunk/swish_website/lib/config/map (modified) (3 diffs)
- trunk/swish_website/lib/pod_toc/index.html (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/swish_website/Plugin/My/POD.pm
r1616 r1624 5 5 use base 'Template::Plugin'; 6 6 7 use vars '@pod_toc';8 9 7 my %split_by = map {"head".$_ => 1} 1..4; 10 8 … … 12 10 13 11 # *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 # 14 17 # 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) 15 25 16 26 sub new { 17 27 my ( $class, $context, $content ) = @_; 18 28 19 # How's this for a hack?20 return \@pod_toc if $content eq 'toc';21 29 22 30 # Grab pod index variable 23 31 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 28 39 my $pom = $parser->parse_text( $content ); 29 40 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 ); 35 56 36 57 … … 41 62 } 42 63 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 }; 56 74 }; 57 75 58 76 59 $data{view} = 'My::Pod::View::HTML';60 61 62 77 return \%data; 63 78 } 79 80 81 82 #----------------------------------------------------------------------------- 64 83 65 84 sub slice_by_head { trunk/swish_website/bin/build
r1611 r1624 4 4 use FindBin '$Bin'; 5 5 6 6 7 #======================================================================= 7 8 # Sat Jan 8 06:56:06 PST 2005 - moseley … … 10 11 # script written by Peter Karman. Peter made it look to simple, so 11 12 # 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) 12 18 # 13 19 # This roughly follows the examples in the Badger book, chapter 11. … … 18 24 # might be off in time 19 25 # 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 # 20 31 # -src sucks as a name. Is that the location of the source html files? 21 32 # No, it's the top-level directory because it expects lib and src … … 28 39 # List of pod files relative to INCLUDE_PATH 29 40 # swish.css is needed for stand-alone html docs. 41 42 43 use vars '$exit_value'; 44 $exit_value = 1; # no files processed yet. 30 45 31 46 my @pod_files = qw( … … 133 148 -ignore = add regex of files to skip. 134 149 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. 135 154 EOF 136 exit 1;155 exit 2; 137 156 }; 138 157 … … 176 195 177 196 197 198 # Build everything here 199 200 201 178 202 my $generator = DocBuilder->new( $config ); 179 203 … … 186 210 187 211 188 exit ;212 exit $exit_value; 189 213 190 214 … … 207 231 use Template; 208 232 use Template::Constants qw( :debug ); 233 use Storable; # cache 209 234 210 235 sub new { … … 356 381 # Start off using Peter's existing work. Much easier that way... 357 382 #------------------------------------------------------------------------ 383 # 358 384 359 385 sub pods { 360 386 my ( $self, $pod_files, $key ) = @_; 361 387 388 362 389 # Add source directory to INCLUDE_PATH 363 390 … … 367 394 unshift @$include_path, $src_dir; 368 395 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 369 417 # set where the docs should be written 370 418 my $out_prefix = $key eq 'swishsrc' ? 'docs' : 'devel/devel_docs'; … … 372 420 my $version = $self->get_swish_version( $src_dir ); 373 421 422 423 my $update_index = 0; 424 374 425 for my $in_file ( @$pod_files ) { 375 426 376 427 my $out_file = basename( $in_file ); 377 428 378 my $doc_type; 379 380 # Change pods to .html -- remove 429 430 # Change pods to .html 431 432 my $doc_type = ''; 381 433 if ( $out_file =~ /\.(pod|pm|pl|cgi)/ ) { 434 $doc_type = 'pod'; 382 435 ($out_file) = map { s/\.in$//; s/\.(pod|pm|pl)$//; lc($_).'.html' } ($out_file); 383 $doc_type = 'pod';384 436 } 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 385 445 386 446 # Set destination directory … … 393 453 my $vars = { 394 454 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, 399 459 swish_version => $version, 400 460 }, 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 402 464 }; 403 465 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 406 478 407 479 shift @$include_path; # remove source dir. … … 461 533 # generate_website() 462 534 # Recurses $topsrc/src generating output to $dest 463 # Time stamps are checked unless $config->all464 535 # output files match perms on input file 465 536 # … … 509 580 $self->process_file( $_, $_ ) for @files; 510 581 511 $self->website( $_ ) for @dirs; 582 $self->website( $_ ) for @dirs; # Recurse 512 583 } 513 584 … … 519 590 # $options - hash ref of options to add to $vars 520 591 # 592 # returns: 593 # true if processed the file (didn't skip for some reason) 594 # 521 595 # Checks that input file is newer than output file 522 596 #------------------------------------------------------------------------- … … 550 624 $self->logfile('Copy', $in_file, (stat $inpath)[7]); 551 625 return if $self->config->dryrun; 626 627 $main::exit_value = 0; 552 628 553 629 copy( $inpath, $outpath ); … … 582 658 583 659 $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; 585 663 586 664 my $mode = $options->{mode} || ( stat $inpath)[2]; 587 665 588 666 chmod( $mode , $outpath ); 667 668 return 1; # return true if processed a file 589 669 590 670 } trunk/swish_website/lib/config/map
r1614 r1624 182 182 page = { 183 183 daily = { 184 name = ' Swish-Daily'184 name = 'swish-daily' 185 185 tooltip = 'Daily snapshots from CVS' 186 186 } … … 192 192 193 193 cvs = { 194 name = ' CVSinfo'194 name = 'cvs info' 195 195 tooltip = 'How to build Swish-e from CVS' 196 196 } 197 197 198 198 view_cvs = { 199 name = ' View CVS'199 name = 'view cvs' 200 200 external = 'http://cvs.sourceforge.net/viewcvs.py/swishe/' 201 201 tooltip = 'Go to the SourceForge.net Swish-e CVS Repository' … … 211 211 page = { 212 212 old = { 213 name = ' Archives'213 name = 'archives' 214 214 tooltip = 'Previous versions' 215 215 } 216 216 217 217 daily = { 218 name = ' Daily Builds'218 name = 'daily builds' 219 219 tooltip = 'Daily packages from CVS' 220 220 file = 'devel/daily.html' trunk/swish_website/lib/pod_toc/index.html
r1616 r1624 5 5 %] 6 6 7 [% USE toc = POD('toc') %]8 7 9 8 <!-- noindex --> … … 15 14 16 15 <ul class="toc"> 17 [% FOREACH item = toc %] 16 [% FOREACH pod = pod_files %] 17 18 [% SET item = toc_cache.$pod %] 19 [% NEXT UNLESS item %] 20 18 21 <li class="top-level"> 19 22 <a href="[% item.page %]">[% item.title %]</a>
