- download http_servlet_handler.rb to project
- watch project
- create foo.jade
- open http://127.0.0.1:24681/foo.jade in browser
ref.
ref.
require 'open3' | |
class JadeHandler | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
if env["PATH_INFO"] =~ /\/$/ | |
env["PATH_INFO"] += "index.jade" | |
end | |
if env["PATH_INFO"] =~ /\.jade$/ | |
path = env["PATH_INFO"][1..-1] | |
body = Open3.popen3('jade') do |stdin, stdout, stderr| | |
template = open(path,'r'){|f| f.read} | |
stdin.write template | |
stdin.close | |
stdout.read + stderr.read.gsub(/\n/, '<br>') | |
end | |
[200, {"Content-Type" => "text/html"}, [body]] | |
else | |
status, headers, body = @app.call(env) | |
[status, headers, body] | |
end | |
end | |
end | |
use JadeHandler |