ignore .git directorys
[grml.org.git] / gen_website
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Template;
7 use File::Find::Rule;
8 use File::Path qw(make_path);
9 use File::Basename qw (fileparse);
10 use File::Copy::Recursive qw(fcopy);
11 use File::Temp qw (tempdir);
12
13 my $out_dir = "out/";
14
15 #find all files
16
17 #rule to match git directorys
18 my $git = File::Find::Rule->directory
19                           ->name(".git")
20                           ->prune
21                           ->discard;
22
23 #matches all files
24 my $file_rule = File::Find::Rule->file();
25
26 #combine both
27 my @files = File::Find::Rule->or( $git, $file_rule )
28                             ->in('.');
29
30 #initialize template toolkit
31
32 my $template = Template->new;
33
34 if (! -d $out_dir) {
35         make_path($out_dir) or die "Could not create outdir $out_dir: $!";
36 }
37
38 foreach my $file (@files) {
39         next if $file =~ /^$out_dir/;
40         next if $file =~ /$0$/;
41         if ($file =~ /\.tt2$/) {
42                 my $output;
43                 $template->process($file, undef, \$output)
44                         || die "Could not process file \"$file\": $!";
45
46                 my ($name,$path,$suffix) = fileparse($file,qw (.tt2));
47         make_path("$out_dir/$path") unless -d "$out_dir/$path";
48                 open (my $fh, '>', "$out_dir/$path/$name")
49                         or die "Could not write to $file: $!";
50                 print $fh $output;
51                 close($fh);
52         } else {
53                 fcopy ($file, "$out_dir/$file") or die "Could not copy $file to $out_dir/$file: $!";
54         }
55 }