Class: Middleman::Rack::MinifyJavascript
- Inherits:
-
Object
- Object
- Middleman::Rack::MinifyJavascript
- Defined in:
- lib/middleman/features/minify_javascript/rack.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ MinifyJavascript
constructor
A new instance of MinifyJavascript.
Constructor Details
#initialize(app, options = {}) ⇒ MinifyJavascript
Returns a new instance of MinifyJavascript.
11 12 13 |
# File 'lib/middleman/features/minify_javascript/rack.rb', line 11 def initialize(app, ={}) @app = app end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/middleman/features/minify_javascript/rack.rb', line 15 def call(env) status, headers, response = @app.call(env) if env["PATH_INFO"].match(/\.js$/) compressor = ::YUI::JavaScriptCompressor.new(:munge => true) 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 end [status, headers, response] end |