Created
May 18, 2011 02:35
-
-
Save gnrlbzik/977887 to your computer and use it in GitHub Desktop.
Sinatra Local Server for ruby script testing
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
# 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}'><..PARENT..></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