Allow compressor to be passed to minify extensions as an activate option
This commit is contained in:
parent
240f67410d
commit
cc3aebf5cc
|
@ -88,6 +88,29 @@ Feature: Minify CSS
|
||||||
</style>
|
</style>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
Scenario: Rendering inline css with a passthrough minifier using activate-style compressor
|
||||||
|
Given a fixture app "passthrough-app"
|
||||||
|
And a file named "config.rb" with:
|
||||||
|
"""
|
||||||
|
module ::HelloCompressor
|
||||||
|
def self.compress(data)
|
||||||
|
"Hello"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
activate :minify_css, :inline => true, :compressor => ::HelloCompressor
|
||||||
|
|
||||||
|
page "/inline-css.html", :layout => false
|
||||||
|
"""
|
||||||
|
And the Server is running at "passthrough-app"
|
||||||
|
When I go to "/inline-css.html"
|
||||||
|
Then I should see:
|
||||||
|
"""
|
||||||
|
<style type='text/css'>
|
||||||
|
Hello
|
||||||
|
</style>
|
||||||
|
"""
|
||||||
|
|
||||||
Scenario: Rendering inline css with the feature enabled
|
Scenario: Rendering inline css with the feature enabled
|
||||||
Given a fixture app "minify-css-app"
|
Given a fixture app "minify-css-app"
|
||||||
And a file named "config.rb" with:
|
And a file named "config.rb" with:
|
||||||
|
|
|
@ -92,6 +92,42 @@ Feature: Minify Javascript
|
||||||
</script>
|
</script>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
Scenario: Rendering inline css with a passthrough minifier using activate-style compressor
|
||||||
|
Given a fixture app "passthrough-app"
|
||||||
|
And a file named "config.rb" with:
|
||||||
|
"""
|
||||||
|
module ::HelloCompressor
|
||||||
|
def self.compress(data)
|
||||||
|
"Hello"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
activate :minify_javascript, :inline => true, :compressor => ::HelloCompressor
|
||||||
|
|
||||||
|
page "/inline-js.html", :layout => false
|
||||||
|
"""
|
||||||
|
And the Server is running at "passthrough-app"
|
||||||
|
When I go to "/inline-js.html"
|
||||||
|
Then I should see:
|
||||||
|
"""
|
||||||
|
<script type='text/javascript'>
|
||||||
|
//<![CDATA[
|
||||||
|
Hello
|
||||||
|
//]]>
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
Hello
|
||||||
|
</script>
|
||||||
|
<script type='text/javascript'>
|
||||||
|
//<!--
|
||||||
|
Hello
|
||||||
|
//-->
|
||||||
|
</script>
|
||||||
|
<script type='text/html'>
|
||||||
|
I'm a jQuery {{template}}.
|
||||||
|
</script>
|
||||||
|
"""
|
||||||
|
|
||||||
Scenario: Rendering inline js with the feature enabled
|
Scenario: Rendering inline js with the feature enabled
|
||||||
Given a fixture app "minify-js-app"
|
Given a fixture app "minify-js-app"
|
||||||
And a file named "config.rb" with:
|
And a file named "config.rb" with:
|
||||||
|
|
|
@ -15,13 +15,13 @@ module Middleman::Extensions
|
||||||
inline = options[:inline] || false
|
inline = options[:inline] || false
|
||||||
|
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
unless respond_to?(:css_compressor) && css_compressor
|
chosen_compressor = css_compressor || options[:compressor] || begin
|
||||||
require "middleman-more/extensions/minify_css/rainpress"
|
require "middleman-more/extensions/minify_css/rainpress"
|
||||||
set :css_compressor, ::Rainpress
|
::Rainpress
|
||||||
end
|
end
|
||||||
|
|
||||||
# Setup Rack middleware to minify CSS
|
# Setup Rack middleware to minify CSS
|
||||||
use MinifyCSSRack, :compressor => css_compressor,
|
use MinifyCSSRack, :compressor => chosen_compressor,
|
||||||
:ignore => ignore,
|
:ignore => ignore,
|
||||||
:inline => inline
|
:inline => inline
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,13 +16,13 @@ module Middleman::Extensions
|
||||||
|
|
||||||
# Once config is parsed
|
# Once config is parsed
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
unless respond_to?(:js_compressor) && js_compressor
|
chosen_compressor = js_compressor || options[:compressor] || begin
|
||||||
require 'uglifier'
|
require 'uglifier'
|
||||||
set :js_compressor, ::Uglifier.new
|
::Uglifier.new
|
||||||
end
|
end
|
||||||
|
|
||||||
# Setup Rack middlware to minify JS
|
# Setup Rack middlware to minify JS
|
||||||
use MinifyJavascriptRack, :compressor => js_compressor,
|
use MinifyJavascriptRack, :compressor => chosen_compressor,
|
||||||
:ignore => ignore,
|
:ignore => ignore,
|
||||||
:inline => inline
|
:inline => inline
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue