From 04e9b16d8f414d60bb53a270c38ed1ac8a1b6629 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Mon, 18 Apr 2011 09:43:58 +0100 Subject: fixed readme_generator again to append to files, rather than trying to create different ones for each script in a dir. Needs a way to force it to completely regen though, otherwise it'll just keep appending each tiem. --- readme_generator.pl | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/readme_generator.pl b/readme_generator.pl index dc3b277..67da7ac 100644 --- a/readme_generator.pl +++ b/readme_generator.pl @@ -45,12 +45,12 @@ sub read_input_file { my @other_files = glob($dir . "/*.pl"); - if (@other_files > 1) { - $filename =~ s/\.pl$//; - create_output_file($dir, "README-$filename.md", $parser); - } else { + # if (@other_files > 1) { + # $filename =~ s/\.pl$//; + # create_output_file($dir, "README-$filename.md", $parser); + # } else { create_output_file($dir, "README.md", $parser); - } + # } } sub create_output_file { @@ -58,9 +58,20 @@ sub create_output_file { my $filepath = File::Spec->catfile($dir, $filename); + my $markdown = $parser->as_markdown; + return unless length chomp($markdown); + return if $markdown =~ m/^\s*$/; + _err("Writing to $filepath"); - open my $wfh, '>', $filepath or die "Couldn't open $filepath for output: $!"; + my $sec_sep = ''; + if (-f $filepath) { + _err("$filepath already exists, going to append"); + $sec_sep = "\n\n* * * *\n\n"; + } + + open my $wfh, '>>', $filepath or die "Couldn't open $filepath for output: $!"; + print $wfh $sec_sep; print $wfh $parser->as_markdown; close $wfh; } -- cgit v1.2.3