diff options
author | matthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2007-11-26 20:11:29 +0000 |
---|---|---|
committer | matthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2007-11-26 20:11:29 +0000 |
commit | f2fef590a7283ea919bdaa51bac9d433e8785a09 (patch) | |
tree | 4ccd3b37fb374e1b21883f1d4d3f8e23dd136884 /lib/Reaction/UI/RenderingContext | |
parent | 097e844260b8b3443cd44d8295c941f1086845bc (diff) | |
download | reaction-f2fef590a7283ea919bdaa51bac9d433e8785a09.tar.gz reaction-f2fef590a7283ea919bdaa51bac9d433e8785a09.zip |
root of componentUI renders
Diffstat (limited to 'lib/Reaction/UI/RenderingContext')
-rw-r--r-- | lib/Reaction/UI/RenderingContext/TT.pm | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/lib/Reaction/UI/RenderingContext/TT.pm b/lib/Reaction/UI/RenderingContext/TT.pm index a4e3ff8..e925ff6 100644 --- a/lib/Reaction/UI/RenderingContext/TT.pm +++ b/lib/Reaction/UI/RenderingContext/TT.pm @@ -11,8 +11,44 @@ class TT is RenderingContext, which { default => sub { 'Reaction::UI::Renderer::TT::Iter'; }, ); + our $body; + + implements 'dispatch' => as { + my ($self, $render_tree, $args) = @_; +#warn "-- dispatch start\n"; + local $body = ''; + my %args_copy = %$args; + foreach my $to_render (@$render_tree) { + my ($type, @to) = @$to_render; + if ($type eq '-layout') { + my ($lset, $fname, $next) = @to; + local $args_copy{call_next} = + (@$next + ? sub { $self->dispatch($next, $args); } + : '' # no point running internal dispatch if nothing -to- dispatch + ); + $self->render($lset, $fname, \%args_copy); + } elsif ($type eq '-render') { + my ($widget, $fname, $over) = @to; + #warn "@to"; + if (defined $over) { + $over->each(sub { + local $args_copy{_} = $_[0]; + $body .= $widget->render($fname, $self, \%args_copy); + }); + } else { + $body .= $widget->render($fname, $self, \%args_copy); + } + } + } +#warn "-- dispatch end, body: ${body}\n-- end body\nbacktrace: ".Carp::longmess()."\n-- end trace\n"; + return $body; + }; + implements 'render' => as { my ($self, $lset, $fname, $args) = @_; + + confess "\$body not in scope" unless defined($body); # foreach non-_ prefixed key in the args # build a subref for this key that passes self so the generator has a @@ -22,7 +58,7 @@ class TT is RenderingContext, which { my $tt_args = { map { my $arg = $args->{$_}; - ($_ => (ref $arg eq 'CODE' ? sub { $arg->($self) } : $arg)) + ($_ => (ref $arg eq 'CODE' ? sub { $arg->($self, $args) } : $arg)) } grep { !/^_/ } keys %$args }; @@ -41,7 +77,8 @@ class TT is RenderingContext, which { $tt_args->{content} = $iter; $tt_args->{pos} = sub { $iter->pos }; } - $lset->tt_view->include($fname, $tt_args); + $body .= $lset->tt_view->include($fname, $tt_args); +#warn "rendered ${fname}, body length now ".length($body)."\n"; }; }; |