From e2e6361cc4d0c389821a4447bee23ae4f08b0d30 Mon Sep 17 00:00:00 2001 From: Dave Cross Date: Tue, 6 Jun 2023 12:29:40 +0100 Subject: [PATCH] Use methods for HTML/CSS so it's easier to subclass. --- lib/Plack/App/Directory.pm | 71 ++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/lib/Plack/App/Directory.pm b/lib/Plack/App/Directory.pm index 48443ca09..8c5dccfed 100644 --- a/lib/Plack/App/Directory.pm +++ b/lib/Plack/App/Directory.pm @@ -10,33 +10,54 @@ use URI::Escape; use Plack::Request; # Stolen from rack/directory.rb -my $dir_file = "%s%s%s%s"; -my $dir_page = < - %s - - + + +

%s

+
+ + + + + + + +%s +
NameSizeTypeLast Modified
+
+ + +PAGE +} + +sub css { + return < - -

%s

-
- - - - - - - -%s -
NameSizeTypeLast Modified
-
- -PAGE +CSS +} sub should_handle { my($self, $file) = @_; @@ -99,9 +120,9 @@ sub serve_path { my $path = Plack::Util::encode_html("Index of $env->{PATH_INFO}"); my $files = join "\n", map { my $f = $_; - sprintf $dir_file, map Plack::Util::encode_html($_), @$f; + sprintf $self->file_html, map Plack::Util::encode_html($_), @$f; } @files; - my $page = sprintf $dir_page, $path, $path, $files; + my $page = sprintf $self->dir_html, $path, $self->css, $path, $files; return [ 200, ['Content-Type' => 'text/html; charset=utf-8'], [ $page ] ]; }