#!/usr/bin/env ruby require 'cgi' file = ENV['REQUEST_URI'].sub(/\/repos\//, "") html_start = < #{file} EOHTML html_end = " \n" code = File.readlines( file ) # Nasty, but this whole script is ... suffix = file.rindex('.') ? file[file.rindex('.')..-1] : 'PLAIN' lang = case suffix when '.c', '.cc', '.cpp', '.h', '.hh' 'c' when '.css' 'css' when '.html', '.htm' 'html' when '.js' 'javascript' when '.rb' 'ruby' else 'PLAIN' end if lang == 'PLAIN' print "Content-Type: text/plain\n\n" puts code.join else print "Content-Type: text/html\n\n" puts <<-EOHTML #{html_start}
#{CGI::escapeHTML(code.join)}
    
#{html_end} EOHTML end