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

25 lines
700 B
Ruby
Raw Normal View History

2009-11-30 14:32:02 -05:00
begin
require "yui/compressor"
rescue LoadError
puts "YUI-Compressor not available. Install it with: gem install yui-compressor"
end
2010-01-20 18:22:40 -05:00
class Middleman::Rack::MinifyCSS
def initialize(app, options={})
@app = app
end
def call(env)
2010-03-02 20:38:08 -05:00
status, headers, response = @app.call(env)
if Middleman::Base.enabled?(:minify_css) && env["PATH_INFO"].match(/\.css$/)
2010-01-20 18:22:40 -05:00
compressor = ::YUI::CssCompressor.new
2010-03-02 20:38:08 -05:00
uncompressed_source = response.is_a?(::Rack::File) ? File.read(response.path) : response
response = compressor.compress(uncompressed_source)
headers["Content-Length"] = ::Rack::Utils.bytesize(response).to_s
2009-11-30 14:32:02 -05:00
end
2010-01-20 18:22:40 -05:00
2010-03-02 20:38:08 -05:00
[status, headers, response]
2009-11-30 14:32:02 -05:00
end
end