first working version

This commit is contained in:
Ask Bjørn Hansen
2008-11-09 15:40:08 -08:00
parent ec79234a4a
commit f20d1b240a
5 changed files with 77 additions and 37 deletions

1
.gitignore vendored
View File

@@ -8,3 +8,4 @@ pm_to_blib*
.lwpcookies
MojoX-Renderer-TT-*
cover_db
*~

View File

@@ -1,5 +1,5 @@
Revision history for MojoX-Renderer-TT
0.01 Date/time
0.01 November 9, 2008
First version, released on an unsuspecting world.

View File

@@ -13,6 +13,7 @@ WriteMakefile(
PL_FILES => {},
PREREQ_PM => {
'Test::More' => 0,
'Mojo' => 0.8008,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'MojoX-Renderer-TT-*' },

16
README
View File

@@ -1,16 +1,7 @@
MojoX-Renderer-TT
The README is used to introduce the module and provide instructions on
how to install the module, any machine dependencies it may have (for
example C compilers and installed libraries) and any other information
that should be provided before the module is installed.
A README file is required for CPAN modules since CPAN extracts the README
file from a module distribution so that people browsing the archive
can use it to get an idea of the module's uses. It is usually a good idea
to provide version information here so that people can decide whether
fixes for the module are worth downloading.
This module implements a Template Toolkit renderer for the Mojo
framework.
INSTALLATION
@@ -33,9 +24,6 @@ You can also look for information at:
RT, CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=MojoX-Renderer-TT
AnnoCPAN, Annotated CPAN documentation
http://annocpan.org/dist/MojoX-Renderer-TT
CPAN Ratings
http://cpanratings.perl.org/d/MojoX-Renderer-TT

View File

@@ -2,10 +2,75 @@ package MojoX::Renderer::TT;
use warnings;
use strict;
use base 'Mojo::Base';
use Template ();
use Carp ();
__PACKAGE__->attr('tt',
chained => 1,
);
sub new {
my $self = shift->SUPER::new(@_);
$self->_init(@_);
return sub { $self->_render(@_) }
}
sub _init {
my $self = shift;
my %args = @_;
my $mojo = delete $args{mojo};
my $dir = $mojo && $mojo->home->rel_dir('tmp/ctpl');
# TODO
# take and process options :-)
my %config = (
COMPILE_EXT => '.ttc',
COMPILE_DIR => ($dir || "/tmp"),
UNICODE => 1,
ENCODING => 'utf-8',
CACHE_SIZE => 128,
RELATIVE => 1,
ABSOLUTE => 1,
);
$self->tt(Template->new( \%config ))
or Carp::croak "Could not initialize Template object: $Template::ERROR";
return $self;
}
sub _render {
my ($self, $c, $tx, $path) = @_;
#use Data::Dump qw(dump);
#warn dump(\@args);
my $output;
unless ( $self->tt->process( $path,
{ c => $c,
tx => $tx,
},
\$output,
{ binmode => ":utf8" }
)
) {
Carp::carp $self->tt->error . "\n";
return $self->tt->error;
}
else {
return $output;
}
}
=head1 NAME
MojoX::Renderer::TT - The great new MojoX::Renderer::TT!
MojoX::Renderer::TT - Template Toolkit renderer for Mojo
=head1 VERSION
@@ -18,35 +83,20 @@ our $VERSION = '0.01';
=head1 SYNOPSIS
Quick summary of what the module does.
Perhaps a little code snippet.
use MojoX::Renderer::TT;
my $foo = MojoX::Renderer::TT->new();
...
sub startup {
...
$renderer->add_handler( tt => MojoX::Renderer::TT->new( mojo => $self ) );
}
=head1 EXPORT
A list of functions that can be exported. You can delete this section
if you don't export anything, such as for a purely object-oriented module.
=head1 METHODS
=head1 FUNCTIONS
=head2 new
=head2 function1
=cut
sub function1 {
}
=head2 function2
=cut
sub function2 {
}
=head1 AUTHOR