Catalyst-Plugin-Static-Simple-ButMaintained
view release on metacpan or search on metacpan
t/lib/TestApp/root/files/empty.txt
t/lib/TestApp/root/files/err.omg
t/lib/TestApp/root/files/static.css
t/lib/TestApp/root/ignored/bad.gif
t/lib/TestApp/root/ignored/index.html
t/lib/TestApp/root/ignored/static.css
t/lib/TestApp/root/ignored/tmpl.tt
t/lib/TestApp/root/images/bad.gif
t/lib/TestApp/root/images/catalyst.png
t/lib/TestApp/root/incpath/incpath.css
t/lib/TestApp/root/overlay/o-ignored/bad.gif
t/lib/TestApp/root/overlay/o-ignored/index.html
t/lib/TestApp/root/overlay/o-ignored/static.css
t/lib/TestApp/root/overlay/o-ignored/tmpl.tt
t/lib/TestApp/root/overlay/overlay.jpg
lib/Catalyst/Plugin/Static/Simple/ButMaintained.pm view on Meta::CPAN
You may specify a list of directories in which to search for your static
files. The directories will be searched in order and will return the
first file found. Note that your root directory is B<not> automatically
added to the search path when you specify an C<include_path>. You should
use C<MyApp-E<gt>config-E<gt>{root}> to add it.
MyApp->config(
static => {
include_path => [
'/path/to/overlay',
\&incpath_generator,
MyApp->config->{root},
],
},
);
With the above setting, a request for the file C</images/logo.jpg> will search
for the following files, returning the first one found:
/path/to/overlay/images/logo.jpg
/dynamic/path/images/logo.jpg
/your/app/home/root/images/logo.jpg
The include path can contain a subroutine reference to dynamically return a
list of available directories. This method will receive the C<$c> object as a
parameter and should return a reference to a list of directories. Errors can
be reported using C<die()>. This method will be called every time a file is
requested that appears to be a static file (i.e. it has an extension).
For example:
lib/Catalyst/Plugin/Static/Simple/ButMaintained.pm view on Meta::CPAN
MyApp->config(
static => {
ignore_dirs => [ qw/tmpl css/ ],
},
);
For example, if combined with the above C<include_path> setting, this
C<ignore_dirs> value will ignore the following directories if they exist:
/path/to/overlay/tmpl
/path/to/overlay/css
/dynamic/path/tmpl
/dynamic/path/css
/your/app/home/root/tmpl
/your/app/home/root/css
=head2 Custom MIME types
To override or add to the default MIME types set by the L<MIME::Types>
module, you may enter your own extension to MIME type mapping.
t/06include_path.t view on Meta::CPAN
use warnings;
use FindBin;
use lib "$FindBin::Bin/lib";
use Test::More tests => 6;
use Catalyst::Test 'TestApp';
# test altenate root dirs
TestApp->config->{'Plugin::Static::Simple::ButMaintained'}->{include_path} = [
TestApp->config->{root} . '/overlay',
\&TestApp::incpath_generator,
TestApp->config->{root},
];
# test overlay dir
ok( my $res = request('http://localhost/overlay.jpg'), 'request ok' );
is( $res->content_type, 'image/jpeg', 'overlay path ok' );
# test incpath_generator
ok( $res = request('http://localhost/incpath.css'), 'request ok' );
is( $res->content_type, 'text/css', 'incpath coderef ok' );
# test passthrough to root
ok( $res = request('http://localhost/images/bad.gif'), 'request ok' );
is( $res->content_type, 'image/gif', 'root path ok' );
t/07mime_types.t view on Meta::CPAN
# test custom MIME types
TestApp->config->{'Plugin::Static::Simple::ButMaintained'}->{mime_types} = {
omg => 'holy/crap',
gif => 'patents/are-evil',
};
ok( my $res = request('http://localhost/files/err.omg'), 'request ok' );
is( $res->content_type, 'holy/crap', 'custom MIME type ok' );
ok( $res = request('http://localhost/files/bad.gif'), 'request ok' );
is( $res->content_type, 'patents/are-evil', 'custom MIME type overlay ok' );
t/10ignore_dirs.t view on Meta::CPAN
use lib "$FindBin::Bin/lib";
use Test::More tests => 6;
use Catalyst::Test 'TestApp';
# test ignoring directories
TestApp->config->{'Plugin::Static::Simple::ButMaintained'}->{ignore_dirs} = [ qw/ignored o-ignored files/ ];
# test altenate root dirs
TestApp->config->{'Plugin::Static::Simple::ButMaintained'}->{include_path} = [
TestApp->config->{root} . '/overlay',
TestApp->config->{root},
];
ok( my $res = request('http://localhost/ignored/bad.gif'), 'request ok' );
is( $res->content, 'default', 'ignored directory `ignored` ok' );
ok( $res = request('http://localhost/files/static.css'), 'request ok' );
is( $res->content, 'default', 'ignored directory `files` ok' );
ok( $res = request('http://localhost/o-ignored/bad.gif'), 'request ok' );
is( $res->content, 'default', 'ignored overlay directory ok' );
( run in 3.386 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )