remove blank lines from CSV responses

This commit is contained in:
Oliver Gorwits
2013-09-23 00:25:07 +01:00
parent 10ef067d6c
commit 25bc6d8f99

View File

@@ -68,6 +68,23 @@ hook 'before_template' => sub {
$Template::Stash::PRIVATE = undef; $Template::Stash::PRIVATE = undef;
}; };
# remove empty lines from CSV response
# this makes writing templates much more straightforward!
hook 'after' => sub {
my $r = shift; # a Dancer::Response
if ($r->content_type and $r->content_type eq 'text/comma-separated-values') {
my @newlines = ();
my @lines = split m/\n/, $r->content;
foreach my $line (@lines) {
push @newlines, $line if $line !~ m/^\s*$/;
}
$r->content(join "\n", @newlines);
}
};
get qr{^/(?:login(?:/denied)?)?} => sub { get qr{^/(?:login(?:/denied)?)?} => sub {
template 'index'; template 'index';
}; };