Allow compressor to be passed to minify extensions as an activate option

This commit is contained in:
Thomas Reynolds 2012-04-26 14:15:35 -07:00
parent 240f67410d
commit cc3aebf5cc
4 changed files with 66 additions and 7 deletions

View file

@ -88,6 +88,29 @@ Feature: Minify CSS
</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
Given a fixture app "minify-css-app"
And a file named "config.rb" with:

View file

@ -92,6 +92,42 @@ Feature: Minify Javascript
</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
Given a fixture app "minify-js-app"
And a file named "config.rb" with:

View file

@ -15,13 +15,13 @@ module Middleman::Extensions
inline = options[:inline] || false
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"
set :css_compressor, ::Rainpress
::Rainpress
end
# Setup Rack middleware to minify CSS
use MinifyCSSRack, :compressor => css_compressor,
use MinifyCSSRack, :compressor => chosen_compressor,
:ignore => ignore,
:inline => inline
end

View file

@ -16,13 +16,13 @@ module Middleman::Extensions
# Once config is parsed
app.after_configuration do
unless respond_to?(:js_compressor) && js_compressor
chosen_compressor = js_compressor || options[:compressor] || begin
require 'uglifier'
set :js_compressor, ::Uglifier.new
::Uglifier.new
end
# Setup Rack middlware to minify JS
use MinifyJavascriptRack, :compressor => js_compressor,
use MinifyJavascriptRack, :compressor => chosen_compressor,
:ignore => ignore,
:inline => inline
end