-
-
Save masterkain/202070 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def browse | |
root, dir = File.expand_path("."), request[:dir] | |
@lis = [] | |
begin | |
path = root + "/" + dir | |
Dir.chdir(File.expand_path(path)) do | |
if Dir.pwd[0,root.length] == root then | |
files = Dir.glob("*") | |
files.each{ |x| | |
next unless File.directory?(x) | |
@lis << "<li class=\"directory collapsed\"><a href=\"#\" rel=\"#{dir}#{x}/\">#{x}</a></li>"; | |
} | |
files.each{ |x| | |
next unless File.file?(x) | |
ext = File.extname(x)[1..-1] | |
@lis << "<li class=\"file ext_#{ext}\"><a href=\"#\" rel=\"#{dir}#{x}\">#{x}</a></li>" | |
} | |
else | |
@lis << "<li>You are way out of your league</li>" | |
end | |
end | |
rescue | |
@lis << "<li>Internal Error</li>" | |
end | |
@lis << "</ul>" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment