]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole/View/TT.pm
Added Maypole::Config, and changed other classes to reflect that.
[maypole.git] / lib / Maypole / View / TT.pm
index 4bd7c0ebb836af2acd0817aba039b1da8b58b7e1..9a15dfa7044f384490b9f4d30a9f1262fa91897f 100644 (file)
@@ -1,81 +1,43 @@
 package Maypole::View::TT;
-use Apache::Constants;
-use Lingua::EN::Inflect;
+use base 'Maypole::View::Base';
+use Maypole::Constants;
 use Template;
-use File::Spec;
-use UNIVERSAL::moniker;
-use strict;
 
+sub template {
+    my ( $self, $r ) = @_;
+    my $template = Template->new( { INCLUDE_PATH => [ $self->paths($r) ] } );
+    my $output;
+    if ( $template->process( $r->template, { $self->vars($r) }, \$output ) ) {
+        $r->{output} = $output;
+        return OK;
+    }
+    else {
+        $r->{error} = $template->error;
+        return ERROR;
+    }
+}
 
-sub new { bless {}, shift } # Not worth having
+1;
 
-sub _tt {
-    my ($self, $r) = @_;
-    # This bit sucks.
-    my $root = $r->{config}{template_root} || $r->get_template_root;
-    Template->new({ INCLUDE_PATH => [
-        $root,
-        ($r->model_class && File::Spec->catdir($root, $r->model_class->moniker)),
-        File::Spec->catdir($root, "custom"),
-        File::Spec->catdir($root, "factory")
-    ]});
-}
+=head1 NAME
 
-sub _args {
-    my ($self, $r) = @_;
-    my $class = $r->model_class;
-    my %args = (
-        request => $r,
-        objects => $r->objects,
-        base    => $r->config->{uri_base},
-        config  => $r->config
-        # ...
-    ) ;
-    if ($class) { 
-        $args{classmetadata} = {
-            name => $class,
-            columns => [ $class->display_columns ],
-            colnames => { $class->column_names },
-            related_accessors => [ $class->related($r) ],
-            moniker => $class->moniker,
-            plural  => $class->plural_moniker,
-            cgi => { $class->to_cgi },
-            description => $class->description
-        };
+Maypole::View::TT - A Template Toolkit view class for Maypole
 
-        # 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 ||[]};
-        }
-    }
+=head1 SYNOPSIS
 
-    # Overrides
-    %args = (%args, %{$r->{template_args}||{}});
-    %args;
-}
+    BeerDB->config->view("Maypole::View::TT"); # The default anyway
 
-sub process {
-    my ($self, $r) = @_;
-    my $template = $self->_tt($r);
-    my $output;
-    $template->process($r->template, { $self->_args($r) }, \$output)
-    || return $self->error($r, $template->error);
+=head1 DESCRIPTION
 
-    $r->{content_type} ||= "text/html";
-    $r->{output} = $output;
-    return 200;
-}
+This is the default view class for Maypole; it uses the Template Toolkit
+to fill in templates with the objects produced by Maypole's model classes.
+Please see the Maypole manual, and in particular, the C<View> chapter,
+for the template variables available and for a refresher on how template
+components are resolved.
 
-sub error {
-    my ($self, $r, $error) = @_;
-    warn $error;
-    if ($error =~ /not found$/) { return DECLINED }
-    $r->{content_type} = "text/plain";
-    $r->{output} = $error;
-    $r->send_output;
-    exit;
-}
+=head1 AUTHOR
+
+Simon Cozens
+
+=cut
 
-1;