class Middleman::Extensions::MinifyCss::Rack
Rack middleware to look for CSS and compress it
def call(env)
-
(Array)
-
Parameters:
-
env
(Rack::Environmemt
) --
def call(env) status, headers, response = @app.call(env) if inline_html_content?(env["PATH_INFO"]) minified = ::Middleman::Util.extract_response_text(response) minified.gsub!(INLINE_CSS_REGEX) do |match| $1 << @compressor.compress($2) << $3 end headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s response = [minified] elsif standalone_css_content?(env["PATH_INFO"]) minified_css = @compressor.compress(::Middleman::Util.extract_response_text(response)) headers["Content-Length"] = ::Rack::Utils.bytesize(minified_css).to_s response = [minified_css] end [status, headers, response] end
def initialize(app, options={})
-
options
(Hash
) -- -
app
(Class
) --
def initialize(app, options={}) @app = app @compressor = options[:compressor] @ignore = options[:ignore] @inline = options[:inline] end
def inline_html_content?(path)
def inline_html_content?(path) (path.end_with?('.html') || path.end_with?('.php')) && @inline end
def standalone_css_content?(path)
def standalone_css_content?(path) path.end_with?('.css') && @ignore.none? {|ignore| Middleman::Util.path_match(ignore, path) } end