53489f352ddc020147029d333859367e06d6a3dc
[scpubgit/SCS.git] / lib / SCSite / SubListFilter.pm
1 package SCSite::SubListFilter;
2
3 use Moo;
4
5 with 'SCSite::Filter';
6
7 sub _filter_stream {
8   my ($self, $stream, $config, $page) = @_;
9   my $max = $config->{max_entries}||undef; # explicit undef (not 0)
10   my %child =
11     map +(exists $config->{$_} ? ($_ => $config->{$_}) : ()),
12       qw(min_depth max_depth at_depth);
13   $stream->select('.SubList')
14          ->repeat_content($page->children(%child)->latest($max)->map(sub {
15              my $o = shift;
16              sub {
17                $_->select('.entry.title')->replace_content($o->title)
18                  ->select('.entry.subtitle')->replace_content($o->subtitle)
19                  ->select('.entry.description')->replace_content($o->description)
20                  ->select('.entry.published_at')->replace_content($o->published_at)
21                  ->select('.entry.link')->set_attribute(href => $o->path);
22              }
23           }));
24 }
25
26 1;