[Bps-public-commit] plack-app-template-declare branch, master, updated. 650adcee3fdc96dbdebf072ce06d788374c5f8df
sartak at bestpractical.com
sartak at bestpractical.com
Wed Dec 23 10:34:35 EST 2009
The branch, master has been updated
via 650adcee3fdc96dbdebf072ce06d788374c5f8df (commit)
via c69d877f34d846e0175460aa70755abdec876004 (commit)
via 9323a9bfaf64dd2f38637d8cd2abad2e9f207d70 (commit)
via b242891e2fbd6ddcfd2bdcb2bb1cc5d60341c2b9 (commit)
via a48adb9c3d5b9f82aa60b9b608d3d3b20bf03519 (commit)
via 09d41bd219d2e41d1e83e32e6145b7c3e37cccb3 (commit)
from e4b2761c444a35db2cae052e76765c8c570d5055 (commit)
Summary of changes:
.gitignore | 11 ++++++
Makefile.PL | 13 +++++++
lib/Plack/App/Template/Declare.pm | 73 +++++++++++++++++++++++++++++++++++++
3 files changed, 97 insertions(+), 0 deletions(-)
create mode 100644 Makefile.PL
create mode 100644 lib/Plack/App/Template/Declare.pm
- Log -----------------------------------------------------------------
commit 09d41bd219d2e41d1e83e32e6145b7c3e37cccb3
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Tue Dec 22 09:32:42 2009 -0500
First cut
diff --git a/.gitignore b/.gitignore
index e69de29..d917e94 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1,11 @@
+META.yml
+Makefile
+Makefile.old
+blib/
+inc/
+*.sw[po]
+pm_to_blib
+MANIFEST
+MANIFEST.bak
+SIGNATURE
+cover_db/
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644
index 0000000..2316977
--- /dev/null
+++ b/Makefile.PL
@@ -0,0 +1,13 @@
+use inc::Module::Install;
+
+name 'Plack-App-Template-Declare';
+all_from 'lib/Plack/App/Template/Declare.pm';
+repository 'http://github.com/bestpractical/plack-app-template-declare';
+
+requires 'Template::Declare';
+requires 'Plack';
+
+build_requires 'Test::Exception';
+
+WriteAll;
+
diff --git a/lib/Plack/App/Template/Declare.pm b/lib/Plack/App/Template/Declare.pm
new file mode 100644
index 0000000..66df150
--- /dev/null
+++ b/lib/Plack/App/Template/Declare.pm
@@ -0,0 +1,55 @@
+package Plack::App::Template::Declare;
+use strict;
+use warnings;
+use parent 'Plack::Component';
+use Plack::Util;
+use Template::Declare;
+
+use Plack::Util::Accessor qw(view args);
+
+sub should_handle {
+ my ($self, $path) = @_;
+ return Template::Declare->has_template($path);
+}
+
+sub call {
+ my $self = shift;
+ my $env = shift;
+
+ my $path = $env->{PATH_INFO};
+
+ if (!$self->should_handle($path)) {
+ return $self->return_404;
+ }
+
+ return $self->serve_path($env, $path);
+}
+
+sub args_for_show {
+ my $self = shift;
+ my $env = shift;
+
+ return @{ $self->args };
+}
+
+sub serve_path {
+ my $self = shift;
+ my $env = shift;
+ my $path = shift;
+
+ my $body = Template::Declare->show_template($path, $self->args_for_show($env));
+
+ return [
+ 200,
+ [],
+ [$body],
+ ];
+}
+
+sub return_404 {
+ my $self = shift;
+ return [404, ['Content-Type' => 'text/plain'], ['not found']];
+}
+
+1;
+
commit a48adb9c3d5b9f82aa60b9b608d3d3b20bf03519
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Tue Dec 22 09:34:39 2009 -0500
Initialize TD
diff --git a/lib/Plack/App/Template/Declare.pm b/lib/Plack/App/Template/Declare.pm
index 66df150..6686c7e 100644
--- a/lib/Plack/App/Template/Declare.pm
+++ b/lib/Plack/App/Template/Declare.pm
@@ -7,6 +7,19 @@ use Template::Declare;
use Plack::Util::Accessor qw(view args);
+sub new {
+ my $self = shift->SUPER::new(@_);
+ $self->init;
+ return $self;
+}
+
+sub init {
+ my $self = shift;
+ my $view = $self->view;
+ $view = [$view] if !ref($view);
+ Template::Declare->init(dispatch_to => $view);
+}
+
sub should_handle {
my ($self, $path) = @_;
return Template::Declare->has_template($path);
commit b242891e2fbd6ddcfd2bdcb2bb1cc5d60341c2b9
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Tue Dec 22 09:35:58 2009 -0500
It's called show not show_template
diff --git a/lib/Plack/App/Template/Declare.pm b/lib/Plack/App/Template/Declare.pm
index 6686c7e..d931d3d 100644
--- a/lib/Plack/App/Template/Declare.pm
+++ b/lib/Plack/App/Template/Declare.pm
@@ -50,7 +50,7 @@ sub serve_path {
my $env = shift;
my $path = shift;
- my $body = Template::Declare->show_template($path, $self->args_for_show($env));
+ my $body = Template::Declare->show($path, $self->args_for_show($env));
return [
200,
commit 9323a9bfaf64dd2f38637d8cd2abad2e9f207d70
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Tue Dec 22 09:36:20 2009 -0500
Handle no args a little better
diff --git a/lib/Plack/App/Template/Declare.pm b/lib/Plack/App/Template/Declare.pm
index d931d3d..5ba87bc 100644
--- a/lib/Plack/App/Template/Declare.pm
+++ b/lib/Plack/App/Template/Declare.pm
@@ -42,7 +42,7 @@ sub args_for_show {
my $self = shift;
my $env = shift;
- return @{ $self->args };
+ return @{ $self->args || [] };
}
sub serve_path {
commit c69d877f34d846e0175460aa70755abdec876004
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Tue Dec 22 10:14:37 2009 -0500
Pass the environment to the templates
diff --git a/lib/Plack/App/Template/Declare.pm b/lib/Plack/App/Template/Declare.pm
index 5ba87bc..89f3727 100644
--- a/lib/Plack/App/Template/Declare.pm
+++ b/lib/Plack/App/Template/Declare.pm
@@ -42,7 +42,7 @@ sub args_for_show {
my $self = shift;
my $env = shift;
- return @{ $self->args || [] };
+ return ($env, @{ $self->args || [] });
}
sub serve_path {
commit 650adcee3fdc96dbdebf072ce06d788374c5f8df
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Tue Dec 22 10:23:01 2009 -0500
Allow passing an actual request object if desired
diff --git a/lib/Plack/App/Template/Declare.pm b/lib/Plack/App/Template/Declare.pm
index 89f3727..d1162e2 100644
--- a/lib/Plack/App/Template/Declare.pm
+++ b/lib/Plack/App/Template/Declare.pm
@@ -5,7 +5,7 @@ use parent 'Plack::Component';
use Plack::Util;
use Template::Declare;
-use Plack::Util::Accessor qw(view args);
+use Plack::Util::Accessor qw(view args pass_request);
sub new {
my $self = shift->SUPER::new(@_);
@@ -42,6 +42,11 @@ sub args_for_show {
my $self = shift;
my $env = shift;
+ if ($self->pass_request) {
+ require Plack::Request;
+ $env = Plack::Request->new($env);
+ }
+
return ($env, @{ $self->args || [] });
}
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list