Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add multi-docroot support

  • Loading branch information...
commit 85afbb136ce1313a0c7693104478a5b0f2682b30 1 parent fa951d8
@jrockway authored
View
5 bin/template-server
@@ -11,7 +11,7 @@ template-server - run App::TemplateServer
=head1 SYNOPSIS
- template-server [--docroot /path/to/templates]
+ template-server [--docroot /path/to/templates]+
[--port 4000]
[--datafile /path/to/data.yml]
[--provider App::TemplateServer::Provider::TT]
@@ -19,5 +19,6 @@ template-server - run App::TemplateServer
=head1 DESCRIPTION
This script starts up an C<App::TemplateServer> server. Given a
-docroot, it will serve rendered HTML templates in that directory. See
+docroot, it will serve rendered HTML templates in that directory (or
+directories if you specify C<--docroot> more than once). See
L<App::TemplateServer> for all the details.
View
8 lib/App/TemplateServer.pm
@@ -31,11 +31,15 @@ has 'port' => (
default => '4000',
);
+coerce 'ArrayRef[Path::Class::Dir]'
+ => as 'ArrayRef[Str]'
+ => via { [map { Path::Class::dir($_) } @$_] };
+
has 'docroot' => (
is => 'ro',
- isa => Dir,
+ isa => 'ArrayRef[Path::Class::Dir]',
+ default => sub { [$ENV{PWD}] },
coerce => 1,
- default => sub { $ENV{PWD} },
lazy => 1,
);
View
15 lib/App/TemplateServer/Provider.pm
@@ -1,12 +1,13 @@
package App::TemplateServer::Provider;
use Moose::Role;
-use MooseX::Types::Path::Class qw(Dir);
+use MooseX::Types::Path::Class;
has 'docroot' => (
- is => 'ro',
- isa => Dir,
- required => 1,
- coerce => 1,
+ is => 'ro',
+ isa => 'ArrayRef[Path::Class::Dir]',
+ required => 1,
+ coerce => 1,
+ auto_deref => 1,
);
requires 'list_templates';
@@ -32,8 +33,8 @@ This role provides the following attributes:
=head2 docroot
-This is the directory where your templates that you are "providing"
-live. It is required.
+This is a list of directories where your templates that you are
+"providing" live.
=head1 REQUIRED METHODS
View
18 lib/App/TemplateServer/Provider/TT.pm
@@ -10,7 +10,7 @@ with 'App::TemplateServer::Provider';
has 'engine' => (
is => 'ro',
isa => 'Template',
- default => sub { Template->new({ INCLUDE_PATH => shift->docroot }) },
+ default => sub { Template->new({ INCLUDE_PATH => [shift->docroot] }) },
lazy => 1,
);
@@ -25,16 +25,18 @@ has 'engine' => (
#);
method list_templates {
- my $docroot = $self->docroot;
+ my @docroot = $self->docroot;
my @files;
#my $file_filter = $self->file_filter;
- find(sub {
- my $name = $File::Find::name;
- push @files, File::Spec->abs2rel($name, $docroot)
- if -f $name; # && $name =~ /$file_filter/;
- },
- $docroot);
+ for my $root (@docroot){
+ find(sub {
+ my $name = $File::Find::name;
+ push @files, File::Spec->abs2rel($name, $root)
+ if -f $name; # && $name =~ /$file_filter/;
+ },
+ $root);
+ }
return @files;
};
Please sign in to comment.
Something went wrong with that request. Please try again.