Skip to content

Instantly share code, notes, and snippets.

@stilist
Created April 26, 2010 03:48
Show Gist options
  • Save stilist/378952 to your computer and use it in GitHub Desktop.
Save stilist/378952 to your computer and use it in GitHub Desktop.
#!/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