Commit | Line | Data |
632f0e07 |
1 | package App::SCS::Plugin::Core::PagePlugin::Template; |
2 | |
3 | use Moo; |
4 | |
5 | with 'App::SCS::Role::PagePlugin'; |
6 | |
7 | has templates => (is => 'ro', required => 1); |
8 | |
9 | has name => (is => 'ro', required => 1); |
10 | |
11 | sub filter_html_zoom { |
12 | my ($self, $zoom) = @_; |
13 | my $template_page = $self->templates->get({ path => $self->name }) |
14 | or die "No such template ${\$self->name}"; |
15 | my $template_zoom = HTML::Zoom->from_html($template_page->html); |
16 | my @ev; |
0034f151 |
17 | $template_zoom->select('*[data-replace]') |
18 | ->collect({ into => \@ev, passthrough => 1 }) |
632f0e07 |
19 | ->then |
0034f151 |
20 | ->replace(sub { |
632f0e07 |
21 | my $sel = $ev[0]->{attrs}{'data-replace'}; |
0034f151 |
22 | $zoom->collect($sel, { into => \my @replace })->run; |
23 | HTML::Zoom::ArrayStream->new({ array => \@replace }) |
24 | }); |
632f0e07 |
25 | } |
26 | |
27 | 1; |