add a default 404 and 403 action, use the 404 on collection controller, make html...
[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 $layouts = $self->layouts;
30
31     my $tt_source = join("\n", "[%- VIEW ${name};",
32       (map {("BLOCK $_; -%]" . $layouts->{$_} ."[%- END;") } keys %$layouts),
33         "END; # End view\ndata.view = ${name}; -%]" );
34
35     $tt_object->process(\$tt_source, $tt_args)
36       || confess "Template processing error: ".$tt_object->error
37                 ." processing:\n${tt_source}";
38     confess "View template processed but no view object found"
39            ." after processing:\n${tt_source}"
40       unless $tt_args->{data}{view};
41     return $tt_args->{data}{view};
42   };
43
44 };
45
46 1;