[Bps-public-commit] r14424 - in Prophet/trunk: .
sartak at bestpractical.com
sartak at bestpractical.com
Wed Jul 23 03:59:12 EDT 2008
Author: sartak
Date: Wed Jul 23 03:59:12 2008
New Revision: 14424
Removed:
Prophet/trunk/lib/Prophet/CLI/Command/Html.pm
Modified:
Prophet/trunk/ (props changed)
Prophet/trunk/lib/Prophet/CLI/Command/Publish.pm
Log:
r64861 at onn: sartak | 2008-07-23 03:59:04 -0400
Instead of an html command, allow for publish --html
Modified: Prophet/trunk/lib/Prophet/CLI/Command/Publish.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Publish.pm (original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Publish.pm Wed Jul 23 03:59:12 2008
@@ -2,17 +2,32 @@
use Moose;
extends 'Prophet::CLI::Command::Export';
with 'Prophet::CLI::PublishCommand';
+with 'Prophet::CLI::CollectionCommand';
before run => sub {
my $self = shift;
die "Please specify a --to.\n" unless $self->has_arg('to');
+
+ # set the temp directory where we will do all of our work, which will be
+ # published via rsync
+ $self->set_arg(path => $self->tempdir);
};
-before run => sub {
+around run => sub {
+ my $orig = shift;
my $self = shift;
- $self->set_arg(path => $self->tempdir);
+
+ # if we have the html argument, populate the tempdir with rendered templates
+ if ($self->has_arg('html')) {
+ $self->render_templates_into($self->arg('path'));
+ return;
+ }
+
+ # otherwise, do the normal prophet export this replica
+ return $self->$orig(@_);
};
+# the tempdir is populated, now publish it
after run => sub {
my $self = shift;
my $from = $self->arg('path');
@@ -26,6 +41,52 @@
print "Publish complete.\n";
};
+# helper methods for rendering templates
+sub render_templates_into {
+ my $self = shift;
+ my $dir = shift;
+
+ require Prophet::Server::View;
+ Template::Declare->init(roots => ['Prophet::Server::View']);
+
+ # allow user to specify a specific type to render
+ my @types = $self->type || $self->types_to_render;
+
+ for my $type (@types) {
+ my $subdir = $dir->subdir($type);
+ $subdir->mkpath;
+
+ my $records = $self->get_collection_object(type => $type);
+ $records->matching(sub { 1 });
+
+ my $fh = $subdir->file('index.html')->openw;
+ print { $fh } Template::Declare->show('record_table' => $records);
+ close $fh;
+
+ for my $record ($records->items) {
+ my $fh = $subdir->file($record->uuid . '.html')->openw;
+ print { $fh } Template::Declare->show('record' => $record);
+ }
+ }
+}
+
+sub should_skip_type {
+ my $self = shift;
+ my $type = shift;
+
+ # should we skip all _private types?
+ return 1 if $type eq '_merge_tickets';
+
+ return 0;
+}
+
+sub types_to_render {
+ my $self = shift;
+
+ return grep { !$self->should_skip_type($_) }
+ @{ $self->app_handle->handle->list_types };
+}
+
__PACKAGE__->meta->make_immutable;
no Moose;
More information about the Bps-public-commit
mailing list