directory_listing 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/sinatra/directory_listing.rb +15 -8
- metadata +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
require 'sinatra/base'
|
|
2
|
-
|
|
3
2
|
require 'truncate'
|
|
4
3
|
require 'filesize'
|
|
5
4
|
require 'pathname'
|
|
@@ -32,6 +31,15 @@ require 'pathname'
|
|
|
32
31
|
# end
|
|
33
32
|
#
|
|
34
33
|
# == Options
|
|
34
|
+
#
|
|
35
|
+
# Options are passed in a hash:
|
|
36
|
+
#
|
|
37
|
+
# list({
|
|
38
|
+
# :stylesheet => "stylesheets/styles.css",
|
|
39
|
+
# :readme => "<a>Welcome!</a>"
|
|
40
|
+
# })
|
|
41
|
+
#
|
|
42
|
+
# Available options:
|
|
35
43
|
#
|
|
36
44
|
# stylesheet # a stylesheet that will be added to the <head> of the generated directory listing
|
|
37
45
|
# readme # an HTML string that will be appended at the footer of the generated directory listing
|
|
@@ -61,24 +69,22 @@ require 'pathname'
|
|
|
61
69
|
# text-align: left;
|
|
62
70
|
# }
|
|
63
71
|
|
|
64
|
-
|
|
65
72
|
module Sinatra
|
|
66
73
|
module Directory_listing
|
|
67
74
|
|
|
68
75
|
private
|
|
69
76
|
|
|
70
77
|
def m_time(file)
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
f = File.join(File.join(settings.public_folder, request.fullpath), file)
|
|
79
|
+
"\t<td>#{File.mtime(f).strftime $last_modified_format}</td>"
|
|
73
80
|
end
|
|
74
81
|
|
|
75
82
|
def size(file)
|
|
76
|
-
|
|
77
|
-
if File.directory?(
|
|
83
|
+
f = File.join(File.join(settings.public_folder, request.fullpath), file)
|
|
84
|
+
if File.directory?(f)
|
|
78
85
|
"\t<td>-</td>"
|
|
79
86
|
else
|
|
80
|
-
|
|
81
|
-
size = Filesize.from("#{File.stat(file).size} B").pretty
|
|
87
|
+
size = Filesize.from("#{File.stat(f).size} B").pretty
|
|
82
88
|
"\t<td>#{size}</td>"
|
|
83
89
|
end
|
|
84
90
|
end
|
|
@@ -132,6 +138,7 @@ module Sinatra
|
|
|
132
138
|
$filename_truncate_length = options[:filename_truncate_length]
|
|
133
139
|
|
|
134
140
|
html = "<html>\n<head>\n"
|
|
141
|
+
html << "<title>Index of #{request.path}</title>\n"
|
|
135
142
|
html << "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n"
|
|
136
143
|
if options[:stylesheet]
|
|
137
144
|
html << "<link rel=\"stylesheet\" type=\"text/css\" href=\"/#{options[:stylesheet].sub(/^[\/]*/,"")}\">\n"
|