1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00
middleman--middleman/lib/middleman/rack/sprockets.rb
tdreyno 58d6fc94ea Revert "update docs"
This reverts commit 43ac01af5c.
2009-10-22 17:25:15 -07:00

34 lines
No EOL
1.1 KiB
Ruby

begin
require 'sprockets'
require 'middleman/rack/sprockets+ruby19' # Sprockets ruby 1.9 duckpunch
rescue LoadError
puts "Sprockets not available. Install it with: gem install sprockets"
end
module Middleman
module Rack
class Sprockets
def initialize(app, options={})
@app = app
end
def call(env)
path = env["PATH_INFO"]
source = File.join(Middleman::Base.views, path)
if path.match(/\.js$/) && File.exists?(source)
secretary = ::Sprockets::Secretary.new( :root => Middleman::Base.root,
:source_files => [ File.join("views", path) ],
:load_path => [ File.join("public", Middleman::Base.js_dir),
File.join("views", Middleman::Base.js_dir) ])
[200, { "Content-Type" => "text/javascript" }, [secretary.concatenation.to_s]]
else
@app.call(env)
end
end
end
end
end
Middleman::Base.supported_formats << "js"