directory_listing 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sinatra/directory_listing.rb +18 -16
- metadata +45 -42
@@ -2,6 +2,7 @@ require 'sinatra/base'
|
|
2
2
|
require 'truncate'
|
3
3
|
require 'filesize'
|
4
4
|
require 'pathname'
|
5
|
+
require 'uri'
|
5
6
|
|
6
7
|
# = Easy, CSS-styled, Apache-like directory listings for Sinatra.
|
7
8
|
#
|
@@ -72,15 +73,13 @@ require 'pathname'
|
|
72
73
|
module Sinatra
|
73
74
|
module Directory_listing
|
74
75
|
|
75
|
-
private
|
76
|
-
|
77
76
|
def m_time(file)
|
78
|
-
f = File.join(File.join(settings.public_folder, request.fullpath), file)
|
77
|
+
f = File.join(File.join(settings.public_folder, URI.unescape(request.fullpath)), file)
|
79
78
|
"\t<td>#{File.mtime(f).strftime $last_modified_format}</td>"
|
80
79
|
end
|
81
80
|
|
82
81
|
def size(file)
|
83
|
-
f = File.join(File.join(settings.public_folder, request.fullpath), file)
|
82
|
+
f = File.join(File.join(settings.public_folder, URI.unescape(request.fullpath)), file)
|
84
83
|
if File.directory?(f)
|
85
84
|
"\t<td>-</td>"
|
86
85
|
else
|
@@ -90,8 +89,9 @@ module Sinatra
|
|
90
89
|
end
|
91
90
|
|
92
91
|
def name(file)
|
92
|
+
file = URI.unescape(file)
|
93
93
|
tfile = file.truncate($filename_truncate_length, '...')
|
94
|
-
if (Pathname.new(request.path).cleanpath).eql?((Pathname.new(settings.public_folder)).cleanpath)
|
94
|
+
if (Pathname.new(URI.unescape(request.path)).cleanpath).eql?((Pathname.new(settings.public_folder)).cleanpath)
|
95
95
|
link = file
|
96
96
|
else
|
97
97
|
link = File.join(request.fullpath, file)
|
@@ -103,25 +103,25 @@ module Sinatra
|
|
103
103
|
else
|
104
104
|
html << "\t<td class='file'><a href='#{link}'>#{tfile}</a></td>"
|
105
105
|
end
|
106
|
-
|
106
|
+
html
|
107
107
|
end
|
108
108
|
|
109
109
|
def wrap(file)
|
110
|
-
|
110
|
+
html = ""
|
111
111
|
if $should_list_invisibles == "yes"
|
112
|
-
|
112
|
+
html << "\n\t<tr>
|
113
113
|
#{name(file)}
|
114
114
|
#{m_time(file)}
|
115
115
|
#{size(file)}\n\t</tr>"
|
116
116
|
else
|
117
117
|
if file[0] != "."
|
118
|
-
|
118
|
+
html << "\n\t<tr>
|
119
119
|
#{name(file)}
|
120
120
|
#{m_time(file)}
|
121
121
|
#{size(file)}\n\t</tr>"
|
122
122
|
end
|
123
123
|
end
|
124
|
-
|
124
|
+
html
|
125
125
|
end
|
126
126
|
|
127
127
|
def list(o={})
|
@@ -138,22 +138,22 @@ module Sinatra
|
|
138
138
|
$filename_truncate_length = options[:filename_truncate_length]
|
139
139
|
|
140
140
|
html = "<html>\n<head>\n"
|
141
|
-
html << "<title>Index of #{request.path}</title>\n"
|
141
|
+
html << "<title>Index of #{URI.unescape(request.path)}</title>\n"
|
142
142
|
html << "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n"
|
143
143
|
if options[:stylesheet]
|
144
144
|
html << "<link rel=\"stylesheet\" type=\"text/css\" href=\"/#{options[:stylesheet].sub(/^[\/]*/,"")}\">\n"
|
145
145
|
end
|
146
146
|
html << "</head>\n<body>\n"
|
147
|
-
html << "<h1>Index of #{request.path}</h1>\n"
|
148
|
-
if request.path != "/"
|
149
|
-
html << "<a href='#{Pathname.new(request.path).parent}'>← Parent directory</a><br><br>"
|
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
150
|
else
|
151
151
|
html << "<a>Root directory</a><br><br>"
|
152
152
|
end
|
153
153
|
html << "<table>\n"
|
154
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
155
|
files = Array.new
|
156
|
-
Dir.foreach(File.join(settings.public_folder, request.path), &files.method(:push))
|
156
|
+
Dir.foreach(File.join(settings.public_folder, URI.unescape(request.path)), &files.method(:push))
|
157
157
|
if files == [".", ".."]
|
158
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
159
|
else
|
@@ -164,8 +164,10 @@ module Sinatra
|
|
164
164
|
html << "\n</table>\n"
|
165
165
|
html << "<br>\n#{options[:readme]}\n" if options[:readme]
|
166
166
|
html << "</body>\n</html>\n"
|
167
|
-
|
167
|
+
html
|
168
168
|
end
|
169
|
+
|
170
|
+
private :wrap, :name, :size, :m_time
|
169
171
|
|
170
172
|
end
|
171
173
|
|
metadata
CHANGED
@@ -1,75 +1,78 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: directory_listing
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
4
5
|
prerelease:
|
5
|
-
version: 0.1.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Richard Myers
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-07-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: filesize
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
23
21
|
version: 0.0.2
|
24
22
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: truncate
|
28
23
|
prerelease: false
|
29
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.2
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: truncate
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
30
33
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
34
37
|
version: 0.0.4
|
35
38
|
type: :runtime
|
36
|
-
|
37
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.0.4
|
46
|
+
description: A Sinatra extension for generating easy, CSS-styled, Apache-like directory
|
47
|
+
listings.
|
38
48
|
email: rick.myers@me.com
|
39
49
|
executables: []
|
40
|
-
|
41
50
|
extensions: []
|
42
|
-
|
43
51
|
extra_rdoc_files: []
|
44
|
-
|
45
|
-
files:
|
52
|
+
files:
|
46
53
|
- lib/sinatra/directory_listing.rb
|
47
54
|
homepage: https://rubygems.org/gems/directory_listing
|
48
55
|
licenses: []
|
49
|
-
|
50
56
|
post_install_message:
|
51
57
|
rdoc_options: []
|
52
|
-
|
53
|
-
require_paths:
|
58
|
+
require_paths:
|
54
59
|
- lib
|
55
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
61
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version:
|
61
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
67
|
none: false
|
63
|
-
requirements:
|
64
|
-
- -
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version:
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
67
72
|
requirements: []
|
68
|
-
|
69
73
|
rubyforge_project:
|
70
|
-
rubygems_version: 1.8.
|
74
|
+
rubygems_version: 1.8.24
|
71
75
|
signing_key:
|
72
76
|
specification_version: 3
|
73
77
|
summary: Easy, CSS-styled, Apache-like directory listings for Sinatra.
|
74
78
|
test_files: []
|
75
|
-
|