Skip to content

Instantly share code, notes, and snippets.

@v2e4lisp
Created October 10, 2013 13:38
Show Gist options
  • Select an option

  • Save v2e4lisp/6918461 to your computer and use it in GitHub Desktop.

Select an option

Save v2e4lisp/6918461 to your computer and use it in GitHub Desktop.
require 'sinatra'
# require 'kramdown'
def files(regex, dir=".")
Dir.chdir(dir) do
ret = Dir[regex].inject([]) {|acc, f| acc << f}
Dir["*/"].inject(ret) {|acc, f| acc << {f => files(regex, f)}}
end
end
get "/:file" do
file = params[:file]
Dir.chdir Dir.pwd do
if File.exists?(file)
File.open(file).read
else
"no such file: #{Dir.pwd}/#{file}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment