aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/View/TT.pm
blob: af282e44a399d1bd747a6f662a05a1a5e38aaf32 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package Reaction::UI::View::TT;

use Reaction::Class;
use aliased 'Reaction::UI::View';
use Template;

class TT is View, which {

  has '_tt' => (isa => 'Template', is => 'rw', lazy_fail => 1);

  implements 'BUILD' => as {
    my ($self, $args) = @_;
    my $tt_args = $args->{tt}||{};
    $self->_tt(Template->new($tt_args));
  };

  overrides 'layout_set_args_for' => sub {
    my ($self) = @_;
    return (super(), tt_object => $self->_tt);
  };

  implements layout_set_file_extension => as { 'tt' };

  implements 'serve_static_file' => as {
    my ($self, $c, $args) = @_;
    foreach my $path (@{$self->search_path_for_type('web')}) {
      my $cand = $path->file(@$args);
      if ($cand->stat) {
        $c->serve_static_file($cand);
        return 1;
      }
    }
    return 0;
  };

};

1;