Catalyst-Plugin-Static-Simple
view release on metacpan or search on metacpan
t/09ignore_ext.t
t/10ignore_dirs.t
t/11serve_static.t
t/12check_error_scope.t
t/13no_include_path.t
t/14deprecated.t
t/20debug.t
t/lib/IncTestApp.pm
t/lib/IncTestApp/Controller/Root.pm
t/lib/IncTestApp/root/images/bad.gif
t/lib/IncTestApp/root/overlay/overlay.jpg
t/lib/TestApp.pm
t/lib/TestApp/Controller/Root.pm
t/lib/TestApp/root/always-static/test
t/lib/TestApp/root/always-static/test.html
t/lib/TestApp/root/css/static.css
t/lib/TestApp/root/files/bad.gif
t/lib/TestApp/root/files/empty.txt
t/lib/TestApp/root/files/err.unknown
't/lib/TestApp/root/files/space file.txt'
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
t/lib/TestLog.pm
xt/02pod.t
xt/03podcoverage.t
xt/notabs.t
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
README README file (added by Distar)
LICENSE LICENSE file (added by Distar)
Including additional directories
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 not automatically
added to the search path when you specify an "include_path". You should
use "MyApp->config->{root}" to add it.
MyApp->config(
'Plugin::Static::Simple' => {
include_path => [
'/path/to/overlay',
\&incpath_generator,
MyApp->config->{root},
],
},
);
With the above setting, a request for the file "/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
object as a parameter and should return a reference to a list of
directories. Errors can be reported using "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).
MyApp->config(
'Plugin::Static::Simple' => {
ignore_dirs => [ qw/tmpl css/ ],
},
);
For example, if combined with the above "include_path" setting, this
"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
Custom MIME types
To override or add to the default MIME types set by the MIME::Types
module, you may enter your own extension to MIME type mapping.
MyApp->config(
lib/Catalyst/Plugin/Static/Simple.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(
'Plugin::Static::Simple' => {
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.pm view on Meta::CPAN
MyApp->config(
'Plugin::Static::Simple' => {
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'}->{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'}->{mime_types} = {
unknown => 'holy/crap',
gif => 'patents/are-evil',
};
ok( my $res = request('http://localhost/files/err.unknown'), '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'}->{ignore_dirs} = [ qw/ignored o-ignored files/ ];
# test altenate root dirs
TestApp->config->{'Plugin::Static::Simple'}->{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' );
t/14deprecated.t view on Meta::CPAN
use FindBin;
use lib "$FindBin::Bin/lib";
use Test::More tests => 5;
use Catalyst::Test 'IncTestApp';
is( $TestLog::logged, "Deprecated 'static' config key used, please use the key 'Plugin::Static::Simple' instead",
"Got warning" );
# test overlay dir
ok( my $res = request('http://localhost/overlay.jpg'), 'request ok' );
is( $res->content_type, 'image/jpeg', 'overlay path 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/lib/IncTestApp.pm view on Meta::CPAN
IncTestApp->config(
name => 'TestApp',
debug => 1,
static => {
include_path => [
IncTestApp->config->{root},
]
},
'Plugin::Static::Simple' => {
include_path => [
IncTestApp->config->{root} . '/overlay',
]
},
);
IncTestApp->log( TestLog->new );
my @plugins = qw/Static::Simple/;
# load the SubRequest plugin if available
eval {
require Catalyst::Plugin::SubRequest;
( run in 2.294 seconds using v1.01-cache-2.11-cpan-d8267643d1d )