- 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 --path .') 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 |
https://gist.github.com/hlb/5581919 |
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 = %x{jade --path . < #{path} } | |
[200, {"Content-Type" => "text/html"}, [body]] | |
else | |
status, headers, body = @app.call(env) | |
[status, headers, body] | |
end | |
end | |
end | |
use JadeHandler |
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]
base = File.basename(path)
dir = File.dirname(path)
body = nil
Dir.chdir(dir) do
body = Open3.popen3('jade --path .') do |stdin, stdout, stderr|
template = open(base,'r'){|f| f.read}
stdin.write template
stdin.close
stdout.read + stderr.read.gsub(/\n/, '<br>')
end
end
[200, {"Content-Type" => "text/html"}, [body]]
else
status, headers, body = @app.call(env)
[status, headers, body]
end
end
end
use JadeHandler
added block and include support for linux version
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]
base = File.basename(path)
dir = File.dirname(path) + "/src"
body = nil
Dir.chdir(dir) do
body = Open3.popen3('node c:/users/etblue/appdata/roaming/npm/node_modules/jade/bin/jade --path .') do |stdin, stdout, stderr|
template = open(base,'r'){|f| f.read}
stdin.write template
stdin.close
stdout.read + stderr.read.gsub(/\n/, '<br>')
end
end
[200, {"Content-Type" => "text/html"}, [body]]
else
status, headers, body = @app.call(env)
[status, headers, body]
end
end
end
use JadeHandler
hi
how do you make it to convert the .jade file to .html?