Almost. There was a thread just a few days ago about viewing haml
directly in Apache:
http://groups.google.com/group/haml/browse_thread/thread/3a1d93760f33d70e
I use a ruby script that uses Webrick to serve all the haml and sass
files in a directory. It's based on one by John Long I found at
Wiseheart Design (inline below).
Neither of these allow you to double click on the file to open it (you
have to know the URL to use, either served from Apache or Webrick),
but otherwise they have the properties you mention.
Rhett
---- BEGIN SCRIPT -----
#!/usr/bin/env ruby
# Simple server that lets you automatically preview Haml outside of an
# application. From http://wiseheartdesign.com/2007/9/4/a-haml-server-for-web-designers/
require 'webrick'
require 'rubygems'
require 'haml'
require 'sass'
class AbstractHamlHandler < WEBrick::HTTPServlet::AbstractServlet
def initialize(server, name)
super
@script_filename = name
end
def do_GET(req, res)
begin
data = open(@script_filename) {|io| io.read }
res.body = parse(data)
res['content-type'] = content_type
rescue StandardError => ex
raise
rescue Exception => ex
@logger.error(ex)
raise HTTPStatus::InternalServerError, ex.message
end
end
alias do_POST do_GET
private
def parse(string)
engine = engine_class.new(string,
:attr_wrapper => '"',
:filename => @script_filename
)
engine.render
end
end
class HamlHandler < AbstractHamlHandler
def content_type
'text/html'
end
def engine_class
Haml::Engine
end
end
class SassHandler < AbstractHamlHandler
def content_type
'text/css'
end
def engine_class
Sass::Engine
end
end
WEBrick::HTTPServlet::FileHandler.add_handler("haml", HamlHandler)
WEBrick::HTTPServlet::FileHandler.add_handler("sass", SassHandler)
args = ARGV.join(' ')
args.gsub!(%r{^http://}, '')
args = args.split(/[ :]/).compact
server = WEBrick::HTTPServer.new(
:Port => args.pop || 3000,
:BindAddress => args.pop || '0.0.0.0',
:DocumentRoot => Dir.pwd
)
trap("INT") { server.shutdown }
server.start