update minify js extension

This commit is contained in:
Thomas Reynolds 2013-04-20 14:29:51 -07:00
parent 11a3507528
commit 1c4e6cb835
2 changed files with 72 additions and 85 deletions

View file

@ -59,10 +59,8 @@ module Middleman
Middleman::Extensions::MinifyCss.register Middleman::Extensions::MinifyCss.register
# MinifyJavascript compresses JS # MinifyJavascript compresses JS
Middleman::Extensions.register(:minify_javascript) do
require "middleman-more/extensions/minify_javascript" require "middleman-more/extensions/minify_javascript"
Middleman::Extensions::MinifyJavascript Middleman::Extensions::MinifyJavascript.register
end
# RelativeAssets allow any asset path in dynamic templates to be either # RelativeAssets allow any asset path in dynamic templates to be either
# relative to the root of the project or use an absolute URL. # relative to the root of the project or use an absolute URL.

View file

@ -1,34 +1,25 @@
# Extension namespace # Minify Javascript Extension
module Middleman class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
module Extensions option :compressor, nil, 'Set the JS compressor to use.'
option :inline, false, 'Whether to minify JS inline within HTML files'
option :ignore, [], 'Patterns to avoid minifying'
# Minify Javascript Extension def initialize(app, options_hash={}, &block)
module MinifyJavascript super
# Setup extension
class << self
# Once registered
def registered(app, options={})
app.config.define_setting :js_compressor, nil, 'Set the JS compressor to use. Deprecated in favor of the :compressor option when activating :minify_js' app.config.define_setting :js_compressor, nil, 'Set the JS compressor to use. Deprecated in favor of the :compressor option when activating :minify_js'
end
ignore = Array(options[:ignore]) << /\.min\./ def after_configuration
inline = options[:inline] || false chosen_compressor = app.config[:js_compressor] || options[:compressor] || begin
# Once config is parsed
app.after_configuration do
chosen_compressor = js_compressor || options[:compressor] || begin
require 'uglifier' require 'uglifier'
::Uglifier.new ::Uglifier.new
end end
# Setup Rack middlware to minify JS # Setup Rack middleware to minify CSS
use Rack, :compressor => chosen_compressor, app.use Rack, :compressor => chosen_compressor,
:ignore => ignore, :ignore => options[:ignore] + [/\.min\./],
:inline => inline :inline => options[:inline]
end
end
alias :included :registered
end end
# Rack middleware to look for JS and compress it # Rack middleware to look for JS and compress it
@ -89,6 +80,4 @@ module Middleman
[status, headers, response] [status, headers, response]
end end
end end
end
end
end end