Commit | Line | Data |
7adfd53f |
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 | |
e22de101 |
11 | implements build_file_extension => as { 'tt' }; |
12 | |
7adfd53f |
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; |
6ab43711 |
28 | $name =~ s/\//__/g; #slashes are not happy here... |
7adfd53f |
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 | |
6ab43711 |
45 | }; |
7adfd53f |
46 | |
47 | 1; |