class Middleman::Extensions::MinifyJavascript::Rack

def call(env)

Returns:
  • (Array) -

Parameters:
  • env (Rack::Environmemt) --
def call(env)
  status, headers, response = @app.call(env)
  path = env["PATH_INFO"]
  begin
    if @inline && (path.end_with?('.html') || path.end_with?('.php'))
      uncompressed_source = ::Middleman::Util.extract_response_text(response)
      minified = minify_inline_content(uncompressed_source)
      headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
      response = [minified]
    elsif path.end_with?('.js') && @ignore.none? {|ignore| Middleman::Util.path_match(ignore, path) }
      uncompressed_source = ::Middleman::Util.extract_response_text(response)
      minified = @compressor.compress(uncompressed_source)
      headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
      response = [minified]
    end
  rescue ExecJS::ProgramError => e
    warn "WARNING: Couldn't compress JavaScript in #{path}: #{e.message}"
  end
  [status, headers, response]
end