use same compressor for Sprockets and Rack, make sure it's configurable
This commit is contained in:
parent
bf025b85e9
commit
ecc77ae89f
|
@ -2,11 +2,14 @@ module Middleman::Extensions
|
||||||
module MinifyJavascript
|
module MinifyJavascript
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
def registered(app)
|
||||||
require 'uglifier'
|
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
set :js_compressor, ::Uglifier.new
|
if !js_compressor
|
||||||
|
require 'uglifier'
|
||||||
|
set :js_compressor, ::Uglifier.new
|
||||||
|
end
|
||||||
|
|
||||||
|
use InlineJavascriptRack, :compressor => js_compressor
|
||||||
end
|
end
|
||||||
app.use InlineJavascriptRack
|
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
@ -14,14 +17,13 @@ module Middleman::Extensions
|
||||||
class InlineJavascriptRack
|
class InlineJavascriptRack
|
||||||
def initialize(app, options={})
|
def initialize(app, options={})
|
||||||
@app = app
|
@app = app
|
||||||
|
@compressor = options[:compressor]
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
status, headers, response = @app.call(env)
|
status, headers, response = @app.call(env)
|
||||||
|
|
||||||
if env["PATH_INFO"].match(/\.html$/)
|
if env["PATH_INFO"].match(/\.html$/)
|
||||||
compressor = ::Uglifier.new
|
|
||||||
|
|
||||||
uncompressed_source = case(response)
|
uncompressed_source = case(response)
|
||||||
when String
|
when String
|
||||||
response
|
response
|
||||||
|
@ -37,7 +39,7 @@ module Middleman::Extensions
|
||||||
first = $1
|
first = $1
|
||||||
uncompressed_source = $2
|
uncompressed_source = $2
|
||||||
last = $3
|
last = $3
|
||||||
minified_js = compressor.compile(uncompressed_source)
|
minified_js = @compressor.compile(uncompressed_source)
|
||||||
|
|
||||||
first << minified_js << "\n" << last
|
first << minified_js << "\n" << last
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue