From: zerohalo Date: 2006-09-21T01:55:58+09:00 Subject: Re: super simple serving of ruby pages Jan Svitok wrote: > Webrick seems to have support for ERB - see httpservlet/erbhandler.rb, > that is used for .rhtml files by FileHandler. Just find in the > tutorials how to start webrick for a given document root > (Webrick::HttpServer.new({:DocumentRoot = '/var/www/'}) and > something?) Yes, I tried that. Unfortunately there is no documentation on the webrick site on how to use ERBHandler. I have this in a ruby script which does start up the Webrick server. However, while it serves HTML files fine, it treats RHTML files as binaries and RB files as just plain text. Here's my code:

require 'webrick'
include WEBrick

def start_webrick(config = {})
  config.update(:Port => 8080)
  server = HTTPServer.new(config)
  yield server if block_given?
  ['INT', 'TERM'].each {|signal|
    trap(signal) {server.shutdown}
  }
  ruby_dir = File.expand_path('/data/sandbox/ruby')
  server.mount("/data/sandbox/ruby", HTTPServlet::ERBHandler, ruby_dir)
  server.start
end

start_webrick(:DocumentRoot => '/data/sandbox/ruby')