1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/webrick/httpservlet/filehandler.rb (set_dir_list): add NameWidth option.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-05-20 13:41:21 +00:00
parent 31c2e85e51
commit 8fb4108bb7

View file

@ -424,11 +424,18 @@ module WEBrick
} }
list.compact! list.compact!
if d0 = req.query["N"]; idx = 0 query = req.query
elsif d0 = req.query["M"]; idx = 1
elsif d0 = req.query["S"]; idx = 2 d0 = nil
else d0 = "A" ; idx = 0 idx = nil
%w[N M S].each_with_index do |q, i|
if d = query.delete(q)
idx ||= i
d0 ||= d
end
end end
d0 ||= "A"
idx ||= 0
d1 = (d0 == "A") ? "D" : "A" d1 = (d0 == "A") ? "D" : "A"
if d0 == "A" if d0 == "A"
@ -437,6 +444,14 @@ module WEBrick
list.sort!{|a,b| b[idx] <=> a[idx] } list.sort!{|a,b| b[idx] <=> a[idx] }
end end
namewidth = query["NameWidth"]
if namewidth == "*"
namewidth = nil
elsif !namewidth or (namewidth = namewidth.to_i) < 2
namewidth = 25
end
query = query.inject('') {|s, (k, v)| s << '&' << HTMLUtils::escape("#{k}=#{v}")}
type = "text/html" type = "text/html"
case enc = Encoding.find('filesystem') case enc = Encoding.find('filesystem')
when Encoding::US_ASCII, Encoding::ASCII_8BIT when Encoding::US_ASCII, Encoding::ASCII_8BIT
@ -455,6 +470,7 @@ module WEBrick
<!-- <!--
.name, .mtime { text-align: left; } .name, .mtime { text-align: left; }
.size { text-align: right; } .size { text-align: right; }
td { text-overflow: ellipsis; white-space: nowrap; overflow: hidden; }
table { border-collapse: collapse; } table { border-collapse: collapse; }
tr th { border-bottom: 2px groove; } tr th { border-bottom: 2px groove; }
//--> //-->
@ -465,9 +481,9 @@ module WEBrick
_end_of_html_ _end_of_html_
res.body << "<TABLE width=\"100%\"><THEAD><TR>\n" res.body << "<TABLE width=\"100%\"><THEAD><TR>\n"
res.body << "<TH class=\"name\"><A HREF=\"?N=#{d1}\">Name</A></TH>" res.body << "<TH class=\"name\"><A HREF=\"?N=#{d1}#{query}\">Name</A></TH>"
res.body << "<TH class=\"mtime\"><A HREF=\"?M=#{d1}\">Last modified</A></TH>" res.body << "<TH class=\"mtime\"><A HREF=\"?M=#{d1}#{query}\">Last modified</A></TH>"
res.body << "<TH class=\"size\"><A HREF=\"?S=#{d1}\">Size</A></TH>\n" res.body << "<TH class=\"size\"><A HREF=\"?S=#{d1}#{query}\">Size</A></TH>\n"
res.body << "</TR></THEAD>\n" res.body << "</TR></THEAD>\n"
res.body << "<TBODY>\n" res.body << "<TBODY>\n"
@ -475,8 +491,10 @@ module WEBrick
list.each{ |name, time, size| list.each{ |name, time, size|
if name == ".." if name == ".."
dname = "Parent Directory" dname = "Parent Directory"
elsif namewidth and name.size > namewidth
dname = name[0...(namewidth - 2)] << '..'
else else
dname = name[0...23] << '..' dname = name
end end
s = "<TR><TD class=\"name\"><A HREF=\"#{HTTPUtils::escape(name)}\">#{HTMLUtils::escape(dname)}</A></TD>" s = "<TR><TD class=\"name\"><A HREF=\"#{HTTPUtils::escape(name)}\">#{HTMLUtils::escape(dname)}</A></TD>"
s << "<TD class=\"mtime\">" << (time ? time.strftime("%Y/%m/%d %H:%M") : "") << "</TD>" s << "<TD class=\"mtime\">" << (time ? time.strftime("%Y/%m/%d %H:%M") : "") << "</TD>"