| | 176 | sub hdlr_entries { |
| | 177 | my ($ctx, $args, $cond) = @_; |
| | 178 | my $entries = $ctx->stash('entries'); |
| | 179 | my @entries = @$entries; |
| | 180 | |
| | 181 | my @res; |
| | 182 | my($last_day, $next_day) = ('00000000') x 2; |
| | 183 | my $i = 0; |
| | 184 | for my $e (@entries) { |
| | 185 | local $ctx->{__stash}{entry} = $e; |
| | 186 | local $ctx->{current_timestamp} = $e->created_on; |
| | 187 | local $ctx->{modification_timestamp} = $e->modified_on; |
| | 188 | my $this_day = substr $e->created_on, 0, 8; |
| | 189 | my $next_day = $this_day; |
| | 190 | my $footer = 0; |
| | 191 | if (defined $entries[$i+1]) { |
| | 192 | $next_day = substr($entries[$i+1]->created_on, 0, 8); |
| | 193 | $footer = $this_day ne $next_day; |
| | 194 | } else { |
| | 195 | $footer++; |
| | 196 | } |
| | 197 | my $out = $builder->build($ctx, $tok, { |
| | 198 | %$cond, |
| | 199 | DateHeader => ($this_day ne $last_day), |
| | 200 | DateFooter => $footer, |
| | 201 | EntriesHeader => !$i, |
| | 202 | EntriesFooter => !defined $entries[$i+1], |
| | 203 | }); |
| | 204 | return $ctx->error($builder->errstr) unless defined $out; |
| | 205 | $last_day = $this_day; |
| | 206 | push @res, $out; |
| | 207 | $i++; |
| | 208 | } |
| | 209 | my $glue = $args->{glue} || ''; |
| | 210 | join $glue, @res; |
| | 211 | } |
| | 212 | |