Skip to content

Commit

Permalink
Add render_xls helper
Browse files Browse the repository at this point in the history
Use github Mojo's new app->helper to make a render_xls simplifying things.

Signed-off-by: Zak B. Elep <zakame@zakame.net>
  • Loading branch information
zakame committed Sep 15, 2010
1 parent 2bfee1f commit 341a618
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/Mojolicious/Plugin/WriteExcel.pm
Expand Up @@ -13,8 +13,14 @@ use MojoX::Renderer::WriteExcel;
sub register {
my ( $self, $app ) = @_;

$app->types->type( xls => 'application/vnd.ms-excel');
$app->types->type( xls => 'application/vnd.ms-excel' );
$app->renderer->add_handler( xls => MojoX::Renderer::WriteExcel->new );
$app->helper(
render_xls => sub {
my $self = shift;
$self->render( handler => 'xls', @_ );
}
);
}

1;
Expand Down
10 changes: 10 additions & 0 deletions t/DemoXls
Expand Up @@ -43,4 +43,14 @@ get '/demo_with_broken_column_width_1.xls' => sub {
);
};

get '/demo_with_app_helper.xls' => sub {
shift->render_xls(
result => [
[qw(foo bar baz)],
[qw(lol wut bbq)],
[qw(kick ass module)],
],
);
};

app->start;
5 changes: 4 additions & 1 deletion t/renderer.t
Expand Up @@ -3,7 +3,7 @@
use strict;
use warnings;

use Test::More tests => 12;
use Test::More tests => 15;
use Test::Mojo;

use File::Basename 'dirname';
Expand All @@ -27,3 +27,6 @@ $t->get_ok('/demo_with_column_width.xls')

$t->get_ok('/demo_with_broken_column_width_1.xls')
->status_is(500)->content_type_is('text/html');

$t->get_ok('/demo_with_app_helper.xls')
->status_is(200)->content_type_is('application/vnd.ms-excel');

0 comments on commit 341a618

Please sign in to comment.