]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Apache/MVC/View/TT.pm
This gives us non-object-based templated pages. And a little start on
[maypole.git] / lib / Apache / MVC / View / TT.pm
index 083b35950832d601ccc260ebb0c9f1d7568497d9..4c15ea9e28a3e0861409caf573c4aad3e75c19aa 100644 (file)
@@ -1,4 +1,5 @@
 package Apache::MVC::View::TT;
+use Apache::Constants;
 use Lingua::EN::Inflect;
 use Template;
 use File::Spec;
@@ -10,10 +11,11 @@ sub new { bless {}, shift } # Not worth having
 
 sub _tt {
     my ($self, $r) = @_;
-    my $root = $r->config->{template_root};
+    my $root = $r->{ar}->document_root . "/". $r->{ar}->location;
+    warn "Root was $root";
     Template->new({ INCLUDE_PATH => [
         $root,
-        File::Spec->catdir($root, $r->model_class->moniker),
+        ($r->model_class && File::Spec->catdir($root, $r->model_class->moniker)),
         File::Spec->catdir($root, "custom"),
         File::Spec->catdir($root, "factory")
     ]});
@@ -29,23 +31,25 @@ sub _args {
         base    => $r->config->{uri_base},
         config  => $r->config
         # ...
-    );
-    $args{classmetadata} = {
-        name => $class,
-        columns => [ $class->columns ],
-        colnames => { $class->column_names },
-        related_accessors => [ $class->related($r) ],
-        moniker => $class->moniker,
-        plural  => $class->plural_moniker,
-        cgi => { $class->to_cgi },
-        description => $class->description
-    };
+    ) ;
+    if ($class) { 
+        $args{classmetadata} = {
+            name => $class,
+            columns => [ $class->columns ],
+            colnames => { $class->column_names },
+            related_accessors => [ $class->related($r) ],
+            moniker => $class->moniker,
+            plural  => $class->plural_moniker,
+            cgi => { $class->to_cgi },
+            description => $class->description
+        };
 
-    # 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};
+        # 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};
+        }
     }
 
     # Overrides
@@ -57,8 +61,11 @@ sub process {
     my ($self, $r) = @_;
     my $template = $self->_tt($r);
     my $output;
+    warn "Processing ".$r->template;
     $template->process($r->template, { $self->_args($r) }, \$output)
-    || $self->error($r, $template->error);
+    || return $self->error($r, $template->error);
+
+    warn "And off it goes!\n";
     $r->{ar}->content_type("text/html");
     $r->{ar}->headers_out->set("Content-Length" => length $output);
     $r->{ar}->send_http_header;
@@ -68,7 +75,11 @@ sub process {
 
 sub error {
     my ($self, $r, $error) = @_;
+    warn $error;
+    if ($error =~ /not found$/) { return DECLINED }
     $r->{ar}->send_http_header("text/plain");
     $r->{ar}->print($error);
     exit;
 }
+
+1;