comparison Lib/IMPL/Web/View/TTView.pm @ 351:cfd7570c2af2

working on TTView: created TTView class for rendering models
author cin
date Tue, 08 Oct 2013 17:40:35 +0400
parents
children feeb3bc4a818
comparison
equal deleted inserted replaced
350:f356c4894d1b 351:cfd7570c2af2
1 package IMPL::Web::View::TTView;
2 use strict;
3
4 use IMPL::Const qw(:prop);
5 use IMPL::declare {
6 require => {
7 Context => 'IMPL::Web::View::TTContext'
8 },
9 base => [
10 'IMPL::Object' => undef,
11 'IMPL::Object::Autofill' => '@_',
12 'IMPL::Object::Serializable' => undef
13 ],
14 props => [
15 options => PROP_RW,
16 view => PROP_RW,
17 layout => PROP_RW,
18 tt_ext => PROP_RW,
19 includes => PROP_RW | PROP_LIST
20 ]
21 };
22
23 sub CTOR {
24 my ($this) = @_;
25
26 $this->tt_ext('tt') unless defined $this->tt_ext;
27 }
28
29 sub display {
30 my ($this,$model,$template,$args) = @_;
31
32 my $context = Context->new($this->options);
33 my $layout = delete $args->{layout};
34
35 return $context->invoke_environment(
36 sub {
37 my $ctx = shift;
38 if ($layout) {
39 return $ctx->invoke_environment(
40 sub {
41 return $ctx->render($layout,$args);
42 },
43 {
44 base => $this->layout,
45 content => sub {
46 $ctx->invoke_environment(
47 sub {
48 return shift->display($model,$template,$args);
49 },
50 {
51 base => $this->view
52 }
53 )
54 }
55 }
56 );
57 } else {
58 return $ctx->invoke_environment(
59 sub {
60 return $ctx->display($model,$template,$args);
61 },
62 {
63 base => $this->view
64 }
65 );
66 }
67 },{
68 includes => scalar($this->includes),
69 tt_ext => 'tt',
70 document => {},
71 debug => sub {
72 warn @_;
73 }
74 }
75 );
76 }
77
78 1;