Sha256: 027083768cde1393e5f20719fbd7c73f014ec40a1605a5ebe51f5a775ad3db05
Contents?: true
Size: 1.22 KB
Versions: 6
Compression:
Stored size: 1.22 KB
Contents
require 'thin' require 'renee' module Gitdocs class Server def initialize(*gitdocs) @gitdocs = gitdocs end def start(port = 8888) gds = @gitdocs Thin::Server.start('127.0.0.1', port) do run Renee { if request.path_info == '/' inline!(<<-EOT, :erb, :locals => {:gds => gds}) <html><body> <table> <% gds.each_with_index do |gd, idx| %> <tr><a href="/<%=idx%>"><%=gd.root%></a></tr> <% end %> </table> </body></html> EOT else var :int do |idx| gd = gds[idx] halt 404 if gd.nil? expanded_path = File.expand_path(".#{request.path_info}", gd.root) halt 400 unless expanded_path[/^#{Regexp.quote(gd.root)}/] halt 404 unless File.exist?(expanded_path) if File.directory?(expanded_path) run! Rack::Directory.new(gd.root) else begin render! expanded_path rescue run! Rack::File.new(gd.root) end end end end } end end end end
Version data entries
6 entries across 6 versions & 1 rubygems