From: Matt S Trout Date: Sun, 23 Oct 2011 03:44:58 +0000 (+0000) Subject: add generate command to output site to a directory tree X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7857f55119dfeebb5355d100d7ccf41936a830ed;p=scpubgit%2FSCS.git add generate command to output site to a directory tree --- diff --git a/lib/SCSite.pm b/lib/SCSite.pm index a6b1abf..f8c8ac1 100755 --- a/lib/SCSite.pm +++ b/lib/SCSite.pm @@ -169,12 +169,42 @@ sub run_if_script { around _run_cli => sub { my ($orig, $self) = (shift, shift); - if (@_ >= 2 and $_[0] eq 'dev' and $_[1] eq 'server') { + if (@_ >= 2 and $_[0] eq 'dev') { require SCSite::DevMode; Moo::Role->apply_roles_to_object($self, 'SCSite::DevMode'); - return $self->_run_dev_server(@_[2..$#_]); + if ($self->can("_run_dev_$_[1]")) { + return $self->${\"_run_dev_$_[1]"}(@_[2..$#_]); + } else { + die "No such dev mode $_[1]"; + } + } + if (@_ >= 1 and my $code = $self->can("_run_cli_$_[0]")) { + shift; + return $self->$code(@_); } return $self->$orig(@_); }; +sub _run_cli_generate { + my ($self, $to) = @_; + die "generate requires a directory to generate to" + unless $to and -d $to; + my $out = io($to); + foreach my $path ('', $self->pages->all_paths) { + my $dir = $out->catdir($path); + $dir->mkpath; + $dir->catfile('index.html')->print( + $self->run_test_request(GET => "$path/")->content + ); + } + foreach my $path (map "/feed/$_/", keys %{$self->_feed_configs}) { + my $dir = $out->catdir($path); + $dir->mkpath; + $dir->catfile('index.atom')->print( + $self->run_test_request(GET => $path)->content + ); + } +} + + __PACKAGE__->run_if_script;