[Jifty-commit] r2521 - in Template-Declare: lib/Template
lib/Template/Declare t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Wed Jan 17 23:29:13 EST 2007
Author: jesse
Date: Wed Jan 17 23:29:12 2007
New Revision: 2521
Added:
Template-Declare/t/99-pod-coverage.t
Template-Declare/t/99-pod.t
Modified:
Template-Declare/ (props changed)
Template-Declare/lib/Template/Declare.pm
Template-Declare/lib/Template/Declare/Tags.pm
Log:
r21079 at hualien: jesse | 2007-01-17 23:28:57 -0500
* More docs!
* pod testing
Modified: Template-Declare/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/lib/Template/Declare.pm (original)
+++ Template-Declare/lib/Template/Declare.pm Wed Jan 17 23:29:12 2007
@@ -24,26 +24,120 @@
=head1 NAME
-Template::Declare
+Template::Declare - Perlish declarative templates
-=head1 DESCRIPTION
+=head1 SYNOPSIS
-C<Template::Declare> is a prototype declarative code-based HTML
-templating system. Yes. Another one. There are many others like it,
-but this one is ours. It's designed to allow template libraries to be
-composed, mixed in and inherited. The code isn't (yet) pretty nor is
-it in any way optimized. It's not well enough tested, either.
+C<Template::Declare> is a pure-perl declarative HTML templating system.
-In the coming weeks, months and years, Template::Declare we will extend it
-to support all the things we've designed it to do.
+Yes. Another one. There are many others like it, but this one is ours.
-=head1 BUGS
+A few key features and buzzwords
-Crawling all over, baby. Be very, very careful. This code is so cutting edge, it can only be fashioned from carbon nanotubes.
+=over
+=item All templates are 100% pure perl code
-=cut
+=item Simple declarative syntax
+
+=item No angle brackets
+
+=item Mixins
+
+=item Inheritance
+
+=item Public and private templates
+
+=back
+
+
+=head1 USAGE
+
+
+=head2 Basic usage
+
+ package MyApp::Templates;
+ use Template::Declare::Tags;
+ use base 'Template::Declare';
+
+ template simple => sub {
+ html {
+ head {}
+ body {
+ p {'Hello, world wide web!'};
+ }
+ }
+ };
+
+ package main;
+ use Template::Declare;
+ Template::Declare->init( roots => ['MyApp::Templates']);
+ print Template::Declare->show( 'simple');
+
+ # Output:
+ #
+ #
+ # <html>
+ # <head></head>
+ # <body>
+ # <p>Hello, world wide web!
+ # </p>
+ # </body>
+ # </html>
+
+
+=head2 A slightly more advanced example
+
+In this example, we'll show off how to set attributes on HTML tags, how to call other templates and how to declare a I<private> template that can't be called directly.
+
+ package MyApp::Templates;
+ use Template::Declare::Tags;
+ use base 'Template::Declare';
+
+ private template 'header' => sub {
+ head {
+ title { 'This is a webpage'};
+ meta { attr { generator => "This is not your father's frontpage"}}
+ }
+ };
+
+ template simple => sub {
+ html {
+ show('header');
+ body {
+ p { attr { class => 'greeting'};
+ 'Hello, world wide web!'};
+ }
+ }
+ };
+
+ package main;
+ use Template::Declare;
+ Template::Declare->init( roots => ['MyApp::Templates']);
+ print Template::Declare->show( 'simple');
+
+ # Output:
+ #
+ # <html>
+ # <head>
+ # <title>This is a webpage
+ # </title>
+ # <meta generator="This is not your father's frontpage" />
+ # </head>
+ # <body>
+ # <p class="greeting">Hello, world wide web!
+ # </p>
+ # </body>
+ # </html>
+
+
+=head2 Multiple template roots (search paths)
+
+=head2 Inheritance
+=head2 Aliasing
+
+=head1 METHODS
=head2 init
@@ -67,6 +161,18 @@
}
+=head2 show TEMPLATE_NAME
+
+Call C<show> with a C<template_name> and C<Template::Declare> will render that template and return the content as a scalar.
+
+=cut
+
+sub show {
+ my $class = shift;
+ my $template = shift;
+ Template::Declare::Tags::show($template);
+
+}
=head2 alias
@@ -127,7 +233,12 @@
}
-=head2 has_template
+=head2 has_template PACKAGE TEMPLATE_NAME SHOW_PRIVATE
+
+Takes a package, template name and a boolean. The boolean determines whether to show private templates.
+
+Returns a reference to the template's code if found. Otherwise,
+returns undef.
=cut
@@ -159,13 +270,15 @@
=head2 resolve_template TEMPLATE_PATH INCLUDE_PRIVATE_TEMPLATES
-Turns a template path (C<TEMPLATE_PATH) into a C<CODEREF>. If the boolean
-C<INCLUDE_PRIVATE_TEMPLATES> is true, resolves private template in
-addition to public ones.
-
-First it looks through all the valid Template::Declare roots. For each root, it looks to see
-if the root has a template called $template_name directly (or via an C<import> statement). Then it looks
-to see if there are any C<alias>ed paths for the root with prefixes that match the template we're looking for.
+Turns a template path (C<TEMPLATE_PATH>) into a C<CODEREF>. If the
+boolean C<INCLUDE_PRIVATE_TEMPLATES> is true, resolves private template
+in addition to public ones.
+
+First it looks through all the valid Template::Declare roots. For each
+root, it looks to see if the root has a template called $template_name
+directly (or via an C<import> statement). Then it looks to see if there
+are any L</alias>ed paths for the root with prefixes that match the
+template we're looking for.
=cut
@@ -225,8 +338,7 @@
my $template_name = shift;
my $code = shift;
push @{ __PACKAGE__->templates()->{$class} }, $template_name;
- _register_template( $class,
- _template_name_to_sub($template_name), $code )
+ _register_template( $class, _template_name_to_sub($template_name), $code )
}
@@ -250,4 +362,24 @@
}
+
+
+=head1 BUGS
+
+Crawling all over, baby. Be very, very careful. This code is so cutting edge, it can only be fashioned from carbon nanotubes.
+
+Some specific bugs and design flaws that we'd love to see fixed
+
+=over
+
+=item Output isn't streamy.
+
+=back
+
+If you run into bugs or misfeatures, please report them to
+C<bug-template-declare at rt.cpan.org>.
+
+
+=cut
+
1;
Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm (original)
+++ Template-Declare/lib/Template/Declare/Tags.pm Wed Jan 17 23:29:12 2007
@@ -202,7 +202,7 @@
return $more_code ? $more_code->() : '';
}
-=head2 show [$class or $object] [$template_name or $template_coderef]
+=head2 show [$template_name or $template_coderef]
C<show> displays templates.
Added: Template-Declare/t/99-pod-coverage.t
==============================================================================
--- (empty file)
+++ Template-Declare/t/99-pod-coverage.t Wed Jan 17 23:29:12 2007
@@ -0,0 +1,12 @@
+use Test::More;
+eval "use Test::Pod::Coverage 1.00";
+plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@;
+all_pod_coverage_ok( );
+
+# Workaround for dumb bug (fixed in 5.8.7) where Test::Builder thinks that
+# certain "die"s that happen inside evals are not actually inside evals,
+# because caller() is broken if you turn on $^P like Module::Refresh does
+#
+# (I mean, if we've gotten to this line, then clearly the test didn't die, no?)
+Test::Builder->new->{Test_Died} = 0;
+
Added: Template-Declare/t/99-pod.t
==============================================================================
--- (empty file)
+++ Template-Declare/t/99-pod.t Wed Jan 17 23:29:12 2007
@@ -0,0 +1,5 @@
+use Test::More;
+eval "use Test::Pod 1.00";
+plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
+all_pod_files_ok();
+
More information about the Jifty-commit
mailing list