Class: Ki::Middleware::CoffeeCompiler

Inherits:
Object
  • Object
show all
Includes:
BaseMiddleware
Defined in:
lib/ki/middleware/coffee_compiler.rb

Instance Method Summary collapse

Methods included from BaseMiddleware

#initialize

Instance Method Details

#call(env) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/ki/middleware/coffee_compiler.rb', line 6

def call(env)
  req = BaseRequest.new env
  coffee_path = req.path.to_s[0...-3] + '.coffee'
  if !public_file_exists?(req) && format_of(req) == 'js' && public_file_exists?(coffee_path)
    js = CoffeeScript.compile(File.read(public_file_path(coffee_path)))
    Rack::Response.new(js, 200, { 'Content-Type' => 'application/javascript' }).finish
  else
    @app.call env
  end
end