Mercurial > pub > Impl
annotate Lib/IMPL/Web/View/TTDocument.pm @ 310:0a9d51cf6dfd
*TTView: refactoring, document supports custom classes, layouts are become controls
author | sergey |
---|---|
date | Fri, 19 Apr 2013 16:39:01 +0400 |
parents | 5e4e7c8fbca1 |
children | d3b5a67ad2e8 |
rev | line source |
---|---|
181 | 1 package IMPL::Web::View::TTDocument; |
2 use strict; | |
3 | |
236 | 4 use Scalar::Util qw(weaken); |
5 use IMPL::Const qw(:prop); | |
288
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
6 use IMPL::lang qw(:hash is); |
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
7 use Carp qw(carp); |
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
8 use mro; |
309 | 9 use IMPL::Exception(); |
236 | 10 use IMPL::declare { |
11 require => { | |
305 | 12 TTRegistry => 'IMPL::Web::View::TTRegistry', |
236 | 13 TTFactory => 'IMPL::Web::View::TTFactory', |
14 TTControl => 'IMPL::Web::View::TTControl', | |
309 | 15 Loader => 'IMPL::Code::Loader', |
16 OpException => '-IMPL::InvalidOperationException' | |
236 | 17 }, |
18 base => [ | |
19 'IMPL::Web::View::TTControl' => sub { | |
309 | 20 my ($template,$ctx,$vars) = @_; |
288
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
21 $ctx ||= Template::Context->new(); |
309 | 22 return $template, $ctx, $vars; # context |
236 | 23 } |
24 ], | |
25 props => [ | |
26 layout => PROP_RW, | |
307 | 27 baseLocation => PROP_RW |
236 | 28 ] |
29 }; | |
181 | 30 |
31 sub CTOR { | |
308 | 32 my ($this,$template,$ctx,$vars) = @_; |
194 | 33 |
34 $this->layout( $template->layout ) unless $this->layout; | |
301 | 35 $this->title( $template->title ) unless $this->title; |
194 | 36 |
288
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
37 $this->context->stash->update($vars) |
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
38 if ref $vars eq 'HASH'; |
181 | 39 } |
40 | |
41 sub Render { | |
194 | 42 my ($this,$args) = @_; |
288
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
43 |
241
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
238
diff
changeset
|
44 $args ||= {}; |
310
0a9d51cf6dfd
*TTView: refactoring, document supports custom classes, layouts are become controls
sergey
parents:
309
diff
changeset
|
45 $args->{document} = $this; |
290 | 46 |
305 | 47 $this->context->stash->update({ |
307 | 48 document => sub { $this } |
305 | 49 }); |
288
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
50 |
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
51 my $text = eval { |
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
52 |
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
53 if ($this->layout) { |
310
0a9d51cf6dfd
*TTView: refactoring, document supports custom classes, layouts are become controls
sergey
parents:
309
diff
changeset
|
54 my $layout = $this->registry->Require(join('/',$this->layoutBase, $this->layout))->new(); |
0a9d51cf6dfd
*TTView: refactoring, document supports custom classes, layouts are become controls
sergey
parents:
309
diff
changeset
|
55 |
288
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
56 my $content = $this->next::method($args); |
310
0a9d51cf6dfd
*TTView: refactoring, document supports custom classes, layouts are become controls
sergey
parents:
309
diff
changeset
|
57 return $layout->Render({ |
0a9d51cf6dfd
*TTView: refactoring, document supports custom classes, layouts are become controls
sergey
parents:
309
diff
changeset
|
58 content => $content, |
0a9d51cf6dfd
*TTView: refactoring, document supports custom classes, layouts are become controls
sergey
parents:
309
diff
changeset
|
59 template => $this->template, |
0a9d51cf6dfd
*TTView: refactoring, document supports custom classes, layouts are become controls
sergey
parents:
309
diff
changeset
|
60 document => $this |
0a9d51cf6dfd
*TTView: refactoring, document supports custom classes, layouts are become controls
sergey
parents:
309
diff
changeset
|
61 }); |
288
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
62 } else { |
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
63 return $this->next::method($args); |
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
64 } |
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
65 }; |
301 | 66 |
67 my $e = $@; | |
288
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
68 |
307 | 69 undef $this; |
70 | |
288
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
71 if ($e) { |
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
72 die $e; |
194 | 73 } else { |
288
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
74 return $text; |
194 | 75 } |
190
cd1ff7029a63
IMLP::Web::View refactored, added new method 'require' which is available inside templates. Changed document rendering.
cin
parents:
189
diff
changeset
|
76 } |
cd1ff7029a63
IMLP::Web::View refactored, added new method 'require' which is available inside templates. Changed document rendering.
cin
parents:
189
diff
changeset
|
77 |
303
a5eb64c6e6f7
TTDocument.GetTemplate corrected to work with document blocks
cin
parents:
301
diff
changeset
|
78 sub GetTemplate { |
a5eb64c6e6f7
TTDocument.GetTemplate corrected to work with document blocks
cin
parents:
301
diff
changeset
|
79 my ($this,$name) = @_; |
a5eb64c6e6f7
TTDocument.GetTemplate corrected to work with document blocks
cin
parents:
301
diff
changeset
|
80 |
a5eb64c6e6f7
TTDocument.GetTemplate corrected to work with document blocks
cin
parents:
301
diff
changeset
|
81 $this->template->blocks->{$name}; |
a5eb64c6e6f7
TTDocument.GetTemplate corrected to work with document blocks
cin
parents:
301
diff
changeset
|
82 } |
a5eb64c6e6f7
TTDocument.GetTemplate corrected to work with document blocks
cin
parents:
301
diff
changeset
|
83 |
308 | 84 sub DTOR { |
85 my $this = shift; | |
86 | |
87 $this->registry->Dispose() if $this->registry; | |
88 } | |
89 | |
289 | 90 sub _clone_context { |
91 my $args = { %{shift || {}} }; | |
92 delete $args->{CONFIG}; | |
93 | |
94 return Template::Context->new($args); | |
95 } | |
96 | |
181 | 97 1; |
98 | |
99 __END__ | |
100 | |
101 =pod | |
102 | |
103 =head1 NAME | |
104 | |
105 C<IMPL::Web::View::TTDocument> - документ для построения HTML страницы на основе шаблонов TT. | |
106 | |
107 =head1 SYNOPSIS | |
108 | |
109 =begin code | |
110 | |
111 | |
112 =end code | |
113 | |
114 =head1 DESCRIPTION | |
115 | |
116 | |
117 =over | |
118 | |
195
7a920771fd8e
IMPL::Web::View changed document layout handling, docs, examples
cin
parents:
194
diff
changeset
|
119 |
181 | 120 =cut |