1 package App::SCS::Plugin::Core::PagePlugin::Template;
3 use List::Util qw(reduce);
6 with 'App::SCS::Role::PagePlugin';
8 has templates => (is => 'ro', required => 1);
10 has name => (is => 'ro', required => 1);
12 sub filter_html_zoom {
13 my ($self, $zoom) = @_;
14 my $template_page = $self->templates->get({ path => $self->name })
15 or die "No such template ${\$self->name}";
16 my $template_zoom = HTML::Zoom->from_html($template_page->html);
19 $template_zoom->select('*[data-wrap]')
20 ->collect({ into => \@ev, passthrough => 1 })
22 ->collect({ filter => sub {
23 my %attrs = %{$ev[0]->{attrs}};
24 my $select = delete $attrs{'data-wrap'};
27 raw => undef, raw_attrs => undef,
30 grep $_ ne 'data-wrap', @{$ev[0]->{attr_names}}
33 $wrap{$select} = \@ev;
41 ->collect({ into => \@orig, passthrough => 1 })
44 my $orig = HTML::Zoom->from_events(\@orig);
45 my $wrap = HTML::Zoom->from_events(\@{$wrap{$sel}});
47 $wrap->select('*[data-replace]')
48 ->collect({ into => \@to_replace, passthrough => 1 })
51 my $sel = $to_replace[0]->{attrs}{'data-replace'};
52 my $content = $sel =~ s/^content-of:\s*//;
53 $orig->collect($sel, {
54 into => \my @replace_with,
57 HTML::Zoom::ArrayStream->new({ array => \@replace_with })