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/minify_css.rb
2009-11-30 11:32:02 -08:00

27 lines
No EOL
799 B
Ruby

begin
require "yui/compressor"
rescue LoadError
puts "YUI-Compressor not available. Install it with: gem install yui-compressor"
end
module Middleman
module Rack
class MinifyCSS
def initialize(app, options={})
@app = app
end
def call(env)
if env["DOWNSTREAM"] && env["PATH_INFO"].match(/\.css$/) && Middleman::Base.enabled?(:minify_css)
compressor = ::YUI::CssCompressor.new
source = env["DOWNSTREAM"][2].is_a?(::Rack::File) ? File.read(env["DOWNSTREAM"][2].path) : env["DOWNSTREAM"][2]
env["DOWNSTREAM"][2] = compressor.compress(source)
env["DOWNSTREAM"][1]["Content-Length"] = ::Rack::Utils.bytesize(env["DOWNSTREAM"][2]).to_s
end
@app.call(env)
end
end
end
end