Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save berdof/5590634 to your computer and use it in GitHub Desktop.
Save berdof/5590634 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment