# Blosxom Plugin: cvsignore -*- perl -*- # Author: David O'Callaghan # Version: 0+1i # Blosxom Home/Docs/Licensing: http://www.raelity.org/blosxom # cvsignore plugin Home/Docs/Licensing: (not yet) package cvsignore; # --- Configuration Variables --- $cvsignore_filename = ".cvsignore"; $debug_level ||= 0; # ------------------------------------------------------------ use FileHandle; use File::Find; use File::stat; use CGI qw/:standard :netscape/; my $package = "cvsignore"; sub debug { my ($level, @msg) = @_; if ($debug_level >= $level) { print STDERR "$package debug $level: @msg\n"; } } sub start { debug(1, "start() called, enabled"); return 1; } sub entries { return sub { my(%files, %indexes); find({wanted => \&wanted, preprocess => \&preprocess}, $blosxom::datadir); sub wanted{ my $d; my $curr_depth = $File::Find::dir =~ tr[/][]; return if $depth and $curr_depth > $depth; $File::Find::name =~ m!^$blosxom::datadir/(?:(.*)/)?(.+)\.$blosxom::file_extension$! and $2 ne 'index' and $2 !~ /^\./ and (-r $File::Find::name) and $files{$File::Find::name} = stat($File::Find::name)->mtime and ( param('-all') or !-T "$blosxom::static_dir/$1/index." . $blosxom::static_flavours[0] or stat("$blosxom::static_dir/$1/index." . $blosxom::static_flavours[0])->mtime < stat($File::Find::name)->mtime ) and $indexes{$1} = 1 and $d = join('/', (blosxom::nice_date($files{$File::Find::name}))[5,2,3]) and $indexes{$d} = $d and $blosxom::static_entries and $indexes{ ($1 ? "$1/" : '') . "$2.$blosxom::file_extension" } = 1; } sub preprocess{ my (@files) = @_; debug(2, "preprocess() called,", scalar(@files), "files"); if(-f "$File::Find::dir/$cvsignore_filename"){ debug(1, "preprocess() found $cvsignore_filename in", $File::Find::dir); my %cvsignorelist = read_cvsignore("$File::Find::dir/$cvsignore_filename"); foreach $file (@files){ if($cvsignorelist{$file}){ debug(1, "preprocess() excluding $file"); $file = ""; } } } debug(2, "preprocess() exiting"); return @files; } sub read_cvsignore{ my ($fn) = @_; debug(2, "read_cvsignore($fn)"); my %cvsignorelist = {}; $fh = new FileHandle; if ($fh->open("$fn")) { while($_ = <$fh>){ chomp($_); $cvsignorelist{$_} = 1; debug(2, "read_cvsignore read: '$_'"); } $fh->close; } return %cvsignorelist; } return (\%files, \%indexes); }; } 1; __DATA__ __END__ =head1 NAME Blosxom Plug-in: cvsignore =head1 SYNOPSIS Purpose: ignores files and directories using standard .cvsignore files. This file does not make any new variables available for use in template files. =head1 VERSION 0+1i 1st test release =head1 AUTHOR David O'Callaghan http://www.cs.tcd.ie/David.OCallaghan/ =head1 BUGS Of course. =head1 Customization =head2 Configuration variables C<$cvsignore_filename> name to use for cvsignore files. Defaults to C<.cvsignore>. =head1 LICENSE this Blosxom Plug-in Copyright 2003, David O'Callaghan (This license is the same as Blosxom's) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.