directory_listing 0.1.2 → 0.1.3
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 +50 -52
- metadata +4 -3
|
@@ -44,7 +44,7 @@ require 'uri'
|
|
|
44
44
|
#
|
|
45
45
|
# stylesheet # a stylesheet that will be added to the <head> of the generated directory listing
|
|
46
46
|
# readme # an HTML string that will be appended at the footer of the generated directory listing
|
|
47
|
-
# should_list_invisibles # whether the directory listing should include invisibles (dotfiles) - "yes" or "no"
|
|
47
|
+
# should_list_invisibles # whether the directory listing should include invisibles (dotfiles) - "yes" or "no", defaults to "no"
|
|
48
48
|
# last_modified_format # format for last modified date (http://www.ruby-doc.org/core-2.0/Time.html) - defaults to "%Y-%m-%d %H:%M:%S"
|
|
49
49
|
# filename_truncate_length # (integer) length to truncate file names to - defaults to 40
|
|
50
50
|
#
|
|
@@ -73,6 +73,49 @@ require 'uri'
|
|
|
73
73
|
module Sinatra
|
|
74
74
|
module Directory_listing
|
|
75
75
|
|
|
76
|
+
def list(o={})
|
|
77
|
+
options = {
|
|
78
|
+
:should_list_invisibles => "no",
|
|
79
|
+
:last_modified_format => "%Y-%m-%d %H:%M:%S",
|
|
80
|
+
:filename_truncate_length => 40,
|
|
81
|
+
:stylesheet => "",
|
|
82
|
+
:readme => ""
|
|
83
|
+
}.merge(o)
|
|
84
|
+
|
|
85
|
+
$should_list_invisibles = options[:should_list_invisibles]
|
|
86
|
+
$last_modified_format = options[:last_modified_format]
|
|
87
|
+
$filename_truncate_length = options[:filename_truncate_length]
|
|
88
|
+
|
|
89
|
+
html = "<html>\n<head>\n"
|
|
90
|
+
html << "<title>Index of #{URI.unescape(request.path)}</title>\n"
|
|
91
|
+
html << "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n"
|
|
92
|
+
if options[:stylesheet]
|
|
93
|
+
html << "<link rel=\"stylesheet\" type=\"text/css\" href=\"/#{options[:stylesheet].sub(/^[\/]*/,"")}\">\n"
|
|
94
|
+
end
|
|
95
|
+
html << "</head>\n<body>\n"
|
|
96
|
+
html << "<h1>Index of #{URI.unescape(request.path)}</h1>\n"
|
|
97
|
+
if URI.unescape(request.path) != "/"
|
|
98
|
+
html << "<a href='#{Pathname.new(URI.unescape(request.path)).parent}'>← Parent directory</a><br><br>"
|
|
99
|
+
else
|
|
100
|
+
html << "<a>Root directory</a><br><br>"
|
|
101
|
+
end
|
|
102
|
+
html << "<table>\n"
|
|
103
|
+
html << "\t<tr>\n\t\t<th>File</th>\n\t\t<th>Last modified</th>\n\t\t<th>Size</th>\n\t</tr>\n"
|
|
104
|
+
files = Array.new
|
|
105
|
+
Dir.foreach(File.join(settings.public_folder, URI.unescape(request.path)), &files.method(:push))
|
|
106
|
+
if files == [".", ".."]
|
|
107
|
+
html << "\t<tr>\n\t\t<th>No files.</th>\n\t\t<th>-</th>\n\t\t<th>-</th>\n\t</tr>"
|
|
108
|
+
else
|
|
109
|
+
files.sort.each do |file|
|
|
110
|
+
html << self.wrap(file)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
html << "\n</table>\n"
|
|
114
|
+
html << "<br>\n#{options[:readme]}\n" if options[:readme]
|
|
115
|
+
html << "</body>\n</html>\n"
|
|
116
|
+
html
|
|
117
|
+
end
|
|
118
|
+
|
|
76
119
|
def m_time(file)
|
|
77
120
|
f = File.join(File.join(settings.public_folder, URI.unescape(request.fullpath)), file)
|
|
78
121
|
"\t<td>#{File.mtime(f).strftime $last_modified_format}</td>"
|
|
@@ -110,64 +153,19 @@ module Sinatra
|
|
|
110
153
|
html = ""
|
|
111
154
|
if $should_list_invisibles == "yes"
|
|
112
155
|
html << "\n\t<tr>
|
|
113
|
-
#{name(file)}
|
|
114
|
-
#{m_time(file)}
|
|
115
|
-
#{size(file)}\n\t</tr>"
|
|
156
|
+
#{self.name(file)}
|
|
157
|
+
#{self.m_time(file)}
|
|
158
|
+
#{self.size(file)}\n\t</tr>"
|
|
116
159
|
else
|
|
117
160
|
if file[0] != "."
|
|
118
161
|
html << "\n\t<tr>
|
|
119
|
-
#{name(file)}
|
|
120
|
-
#{m_time(file)}
|
|
121
|
-
#{size(file)}\n\t</tr>"
|
|
162
|
+
#{self.name(file)}
|
|
163
|
+
#{self.m_time(file)}
|
|
164
|
+
#{self.size(file)}\n\t</tr>"
|
|
122
165
|
end
|
|
123
166
|
end
|
|
124
167
|
html
|
|
125
168
|
end
|
|
126
|
-
|
|
127
|
-
def list(o={})
|
|
128
|
-
options = {
|
|
129
|
-
:should_list_invisibles => "no",
|
|
130
|
-
:last_modified_format => "%Y-%m-%d %H:%M:%S",
|
|
131
|
-
:filename_truncate_length => 40,
|
|
132
|
-
:stylesheet => "",
|
|
133
|
-
:readme => ""
|
|
134
|
-
}.merge(o)
|
|
135
|
-
|
|
136
|
-
$should_list_invisibles = options[:should_list_invisibles]
|
|
137
|
-
$last_modified_format = options[:last_modified_format]
|
|
138
|
-
$filename_truncate_length = options[:filename_truncate_length]
|
|
139
|
-
|
|
140
|
-
html = "<html>\n<head>\n"
|
|
141
|
-
html << "<title>Index of #{URI.unescape(request.path)}</title>\n"
|
|
142
|
-
html << "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n"
|
|
143
|
-
if options[:stylesheet]
|
|
144
|
-
html << "<link rel=\"stylesheet\" type=\"text/css\" href=\"/#{options[:stylesheet].sub(/^[\/]*/,"")}\">\n"
|
|
145
|
-
end
|
|
146
|
-
html << "</head>\n<body>\n"
|
|
147
|
-
html << "<h1>Index of #{URI.unescape(request.path)}</h1>\n"
|
|
148
|
-
if URI.unescape(request.path) != "/"
|
|
149
|
-
html << "<a href='#{Pathname.new(URI.unescape(request.path)).parent}'>← Parent directory</a><br><br>"
|
|
150
|
-
else
|
|
151
|
-
html << "<a>Root directory</a><br><br>"
|
|
152
|
-
end
|
|
153
|
-
html << "<table>\n"
|
|
154
|
-
html << "\t<tr>\n\t\t<th>File</th>\n\t\t<th>Last modified</th>\n\t\t<th>Size</th>\n\t</tr>\n"
|
|
155
|
-
files = Array.new
|
|
156
|
-
Dir.foreach(File.join(settings.public_folder, URI.unescape(request.path)), &files.method(:push))
|
|
157
|
-
if files == [".", ".."]
|
|
158
|
-
html << "\t<tr>\n\t\t<th>No files.</th>\n\t\t<th>-</th>\n\t\t<th>-</th>\n\t</tr>"
|
|
159
|
-
else
|
|
160
|
-
files.sort.each do |file|
|
|
161
|
-
html << wrap(file)
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
html << "\n</table>\n"
|
|
165
|
-
html << "<br>\n#{options[:readme]}\n" if options[:readme]
|
|
166
|
-
html << "</body>\n</html>\n"
|
|
167
|
-
html
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
private :wrap, :name, :size, :m_time
|
|
171
169
|
|
|
172
170
|
end
|
|
173
171
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: directory_listing
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-07-
|
|
12
|
+
date: 2013-07-18 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: filesize
|
|
@@ -52,7 +52,8 @@ extra_rdoc_files: []
|
|
|
52
52
|
files:
|
|
53
53
|
- lib/sinatra/directory_listing.rb
|
|
54
54
|
homepage: https://rubygems.org/gems/directory_listing
|
|
55
|
-
licenses:
|
|
55
|
+
licenses:
|
|
56
|
+
- WTFPL
|
|
56
57
|
post_install_message:
|
|
57
58
|
rdoc_options: []
|
|
58
59
|
require_paths:
|