Mercurial > pub > Impl
annotate Lib/IMPL/Web/View/TTView.pm @ 362:715b9959b207
WebView: initial work on metadata providers
author | cin |
---|---|
date | Thu, 28 Nov 2013 20:00:20 +0400 |
parents | 833e663796c4 |
children | d5c8b955bf8d |
rev | line source |
---|---|
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
1 package IMPL::Web::View::TTView; |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
2 use strict; |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
3 |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
4 use JSON; |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
5 use IMPL::lang qw(hashMerge is); |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
6 use IMPL::Const qw(:prop); |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
7 use IMPL::declare { |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
8 require => { |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
9 Context => 'IMPL::Web::View::TTContext', |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
10 Loader => 'IMPL::Code::Loader' |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
11 }, |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
12 base => [ |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
13 'IMPL::Object' => undef, |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
14 'IMPL::Object::Autofill' => '@_', |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
15 'IMPL::Object::Serializable' => undef |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
16 ], |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
17 props => [ |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
18 options => PROP_RW, |
353 | 19 viewBase => PROP_RW, |
20 layoutBase => PROP_RW, | |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
21 layout => PROP_RW, |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
22 tt_ext => PROP_RW, |
353 | 23 includes => PROP_RW | PROP_LIST, |
24 globals => PROP_RW | |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
25 ] |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
26 }; |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
27 |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
28 sub CTOR { |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
29 my ($this) = @_; |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
30 |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
31 $this->tt_ext('tt') unless defined $this->tt_ext; |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
32 } |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
33 |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
34 sub display { |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
35 my ($this,$model,$template,$args) = @_; |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
36 |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
37 my $context = Context->new($this->options); |
353 | 38 my $layout = delete $args->{layout} || $this->layout; |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
39 |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
40 return $context->invoke_environment( |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
41 sub { |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
42 my $ctx = shift; |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
43 if ($layout) { |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
44 return $ctx->invoke_environment( |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
45 sub { |
354 | 46 return shift->render( |
47 $layout, | |
48 hashMerge( | |
49 { | |
50 content => sub { | |
51 $ctx->invoke_environment( | |
52 sub { | |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
53 return shift->display_model($model,$template); |
354 | 54 }, |
55 { | |
56 base => $this->viewBase | |
57 } | |
58 ) | |
59 } | |
60 } | |
61 ) | |
62 ); # render | |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
63 }, |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
64 { |
353 | 65 base => $this->layoutBase, |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
66 } |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
67 ); |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
68 } else { |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
69 return $ctx->invoke_environment( |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
70 sub { |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
71 return shift->display_model($model,$template); |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
72 }, |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
73 { |
353 | 74 base => $this->viewBase |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
75 } |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
76 ); |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
77 } |
353 | 78 },hashMerge( |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
79 $this->globals, |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
80 hashMerge( |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
81 $args, |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
82 { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
83 includes => scalar($this->includes), |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
84 tt_ext => $this->tt_ext, |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
85 debug => sub { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
86 warn @_; |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
87 }, |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
88 is => sub { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
89 return is(shift,shift); |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
90 }, |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
91 import => sub { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
92 return Loader->safe->Require(shift); |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
93 }, |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
94 toJSON => sub { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
95 return JSON->new()->utf8->pretty->encode(shift); |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
96 } |
353 | 97 } |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
98 ) |
353 | 99 ) |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
100 ); |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
101 } |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
102 |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
103 1; |