1 package Reaction::UI::RenderingContext::TT;
4 use aliased 'Reaction::UI::RenderingContext';
5 use aliased 'Template::View';
7 class TT is RenderingContext, which {
10 is => 'ro', required => 1,
11 default => sub { 'Reaction::UI::Renderer::TT::Iter'; },
14 implements 'render' => as {
15 my ($self, $lset, $fname, $args) = @_;
17 # foreach non-_ prefixed key in the args
18 # build a subref for this key that passes self so the generator has a
19 # rendering context when [% key %] is evaluated by TT as $val->()
20 # (assuming it's a subref - if not just pass through)
24 my $arg = $args->{$_};
25 ($_ => (ref $arg eq 'CODE' ? sub { $arg->($self) } : $arg))
26 } grep { !/^_/ } keys %$args
29 # if there's an _ key that's our current topic (decalarative syntax
30 # sees $_ as $_{_}) so build an iterator around it.
32 # There's possibly a case for making everything an iterator but I think
33 # any fragment should only have a single multiple arg
35 # we also create a 'pos' shortcut to content.pos for brevity
37 if (my $topic = $args->{_}) {
38 my $iter = $self->iter_class->new(
41 $tt_args->{content} = $iter;
42 $tt_args->{pos} = sub { $iter->pos };
44 $lset->tt_view->include($fname, $tt_args);
49 package Reaction::UI::Renderer::TT::Iter;
56 sub pos { shift->{pos} }
59 my ($class, $cr, $rctx) = @_;
60 bless({ rctx => $rctx, cr => $cr, pos => 0 }, $class);
66 my $next = $self->{cr}->();
68 return sub { $next->($self->{rctx}) };
74 while (my $e = $self->next) {
83 foreach my $e (@{$self->all}) {