]> git.decadent.org.uk Git - maypole.git/blobdiff - 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
diff --git a/lib/Apache/MVC/View/TT.pm b/lib/Apache/MVC/View/TT.pm
new file mode 100644 (file)
index 0000000..5c67d50
--- /dev/null
@@ -0,0 +1,35 @@
+package Apache::MVC::View::TT;
+use Lingua::EN::Inflect;
+use Template;
+use File::Spec;
+use UNIVERSAL::moniker;
+
+sub template_root { "/opt/houseshare/templates" } # For now
+
+sub new { bless {}, shift } # Not worth having
+
+sub process {
+    my ($self, $r) = @_;
+    my $root = $self->template_root;
+    my $template = Template->new({ INCLUDE_PATH => [
+        $root,
+        File::Spec->catdir($root, $r->model_class->moniker),
+        File::Spec->catdir($root, "custom"),
+        File::Spec->catdir($root, "factory")
+    ]});
+    my %args = (
+        request => $r,
+        class   => $r->model_class,
+        objects => $r->objects,
+        # ...
+    );
+
+    # User-friendliness facility for custom template writers.
+    if (@{$r->objects} > 1){
+        $args{$r->model_class->plural_moniker} = $r->objects;
+    } else {
+        ($args{$r->model_class->moniker}) = @{$r->objects};
+    }
+
+    $template->process($r->template, \%args);
+}