[Catalyst-commits] r11695 - in Catalyst-View-TD/trunk: .
lib/Catalyst/Helper lib/Catalyst/Helper/View
theory at dev.catalyst.perl.org
theory at dev.catalyst.perl.org
Fri Oct 30 17:37:59 GMT 2009
Author: theory
Date: 2009-10-30 17:37:59 +0000 (Fri, 30 Oct 2009)
New Revision: 11695
Added:
Catalyst-View-TD/trunk/lib/Catalyst/Helper/TDClass.pm
Modified:
Catalyst-View-TD/trunk/
Catalyst-View-TD/trunk/lib/Catalyst/Helper/View/TD.pm
Log:
Created the TD helpers.
The View helper now creates a more thorough test example. And the helper
actually works.
I also added Catalyst::View::TDClass, which allows one to create new
TD template classes like so:
myapp_create.pl TDClass XHTML
And a new class will be created in `lib/MyApp/TD/XHTML.pm`.
Property changes on: Catalyst-View-TD/trunk
___________________________________________________________________
Name: svn:ignore
- META.yml
pm_to_blib
blib
inc
Makefile
README
+ META.yml
pm_to_blib
blib
inc
Makefile
Makefile.old
README
Added: Catalyst-View-TD/trunk/lib/Catalyst/Helper/TDClass.pm
===================================================================
--- Catalyst-View-TD/trunk/lib/Catalyst/Helper/TDClass.pm (rev 0)
+++ Catalyst-View-TD/trunk/lib/Catalyst/Helper/TDClass.pm 2009-10-30 17:37:59 UTC (rev 11695)
@@ -0,0 +1,115 @@
+package Catalyst::Helper::TDClass;
+
+use strict;
+
+=head1 Name
+
+Catalyst::Helper::TDClass - Helper for creating TD Template classes
+
+=head1 Synopsis
+
+ myapp_create.pl TDClass HTML
+
+=head1 Description
+
+Helper for creating TD Template classes.
+
+=head2 Methods
+
+=head3 mk_comptest
+
+Creates a test script for the view class.
+
+=cut
+
+=head3 mk_stuff
+
+Creates a template class.
+
+=cut
+
+sub mk_stuff {
+ my ( $self, $helper, $name ) = @_;
+
+ $name ||= $helper->{name};
+ my $class = "$helper->{app}::TD::$name";
+
+ my @path = split /::/, $class;
+ my $file = pop @path;
+ my $path = File::Spec->catdir( $helper->{base}, 'lib', @path );
+ $helper->mk_dir($path);
+ $file = File::Spec->catfile( $path, "$file.pm" );
+ local $helper->{file} = $file;
+ $helper->render_file( 'tmpl_class', $file, { class => $class, name => $name } );
+}
+
+=head1 SEE ALSO
+
+L<Catalyst::View::TD>, L<Catalyst::Helper::View::TD>
+
+=head1 Author
+
+David E. Wheeler <david at justatheory.com>
+
+=head1 License
+
+This library is free software. You can redistribute it and/or modify it under
+the same terms as perl itself.
+
+=cut
+
+1;
+
+__DATA__
+
+__tmpl_class__
+package [% class %];
+
+use strict;
+use warnings;
+use Template::Declare::Tags;
+
+# See Template::Declare docs for details on creating templates, which look
+# something like this.
+# template hello => sub {
+# my ($self, $vars) = @_;
+# html {
+# head { title { "Hello, $vars->{user}" } };
+# body { h1 { "Hello, $vars->{user}" } };
+# };
+# };
+
+=head1 NAME
+
+[% class %] - [% name %] templates for [% app %]
+
+=head1 DESCRIPTION
+
+[% name %] templates for [% app %].
+
+=head1 SEE ALSO
+
+=over
+
+[% IF vclass %]=item L<[% vclass %]>
+
+[% END %]=item L<[% app %]>
+
+=item L<Template::Declare>
+
+=item L<Catalyst::View::TD>
+
+=back
+
+=head1 AUTHOR
+
+[% author %]
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut
+
+1;
Modified: Catalyst-View-TD/trunk/lib/Catalyst/Helper/View/TD.pm
===================================================================
--- Catalyst-View-TD/trunk/lib/Catalyst/Helper/View/TD.pm 2009-10-29 19:42:06 UTC (rev 11694)
+++ Catalyst-View-TD/trunk/lib/Catalyst/Helper/View/TD.pm 2009-10-30 17:37:59 UTC (rev 11695)
@@ -18,14 +18,34 @@
=head3 mk_compclass
+Creates a view class and corresponding template class.
+
=cut
sub mk_compclass {
my ( $self, $helper ) = @_;
+ (my $tclass = $helper->{class}) =~ s/::View::/::TD::/;
my $file = $helper->{file};
- $helper->render_file( 'compclass', $file );
+ $helper->render_file( 'compclass', $file, { tclass => $tclass } );
+
+ # Create a template, too.
+ require Catalyst::Helper::TDClass;
+ local $helper->{vclass} = $helper->{class};
+ Catalyst::Helper::TDClass->mk_stuff( $helper );
}
+=head3 mk_comptest
+
+Creates a test script for the view class.
+
+=cut
+
+sub mk_comptest {
+ my ( $self, $helper ) = @_;
+ my $test = $helper->{test};
+ $helper->render_file( 'comptest', $test );
+}
+
=head1 SEE ALSO
L<Catalyst::View::TD>, L<Catalyst::Manual>, L<Catalyst::Test>,
@@ -47,10 +67,6 @@
__DATA__
__compclass__
-[% PERL %]
-(my $tclass = $stash->get('class')) =~ s/::View::/::TD::/;
-$stash->set(tclass => $tclass );
-[% END %]
package [% class %];
use strict;
@@ -58,21 +74,23 @@
use parent 'Catalyst::View::TD';
-# If roots is not specified, Catalyst::View::TD will automatically load all
-# modules below the [% class %]::* namespace. It's simplest to create
-# your template modules there. See the Template::Declare documentation for a
+# Unless auto_alias is false, Catalyst::View::TD will automatically load all
+# modules below the [% tclass %] namespace and alias their
+# templates into [% tclass %]. It's simplest to create your
+# template classes there. See the Template::Declare documentation for a
# complete description of its init() parameters, all of which are supported
# here.
__PACKAGE__->config(
# dispatch_to => [qw([% tclass %])],
+ # auto_alias => 1,
# postprocessor => sub { ... },
# around_template => sub { ... },
);
=head1 NAME
-[% class %] - TD View for [% app %]
+[% class %] - [% name %] View for [% app %]
=head1 DESCRIPTION
@@ -95,3 +113,74 @@
=cut
1;
+__comptest__
+use strict;
+use warnings;
+use Test::More tests => 3;
+# use Test::XPath;
+
+BEGIN {
+ use_ok '[% class %]' or die;
+ use_ok '[% app %]' or die;
+}
+
+ok my $view = [% app %]->view('[% name %]'), 'Get [% name %] view object';
+
+# ok my $output = $view->render(undef, 'hello', { user => 'Theory' }),
+# 'Render the "hello" template';
+
+# Test output using Test::XPath or similar.
+# my $tx = Test::XPath->new( xml => $output, is_html => 1);
+# $tx->ok('/html', 'Should have root html element');
+# $tx->is('/html/head/title', 'Hello, Theory', 'Title should be correct');
+__tmpl_class__
+package [% class %];
+
+use strict;
+use warnings;
+use Template::Declare::Tags;
+
+# See Template::Declare docs for details on creating templates, which look
+# something like this.
+# template hello => sub {
+# my ($self, $vars) = @_;
+# html {
+# head { title { "Hello, $vars->{user}" } };
+# body { h1 { "Hello, $vars->{user}" } };
+# };
+# };
+
+=head1 NAME
+
+[% class %] - [% name %] templates for [% app %]
+
+=head1 DESCRIPTION
+
+TD templates for [% app %].
+
+=head1 SEE ALSO
+
+=over
+
+[% IF vclass %]=item L<[% vclass %]>
+
+[% END %]=item L<[% app %]>
+
+=item L<Template::Declare>
+
+=item L<Catalyst::View::TD>
+
+=back
+
+=head1 AUTHOR
+
+[% author %]
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut
+
+1;
More information about the Catalyst-commits
mailing list