<%
  $:.unshift '/home3/apotheon/.gems/gems'

  require 'cgi'
  require 'bluecloth'

  path = File.dirname(__FILE__)

  cgi = CGI.new

  content_file = cgi.params['content'][0]
  contents = String.new
  title = String.new
  if content_file
    contents << File.read(path + '/content/' + content_file + '.txt')
    title = contents.split("\n")[0]
  else
    File.open(path + '/content/toc').each do |l|
      line = l.split
      content_file = line.shift
      title = line.join(' ')
      contents << "* [#{title}](text.rhtml?content=#{content_file})\n"
    end
    title = 'Table Of Contents'
  end

  contents = "* [Table Of Contents](text.rhtml)\n" + contents

%><html>
  <head>
    <title><%= title.sub(/#\s+/, '') %></title>
    <link rel="stylesheet" type="text/css" href="text.css" />
  </head>

  <body>
    <div>
      <%= BlueCloth.new(contents).to_html %>
      <!-- %= RedRug.to_html(contents) % -->
    </div>
  </body>
</html>
