use Data::Pond qw(pond_read_datum pond_write_datum);
use List::Util qw(reduce);
use Module::Runtime qw(use_module);
+use HTML::Zoom;
use Moo;
has "_$_" => (is => 'ro', init_arg => $_) for qw(page_set);
with 'App::SCS::Role::PageChildren';
has $_ => (is => 'ro') for qw(
- title subtitle description keywords plugins html created path
+ title subtitle description keywords html created path
);
-has plugin_config => (is => 'lazy');
-
-sub _build_plugin_config {
- my ($self) = @_;
- $self->plugins
- ? pond_read_datum('[ '.$self->plugins.' ]')
- : []
-}
+has plugin_config => (is => 'rw', 'required' => 1);
sub has_plugin_config { exists $_[0]->plugin_config->{$_[1]} }
: ($name, $config)
);
}
- return $self->with(plugins => pond_write_datum(\@new));
+ return $self->with(plugin_config => \@new);
}
-has _page_plugins => (is => 'lazy');
-
-sub _build__page_plugins {
+has _raw_page_plugins => (is => 'lazy', builder => sub {
my ($self) = @_;
my $plugin_config = $self->plugin_config;
my ($plugin_map, $defaults) = @{$self->_page_set->plugin_config}
my $info = $plugin_map->{$name};
push @plugins,
use_module($info->{class})->new(
- ($info->{config}||sub{})->(), %$config, page => $self
+ ($info->{config}||sub{})->(), %$config, page => $self,
+ plugin_map => $plugin_map, # some things will need this
);
}
return \@plugins;
-}
+});
+
+has _page_plugins => (is => 'lazy', builder => sub {
+ my ($self) = @_;
+ my $raw = $self->_raw_page_plugins;
+ reduce { $b->filter_plugins($a) } $raw, @$raw;
+});
sub published_at {
$_[0]->created
} HTML::Zoom->from_html($self->html), @{$self->_page_plugins};
}
+sub body {
+ my ($self) = @_;
+ HTML::Zoom->from_html($self->html)
+ ->collect(body => { into => \my @ev })
+ ->run;
+ HTML::Zoom->from_events(\@ev)->to_html;
+}
+
no Moo;
sub with {