Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

new Tenjin, new version, new tests

  • Loading branch information...
commit fd273b262b8e5a103899e808972821a6e302ac37 1 parent 1b240ac
@ido50 authored
View
2  .gitignore
@@ -12,3 +12,5 @@ pm_to_blib*
cover_db
pod2htm*.tmp
Catalyst-View-Tenjin-*
+.build*
+*.cache
View
4 Changes
@@ -1,8 +1,10 @@
Revision history for Perl extension Catalyst::View::Tenjin
{{$NEXT}}
+ - Adapted for changes to Tenjin (this is basically just an encoding change)
+ - Created tests, adapted from Catalyst::View::TT's test suite
-0.042 2010-08-06 22:20:04 Asia/Jerusalem
+0.042 2010-08-06 22:20:04 Asia/Jerusalem
- Updated to reflect changes in Tenjin
- Migrated distribution to use Dist::Zilla
View
18 MANIFEST.SKIP
@@ -1 +1,17 @@
-.gitignore
+^\.gitignore$
+^blib/.*$
+^inc/.*$
+^Makefile$
+^Makefile\.old$
+^pm_to_blib$
+^Build$
+^Build\.bat$
+^_build\.*$
+^pm_to_blib.+$
+^.+\.tar\.gz$
+^\.lwpcookies$
+^cover_db$
+^pod2htm.*\.tmp$
+^Catalyst-View-Tenjin-.*$
+^\.build.*$
+^.+\.cache$
View
24 README
@@ -7,10 +7,10 @@ SYNOPSIS
# check your new view's configuration
__PACKAGE__->config(
- USE_STRICT => 1,
+ USE_STRICT => 1, # false by default
INCLUDE_PATH => [ MyApp->path_to('root', 'templates') ],
TEMPLATE_EXTENSION => '.html',
- ENCODING => 'utf8',
+ ENCODING => 'UTF-8', # this is the default
);
# render view from lib/MyApp.pm or lib/MyApp::C::SomeController.pm
@@ -272,18 +272,6 @@ METHODS
# Redirect or display a message
}
-CHANGES
- * 0.04: Created a helper module so views can be created with
- myapp_create.pl
-
- * 0.03: Updated for compatibility with the new and revised Tenjin
- version.
-
- * 0.03: This module is now based on Moose.
-
-TODO
- * Create appropriate tests.
-
BUGS
Please report any bugs or feature requests to "bug-tenjin at
rt.cpan.org", or through the web interface at
@@ -294,7 +282,7 @@ BUGS
SUPPORT
You can find documentation for this module with the perldoc command.
- perldoc Catalyst::View::Tenjin
+ perldoc Catalyst::View::Tenjin
You can also look for information at:
@@ -318,15 +306,15 @@ SEE ALSO
Tenjin, Catalyst, Catalyst::View::TT
AUTHOR
- Ido Perlmuter <ido@ido50.net>. This module was adapted from
+ Ido Perlmuter "<ido at ido50.net>". This module was adapted from
Catalyst::View::TT, so most of the code and even the documentation
belongs to the authors of Catalyst::View::TT.
- Development of this module is done with github at
+ Development of this module is tracked via github at
<http://github.com/ido50/Catalyst-View-Tenjin>.
LICENSE AND COPYRIGHT
- Copyright (c) 2009-2010 the aforementioned authors.
+ Copyright (c) 2009-2011 the aforementioned authors.
This program is free software, you can redistribute it and/or modify it
under the same terms as Perl itself.
View
1  dist.ini
@@ -1,5 +1,4 @@
name = Catalyst-View-Tenjin
-version = 0.042
author = Ido Perlmuter <ido@ido50.net>
license = Perl_5
copyright_holder = Ido Perlmuter
View
8 lib/Catalyst/Helper/View/Tenjin.pm
@@ -1,10 +1,10 @@
package Catalyst::Helper::View::Tenjin;
+# ABSTRACT: Helper for creating Tenjin Views
+
use strict;
use warnings;
-# ABSTRACT: Helper for creating Tenjin Views
-
=head1 NAME
Catalyst::Helper::View::Tenjin - Helper for creating Tenjin Views
@@ -64,7 +64,7 @@ __PACKAGE__->config(
#USE_STRICT => 1,
INCLUDE_PATH => [ [% app %]->path_to('root', 'templates') ],
TEMPLATE_EXTENSION => '.html',
- ENCODING => 'utf8',
+ #ENCODING => 'UTF-8', # this is the default
);
=head1 NAME
@@ -90,4 +90,4 @@ it under the same terms as Perl itself.
=cut
-__PACKAGE__->meta->make_immutable();
+__PACKAGE__->meta->make_immutable;
View
97 lib/Catalyst/View/Tenjin.pm
@@ -1,13 +1,16 @@
package Catalyst::View::Tenjin;
+# ABSTRACT: Tenjin view class for Catalyst.
+
use Moose;
use namespace::autoclean;
use Data::Dump 'dump';
-use Tenjin;
+use Tenjin 0.070001;
-extends 'Catalyst::View';
+our $VERSION = "0.050";
+$VERSION = eval $VERSION;
-# ABSTRACT: Tenjin view class for Catalyst.
+extends 'Catalyst::View';
=head1 NAME
@@ -20,10 +23,10 @@ Catalyst::View::Tenjin - Tenjin view class for Catalyst.
# check your new view's configuration
__PACKAGE__->config(
- USE_STRICT => 1,
+ USE_STRICT => 1, # false by default
INCLUDE_PATH => [ MyApp->path_to('root', 'templates') ],
TEMPLATE_EXTENSION => '.html',
- ENCODING => 'utf8',
+ ENCODING => 'UTF-8', # this is the default
);
# render view from lib/MyApp.pm or lib/MyApp::C::SomeController.pm
@@ -101,30 +104,30 @@ sub COMPONENT {
};
unless (ref $config->{INCLUDE_PATH} eq 'ARRAY') {
- my @include_path = _coerce_paths( $config->{INCLUDE_PATH}, $config->{DELIMITER} );
- if ( !@include_path ) {
- my $base = Path::Class::dir( $c->config->{root}, 'base' );
- @include_path = ( "$c->config->{root}", "$base" );
+ $config->{INCLUDE_PATH} = [_coerce_paths($config->{INCLUDE_PATH}, $config->{DELIMITER})];
+ unless (scalar @{$config->{INCLUDE_PATH}}) {
+ my $base = Path::Class::dir($c->config->{root}, 'base');
+ $config->{INCLUDE_PATH} = [$c->config->{root}, $base];
}
- $config->{INCLUDE_PATH} = \@include_path;
}
- if ($c->debug && $config->{DUMP_CONFIG}) {
- $c->log->debug( "Tenjin Config: ", dump($config) );
- }
+ $c->log->debug("Tenjin Config: ".dump($config))
+ if $c->debug && $config->{DUMP_CONFIG};
my $self = $class->new($c, $config);
$self->config($config);
- if ($config->{USE_STRICT}) {
- $Tenjin::USE_STRICT = 1;
- }
- if ($config->{ENCODING}) {
- $Tenjin::ENCODING = $config->{ENCODING};
- }
+ $Tenjin::USE_STRICT = 1
+ if $config->{USE_STRICT};
+
+ $Tenjin::ENCODING = $config->{ENCODING}
+ if $config->{ENCODING};
- $self->{template} = Tenjin->new({ path => $config->{INCLUDE_PATH}, postfix => $config->{TEMPLATE_EXTENSION} });
+ $self->{template} = Tenjin->new({
+ path => $config->{INCLUDE_PATH},
+ postfix => $config->{TEMPLATE_EXTENSION},
+ });
return $self;
};
@@ -151,7 +154,7 @@ sub process {
my $output = $self->render($c, $template);
$c->response->content_type('text/html; charset=utf-8')
- unless ($c->response->content_type);
+ unless $c->response->content_type;
$c->response->body($output);
@@ -212,7 +215,8 @@ the C<$c>, C<$base> and C<$name> variables are omitted.
sub render {
my ($self, $c, $tmpl_name, $args) = @_;
- $c->log->debug(qq/Rendering template "$tmpl_name"/) if $c->debug;
+ $c->log->debug("Rendering template \"$tmpl_name\"")
+ if $c->debug;
my $vars = {
(ref $args eq 'HASH' ? %$args : %{ $c->stash() }),
@@ -239,12 +243,12 @@ sub template_vars {
my $cvar = $self->config->{CATALYST_VAR};
defined $cvar
- ? ( $cvar => $c )
- : (
- c => $c,
- base => $c->req->base,
- name => $c->config->{name}
- )
+ ? ( $cvar => $c )
+ : (
+ c => $c,
+ base => $c->req->base,
+ name => $c->config->{name}
+ );
}
=head2 _coerce_paths( $dlim )
@@ -253,17 +257,18 @@ sub template_vars {
sub _coerce_paths {
my ($paths, $dlim) = shift;
- return () if ( !$paths );
- return @{$paths} if ( ref $paths eq 'ARRAY' );
+ return () unless $paths;
+ return @{$paths} if ref $paths eq 'ARRAY';
# tweak delim to ignore C:/
- unless ( defined $dlim ) {
+ unless (defined $dlim) {
$dlim = ( $^O eq 'MSWin32' ) ? ':(?!\\/)' : ':';
}
+
return split( /$dlim/, $paths );
}
-__PACKAGE__->meta->make_immutable();
+__PACKAGE__->meta->make_immutable;
=head2 CONFIGURATION
@@ -427,26 +432,6 @@ use can use it with L<Catalyst::Plugin::Email>:
# Redirect or display a message
}
-=head1 CHANGES
-
-=over
-
-=item * 0.04: Created a helper module so views can be created with myapp_create.pl
-
-=item * 0.03: Updated for compatibility with the new and revised L<Tenjin> version.
-
-=item * 0.03: This module is now based on Moose.
-
-=back
-
-=head1 TODO
-
-=over
-
-=item * Create appropriate tests.
-
-=back
-
=head1 BUGS
Please report any bugs or feature requests to C<bug-tenjin at rt.cpan.org>,
@@ -458,7 +443,7 @@ on your bug as I make changes.
You can find documentation for this module with the perldoc command.
- perldoc Catalyst::View::Tenjin
+ perldoc Catalyst::View::Tenjin
You can also look for information at:
@@ -488,15 +473,15 @@ L<Tenjin>, L<Catalyst>, L<Catalyst::View::TT>
=head1 AUTHOR
-Ido Perlmuter E<lt>ido@ido50.netE<gt>. This module was adapted from
+Ido Perlmuter C<< <ido at ido50.net> >>. This module was adapted from
L<Catalyst::View::TT>, so most of the code and even the documentation
belongs to the authors of L<Catalyst::View::TT>.
-Development of this module is done with github at L<http://github.com/ido50/Catalyst-View-Tenjin>.
+Development of this module is tracked via github at L<http://github.com/ido50/Catalyst-View-Tenjin>.
=head1 LICENSE AND COPYRIGHT
-Copyright (c) 2009-2010 the aforementioned authors.
+Copyright (c) 2009-2011 the aforementioned authors.
This program is free software, you can redistribute it and/or modify it
under the same terms as Perl itself.
View
20 t/01-simple.t
@@ -0,0 +1,20 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More tests => 5;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use_ok('Catalyst::Test', 'TestApp');
+
+my $response;
+
+ok(($response = request("/"))->is_success, 'default request okay');
+is($response->content, "Amy, do you like magic?\n", 'default response okay');
+
+ok(($response = request("/encoding"))->is_success, 'encoding request okay');
+is($response->content, qq~<h1>העמוד בכתובת <a href="encoding" title="&lt;&quot;&gt;">encoding</a> אומר: מי שלא שותה לא משתין</h1>\n~, 'encoding response okay');
+
+done_testing();
View
15 t/lib/TestApp.pm
@@ -0,0 +1,15 @@
+package TestApp;
+
+use Moose;
+use namespace::autoclean;
+
+use Catalyst::Runtime 5.80;
+
+extends 'Catalyst';
+
+our $VERSION = '0.01';
+
+__PACKAGE__->config(name => 'TestApp');
+__PACKAGE__->setup;
+
+__PACKAGE__->meta->make_immutable;
View
34 t/lib/TestApp/Controller/Root.pm
@@ -0,0 +1,34 @@
+package TestApp::Controller::Root;
+
+use Moose;
+use namespace::autoclean;
+use utf8;
+use Encode;
+
+BEGIN { extends 'Catalyst::Controller' }
+
+__PACKAGE__->config(namespace => '');
+
+sub default : Private {
+ my ($self, $c) = @_;
+
+ $c->stash->{message} = "Amy, do you like magic?";
+ $c->stash->{template} = "default.html";
+}
+
+sub encoding : Local {
+ my ($self, $c) = @_;
+
+ $c->stash->{message} = "מי שלא שותה לא משתין";
+ $c->stash->{template} = "encoding.html";
+}
+
+sub end : Private {
+ my ($self, $c) = @_;
+
+ $c->forward( $c->view('Tenjin') );
+
+ $c->res->body(Encode::encode('UTF-8', $c->res->body));
+}
+
+__PACKAGE__->meta->make_immutable;
View
15 t/lib/TestApp/View/Tenjin.pm
@@ -0,0 +1,15 @@
+package TestApp::View::Tenjin;
+
+use Moose;
+use namespace::autoclean;
+
+extends 'Catalyst::View::Tenjin';
+
+__PACKAGE__->config(
+ #USE_STRICT => 1,
+ INCLUDE_PATH => [ TestApp->path_to('root') ],
+ TEMPLATE_EXTENSION => '.html',
+ #ENCODING => 'UTF-8', # this is the default
+);
+
+__PACKAGE__->meta->make_immutable;
View
1  t/lib/TestApp/root/default.html
@@ -0,0 +1 @@
+[== $message =]
View
1  t/lib/TestApp/root/encoding.html
@@ -0,0 +1 @@
+<h1>העמוד בכתובת <a href="[== $c->req->path =]" title="[= '<">' =]">[== $c->req->path =]</a> אומר: [== $message =]</h1>
View
13 t/manifest.t
@@ -1,13 +0,0 @@
-#!perl -T
-
-use strict;
-use warnings;
-use Test::More;
-
-unless ( $ENV{RELEASE_TESTING} ) {
- plan( skip_all => "Author tests not required for installation" );
-}
-
-eval "use Test::CheckManifest 0.9";
-plan skip_all => "Test::CheckManifest 0.9 required" if $@;
-ok_manifest( { filter => [ qr/\.git/ ] } );
Please sign in to comment.
Something went wrong with that request. Please try again.