Skip to content

Instantly share code, notes, and snippets.

@gnrlbzik
Created May 18, 2011 02:35
Show Gist options
  • Save gnrlbzik/977887 to your computer and use it in GitHub Desktop.
Save gnrlbzik/977887 to your computer and use it in GitHub Desktop.
Sinatra Local Server for ruby script testing
# http://localhost:4567/
require 'rubygems'
require 'sinatra'
get("/*.rb") do
`ruby #{request.path_info.slice(1..-1)}`
end
get("/*.*") do
status 200
content_type 'text/html'
body File.open(request.path_info.to_s.sub(/\//, ''))
end
get("*") do
request_path = request.path_info.to_s
dir_items = Dir.entries(Dir.pwd.dup.to_s + request_path)
list_items = dir_items.map do |fd|
if fd.to_s == '.'
elsif fd.to_s == '..'
if request_path.length > 1
charat = request_path.rindex('/')
charat == 0 ? request_path_parent = '/' : request_path_parent = request_path.slice(0, charat)
"<a href='#{request_path_parent}'>&lt;..PARENT..&gt;</a><br />"
end
else
request_path.length <= 1 ? generated_path = "#{fd}" : generated_path = "#{request_path}/#{fd}"
"<a href='#{generated_path}'>#{fd}</a>"
end
end
p list_items.join("<br />")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment