Skip Menu |

This queue is for tickets about the App-Dapper CPAN distribution.

Report information
The Basics
Id: 102915
Status: new
Priority: 0/
Queue: App-Dapper

People
Owner: Nobody in particular
Requestors: jhealy [...] logn.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Main object values not overridden by config
Date: Fri, 20 Mar 2015 14:59:43 -0400
To: bug-App-Dapper [...] rt.cpan.org
From: Jason Healy <jhealy [...] logn.net>
Hello! Just started playing with Dapper today for a couple hours and I’m liking it a lot. I bumped into a problem when I tried to specify an output directory in the _config.yml file; dapper just seemed to ignore it. I’m running Dapper 0.18 from CPAN. I hacked the source a little and found that the YAML is loaded into $self->{site}, but most of the code uses $self->{output} (not $self->{site}->{output}). I went with the fewest changes by just overwriting the $self variables when they’re defined in the YAML. As additional cleanup, there was one instance of using $self->{site}->{output}, which I changed for consistency. Lastly, I auto-added the custom values to the “ignore” config so they don’t get swept up by the file copy. I’ve also included a small patch for Utils.pm that does a (trivially) faster file read (non line-oriented), and offers some better error reporting for input files that don’t contain the correct YAML header. I didn’t realize that the copy was from the current working directory (I thought it was from source), and this patch makes that case easier to track down. Thanks for your work, and I hope these are helpful. Jason --- /usr/local/src/App-Dapper-0.18/lib/App/Dapper.pm 2014-05-02 02:02:55.0000 00000 -0400 +++ Dapper.pm 2015-03-20 14:43:53.232500785 -0400 @@ -480,6 +480,13 @@ # Graft together @{$self->{site}}{keys %{$config}} = values %$config; + # Override top-level defaults with config file values + for my $tl (qw(source output layout)) { + if (defined($config->{$tl})) { + $self->{$tl} = $config->{$tl}; + } + } + die "error: \"source\" must be defined in project file\n" unless defined $s elf->{source}; die "error: \"output\" must be defined in project file\n" unless defined $self->{output}; die "error: \"layout\" must be defined in project file\n" unless defined $self->{layout}; @@ -588,6 +595,8 @@ $source_content =~ /(---.*?)---(.*)/s; + die("No YAML found in source file '$source_file_name'\n") unless $1; + my ($frontmatter) = Load($1); $page{content} = $2; @@ -649,7 +658,7 @@ $page{filename} = App::Dapper::Utils::filter_stem("$destination_file_name") . $page{extension}; if(defined $page{categories}) { - my $filename = $self->{site}->{output} . $page{url}; + my $filename = $self->{output} . $page{url}; $filename =~ s/\/$/\/index.html/; $page{filename} = canonpath $filename; } @@ -689,6 +698,9 @@ for my $i (@{ $self->{site}->{ignore} }) { next DIR if ($file =~ m/$i/); } + for my $i (($self->{source}, $self->{layout}, $self->{output})) { + next DIR if ($file =~ m/$i/); + } $output =~ s/\/$//; my $command = "cp -r $file $output”; --- /usr/local/src/App-Dapper-0.18/lib/App/Dapper/Utils.pm 2014-04-17 23:23:44.000000000 -0400 +++ Dapper/Utils.pm 2015-03-20 14:35:22.488676006 -0400 @@ -30,12 +30,12 @@ my $file_contents; #print "Reading contents of $file_name\n"; - + local $/; # Disable line parsing, slurp whole file at once open(FILE, "<:encoding(UTF-8)", "$file_name") or die("could not open file: $!\n"); - foreach (<FILE>) { $file_contents .= $_; } + $file_contents = <FILE>; close(FILE) or die("could not close file: $!\n"); - return $file_contents; + return $file_contents || ''; } =head2 get_modified_time