directory_listing 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sinatra/directory_listing.rb +82 -34
- metadata +25 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc6e8b90276b6880d8cc5eefca368b999056d6d7
|
4
|
+
data.tar.gz: 27e126e7c527ac9e756dc9b2d620b3614ebf9880
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2232198ba1bd9c8f62d2af86c23b2581e6bbaffc448fd9c8fd98805601cad2b536e3db4c82c7f7143d3c177e03a43d84cffa9cfecdcef4880b672a7f952a962
|
7
|
+
data.tar.gz: 62cbfe05a591976fe342694fd9664de8efa2f8bf16a8d872dd05fba2f42fe4fef060ead3234b690b0bf84529c1b122ae8669ff784a5ae8fbb0bf5f9bebf82012
|
@@ -5,14 +5,20 @@ require 'pathname'
|
|
5
5
|
require 'uri'
|
6
6
|
require 'erb'
|
7
7
|
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
8
|
+
# ### directory_listing: easy, CSS-styled, Apache-like directory listings for Sinatra.
|
9
|
+
#
|
10
|
+
# ### Build from source:
|
11
|
+
#
|
12
|
+
# ```bash
|
13
|
+
# gem build directory_listing.gemspec
|
14
|
+
# sudo gem install ./directory_listing-x.x.x.gem
|
15
|
+
# ```
|
16
|
+
#
|
17
|
+
# ### Usage:
|
18
|
+
#
|
19
|
+
# ```list()``` will return HTML, so the following is a complete Sinatra app that will provide a directory listing of whatever path you navigate to and let you view any file that is served directly:
|
20
|
+
#
|
21
|
+
# ```ruby
|
16
22
|
# require 'sinatra'
|
17
23
|
# require 'sinatra/directory_listing'
|
18
24
|
#
|
@@ -31,49 +37,61 @@ require 'erb'
|
|
31
37
|
# not_found do
|
32
38
|
# 'Try again.'
|
33
39
|
# end
|
34
|
-
#
|
35
|
-
#
|
40
|
+
# ```
|
41
|
+
#
|
42
|
+
# ### Options:
|
36
43
|
#
|
37
44
|
# Options are passed in a hash:
|
38
45
|
#
|
46
|
+
# ```ruby
|
39
47
|
# list({
|
40
48
|
# :stylesheet => "stylesheets/styles.css",
|
41
49
|
# :readme => "<a>Welcome!</a>"
|
42
50
|
# })
|
43
|
-
#
|
51
|
+
# ```
|
52
|
+
#
|
44
53
|
# Available options:
|
45
|
-
#
|
46
|
-
# stylesheet # a stylesheet that will be added to the <head> of the generated directory listing
|
47
|
-
# readme # an HTML string that will be appended at the footer of the generated directory listing
|
48
|
-
# should_list_invisibles # whether the directory listing should include invisibles (dotfiles) - true or false, defaults to false
|
49
|
-
# 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"
|
50
|
-
# filename_truncate_length # (integer) length to truncate file names to - defaults to 40
|
51
|
-
#
|
52
|
-
# == Styling
|
53
|
-
#
|
54
|
-
# It's pretty easy to figure out how to style directory_listing by looking at the source, but here are some gotchas:
|
55
|
-
#
|
56
|
-
# Every item listed is a <td> element in a table. Directories will have a class of "dir" and regular files will have a class of "file".
|
57
|
-
#
|
58
|
-
# You can style the "File" column with this CSS:
|
59
54
|
#
|
55
|
+
# - ```stylesheet``` - a stylesheet that will be added to the <head> of the generated directory listing
|
56
|
+
# - ```readme``` - an HTML string that will be appended at the footer of the generated directory listing
|
57
|
+
# - ```should_list_invisibles``` - whether the directory listing should include invisibles (dotfiles) - true or false, defaults to false
|
58
|
+
# - ```last_modified_format``` - [format](http://www.ruby-doc.org/core-2.0/Time.html) for last modified date - defaults to ```%Y-%m-%d %H:%M:%S```
|
59
|
+
# - ```filename_truncate_length``` - (integer) length to truncate file names to - defaults to 40
|
60
|
+
#
|
61
|
+
# ### Styling:
|
62
|
+
#
|
63
|
+
# It's pretty easy to figure out how to style ```directory_listing``` by looking at the source, but here are some gotchas:
|
64
|
+
#
|
65
|
+
# - Every item listed is a ```<td>``` element in a table. Directories will have a class of ```dir``` and regular files will have a class of ```file```.
|
66
|
+
# - You can style the "File" column with this CSS:
|
67
|
+
#
|
68
|
+
# ```css
|
60
69
|
# table tr > td:first-child {
|
61
70
|
# text-align: left;
|
62
71
|
# }
|
72
|
+
# ```
|
73
|
+
#
|
74
|
+
# - "Last modified" column:
|
63
75
|
#
|
64
|
-
#
|
76
|
+
# ```css
|
65
77
|
# table tr > td:first-child + td {
|
66
78
|
# text-align: left;
|
67
79
|
# }
|
80
|
+
# ```
|
81
|
+
#
|
82
|
+
# - "Size" column:
|
68
83
|
#
|
69
|
-
#
|
84
|
+
# ```css
|
70
85
|
# table tr > td:first-child + td + td {
|
71
86
|
# text-align: left;
|
72
87
|
# }
|
88
|
+
# ```
|
73
89
|
|
74
90
|
module Sinatra
|
75
91
|
module Directory_listing
|
76
92
|
|
93
|
+
VERSION = '0.2.2'
|
94
|
+
|
77
95
|
##
|
78
96
|
# erb template for page
|
79
97
|
|
@@ -109,7 +127,7 @@ module Sinatra
|
|
109
127
|
|
110
128
|
def m_time(file)
|
111
129
|
f = File.join(File.join(settings.public_folder, URI.unescape(request.fullpath)), file)
|
112
|
-
"\t<td>#{File.mtime(f).strftime
|
130
|
+
"\t<td>#{File.mtime(f).strftime($last_modified_format)}</td>"
|
113
131
|
end
|
114
132
|
|
115
133
|
##
|
@@ -126,23 +144,48 @@ module Sinatra
|
|
126
144
|
end
|
127
145
|
|
128
146
|
##
|
129
|
-
# Get the name of
|
147
|
+
# Get the name of the file and its link.
|
130
148
|
|
131
149
|
def name(file)
|
150
|
+
|
151
|
+
##
|
152
|
+
# Make sure we're working with an unescaped file name and truncate it.
|
153
|
+
# URI.unescape seems to work best to decode uris.
|
154
|
+
|
132
155
|
file = URI.unescape(file)
|
133
|
-
|
134
|
-
|
156
|
+
file_truncated = file.truncate($filename_truncate_length, '...')
|
157
|
+
|
158
|
+
##
|
159
|
+
# If the requested resource is in the root public directory, the link is
|
160
|
+
# just the resource itself without the public directory path as well.
|
161
|
+
|
162
|
+
requested = Pathname.new(URI.unescape(request.path)).cleanpath
|
163
|
+
public_folder = Pathname.new(settings.public_folder).cleanpath
|
164
|
+
if requested.eql?(public_folder)
|
135
165
|
link = file
|
136
166
|
else
|
137
167
|
link = File.join(request.fullpath, file)
|
138
168
|
end
|
169
|
+
|
170
|
+
##
|
171
|
+
# Add a class of "dir" to directories and "file" to files.
|
139
172
|
|
140
173
|
html = ""
|
141
174
|
if File.directory?(File.join(settings.public_folder, link))
|
142
|
-
html << "\t<td class='dir'
|
175
|
+
html << "\t<td class='dir'>"
|
143
176
|
else
|
144
|
-
html << "\t<td class='file'
|
177
|
+
html << "\t<td class='file'>"
|
145
178
|
end
|
179
|
+
|
180
|
+
##
|
181
|
+
# Append the rest of the html.
|
182
|
+
#
|
183
|
+
# I haven't found a URI escaping library that will handle this
|
184
|
+
# gracefully, so for now, we're going to just take care of spaces and
|
185
|
+
# apostrophes ourselves.
|
186
|
+
|
187
|
+
link = link.gsub(" ", "%20").gsub("'", "%27")
|
188
|
+
html << "<a href='#{link}'>#{file_truncated}</a></td>"
|
146
189
|
html
|
147
190
|
end
|
148
191
|
|
@@ -200,7 +243,12 @@ module Sinatra
|
|
200
243
|
files = Array.new
|
201
244
|
Dir.foreach(File.join(settings.public_folder, URI.unescape(request.path)), &files.method(:push))
|
202
245
|
if files == [".", ".."]
|
203
|
-
$files_html << "
|
246
|
+
$files_html << "
|
247
|
+
<tr>
|
248
|
+
<th>No files.</th>
|
249
|
+
<th>-</th>
|
250
|
+
<th>-</th>
|
251
|
+
</tr>"
|
204
252
|
else
|
205
253
|
files.sort.each do |file|
|
206
254
|
$files_html << self.wrap(file)
|
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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Myers
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-23 00:00:00 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: filesize
|
@@ -31,6 +31,27 @@ dependencies:
|
|
31
31
|
version: 0.0.4
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id002
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: bundler
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "1.3"
|
42
|
+
type: :development
|
43
|
+
version_requirements: *id003
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: rake
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- &id005
|
50
|
+
- ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
type: :development
|
54
|
+
version_requirements: *id004
|
34
55
|
description: A Sinatra extension for generating easy, CSS-styled, Apache-like directory listings.
|
35
56
|
email: rick.myers@me.com
|
36
57
|
executables: []
|
@@ -53,13 +74,10 @@ require_paths:
|
|
53
74
|
- lib
|
54
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
55
76
|
requirements:
|
56
|
-
-
|
57
|
-
- ">="
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version: "0"
|
77
|
+
- *id005
|
60
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
79
|
requirements:
|
62
|
-
- *
|
80
|
+
- *id005
|
63
81
|
requirements: []
|
64
82
|
|
65
83
|
rubyforge_project:
|