Created
April 26, 2010 03:48
-
-
Save stilist/378952 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby -wKU | |
# encoding: UTF-8 | |
# provided under the MIT license; see | |
# http://github.com/stilist/ratafiacurrant/blob/master/License | |
require "rubygems" | |
require "sinatra" | |
helpers do | |
def list_paths(path) | |
list = [] | |
# directories and entries | |
["#{path}*/", "#{path}*.rc"].each { |pattern| | |
Dir.glob(pattern).each { |path| list << generate_link(path) } | |
} | |
list.join("<br>") | |
end | |
def generate_link(path) | |
# link text trimemd to name of directory or entry | |
"<a href='/#{path}'>#{path.split('/')[-1]}</a>" | |
end | |
end | |
get "/" do | |
list_paths("#{Dir.pwd}/") | |
end | |
get "/*" do | |
path = params[:splat].to_s | |
if File.file?(path) | |
begin | |
IO.read(path).gsub(/\n/, "<br>") | |
rescue => err | |
"Problem reading file: #{err}" | |
end | |
elsif File.directory?(path) | |
list_paths(path) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment