fix minify javascript

This commit is contained in:
Thomas Reynolds 2011-11-18 17:17:33 -08:00
parent 1d2eca5373
commit 7d9550e9ce

View file

@ -2,7 +2,9 @@ module Middleman::Features::MinifyJavascript
class << self class << self
def registered(app) def registered(app)
require 'uglifier' require 'uglifier'
app.set :js_compressor, ::Uglifier.new app.before_configuration do
app.set :js_compressor, ::Uglifier.new
end
app.use InlineJavascriptRack app.use InlineJavascriptRack
end end
alias :included :registered alias :included :registered
@ -19,10 +21,15 @@ module Middleman::Features::MinifyJavascript
if env["PATH_INFO"].match(/\.html$/) if env["PATH_INFO"].match(/\.html$/)
compressor = ::Uglifier.new compressor = ::Uglifier.new
if response.is_a?(::Rack::File)# or response.is_a?(::Sinatra::Helpers::StaticFile) uncompressed_source = case(response)
uncompressed_source = File.read(response.path) when String
else response
uncompressed_source = response.join when Array
response.join
when Rack::Response
response.body.join
when Rack::File
File.read(response.path)
end end
minified = uncompressed_source.gsub(/(<scri.*?\/\/<!\[CDATA\[\n)(.*?)(\/\/\]\].*?<\/script>)/m) do |m| minified = uncompressed_source.gsub(/(<scri.*?\/\/<!\[CDATA\[\n)(.*?)(\/\/\]\].*?<\/script>)/m) do |m|