X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FMaypole%2FView%2FTT.pm;h=0e8d89fbc1b2476f992c7aee9c57a1f7eafd3ea3;hb=5c199c0e9cd05a00bfc04d9688982979a41f3ee8;hp=babd0f457a9260735ccd438eb88c5b2ce2c00837;hpb=d09e000fc977211b8bd1a77285a952421b60aa7a;p=maypole.git diff --git a/lib/Maypole/View/TT.pm b/lib/Maypole/View/TT.pm index babd0f4..0e8d89f 100644 --- a/lib/Maypole/View/TT.pm +++ b/lib/Maypole/View/TT.pm @@ -1,82 +1,41 @@ -package Apache::MVC::View::TT; -use Apache::Constants; -use Lingua::EN::Inflect; +package Maypole::View::TT; +use base 'Maypole::View::Base'; +use Maypole::Constants; use Template; -use File::Spec; -use UNIVERSAL::moniker; -use strict; - -sub new { bless {}, shift } # Not worth having - -sub _tt { +sub template { my ($self, $r) = @_; - my $root = $r->{ar}->document_root . "/". $r->{ar}->location; - warn "Root was $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") - ]}); + 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 _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->columns ], - colnames => { $class->column_names }, - related_accessors => [ $class->related($r) ], - moniker => $class->moniker, - plural => $class->plural_moniker, - cgi => { $class->to_cgi }, - description => $class->description - }; +1; - # 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 NAME - # Overrides - %args = (%args, %{$r->{template_args}||{}}); - %args; -} +Maypole::View::TT - A Template Toolkit view class for Maypole -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 SYNOPSIS - $r->{ar}->content_type("text/html"); - $r->{ar}->headers_out->set("Content-Length" => length $output); - $r->{ar}->send_http_header; - $r->{ar}->print($output); - return 200; -} + BeerDB->config->{view} = "Maypole::View::TT"; # The default anyway -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; -} +=head1 DESCRIPTION -1; +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 chapter, +for the template variables available and for a refresher on how template +components are resolved. + +=head1 AUTHOR + +Simon Cozens + +=cut