unstable switchover before template renaming. added searchpath for widgets trying...
[catagits/Reaction.git] / lib / Reaction / UI / LayoutSet / TT.pm
1 package Reaction::UI::LayoutSet::TT;
2
3 use Reaction::Class;
4 use aliased 'Reaction::UI::LayoutSet';
5 use aliased 'Template::View';
6
7 class TT is LayoutSet, which {
8
9   has 'tt_view' => (is => 'rw', isa => View, lazy_fail => 1);
10
11   implements build_file_extension => as { 'tt' };
12
13   implements 'BUILD' => as {
14     my ($self, $args) = @_;
15
16     # Do this at build time rather than on demand so any exception if it
17     # goes wrong gets thrown sometime sensible
18
19     $self->tt_view($self->_build_tt_view($args));
20   };
21
22   implements '_build_tt_view' => as {
23     my ($self, $args) = @_;
24     my $tt_object = $args->{tt_object}
25       || confess "tt_object not provided to new()";
26     my $tt_args = { data => {} };
27     my $name = $self->name;
28     $name =~ s/\//__/g; #slashes are not happy here...
29     my $fragments = $self->fragments;
30     my $tt_source = qq{[% VIEW ${name};\n\n}.
31                     join("\n\n",
32                       map {
33                         qq{BLOCK $_; -%]\n}.$fragments->{$_}.qq{\n[% END;};
34                       } keys %$fragments
35                    ).qq{\nEND; # End view\ndata.view = ${name};\n %]};
36     $tt_object->process(\$tt_source, $tt_args)
37       || confess "Template processing error: ".$tt_object->error
38                 ." processing:\n${tt_source}";
39     confess "View template processed but no view object found"
40            ." after processing:\n${tt_source}"
41       unless $tt_args->{data}{view};
42     return $tt_args->{data}{view};
43   };
44
45 };
46
47 1;