]> git.decadent.org.uk Git - maypole.git/blob - lib/Apache/MVC/View/TT.pm
This is very close to being able to spit out pages now.
[maypole.git] / lib / Apache / MVC / View / TT.pm
1 package Apache::MVC::View::TT;
2 use Lingua::EN::Inflect;
3 use Template;
4 use File::Spec;
5 use UNIVERSAL::moniker;
6
7 sub template_root { "/opt/houseshare/templates" } # For now
8
9 sub new { bless {}, shift } # Not worth having
10
11 sub process {
12     my ($self, $r) = @_;
13     my $root = $self->template_root;
14     my $template = Template->new({ INCLUDE_PATH => [
15         $root,
16         File::Spec->catdir($root, $r->model_class->moniker),
17         File::Spec->catdir($root, "custom"),
18         File::Spec->catdir($root, "factory")
19     ]});
20     my %args = (
21         request => $r,
22         class   => $r->model_class,
23         objects => $r->objects,
24         # ...
25     );
26
27     # User-friendliness facility for custom template writers.
28     if (@{$r->objects} > 1){
29         $args{$r->model_class->plural_moniker} = $r->objects;
30     } else {
31         ($args{$r->model_class->moniker}) = @{$r->objects};
32     }
33
34     $template->process($r->template, \%args);
35 }