Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

settings to individually disable css and js compression #204

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/jammit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class << self
:embed_assets, :package_assets, :compress_assets, :gzip_assets,
:package_path, :mhtml_enabled, :include_jst_script, :config_path,
:javascript_compressor, :compressor_options, :css_compressor_options,
:template_extension, :template_extension_matcher, :allow_debugging
:template_extension, :template_extension_matcher, :allow_debugging,
:compress_js, :compress_css
attr_accessor :compressors
end

Expand All @@ -77,6 +78,8 @@ def self.load_configuration(config_path, soft=false)
@package_path = conf[:package_path] || DEFAULT_PACKAGE_PATH
@embed_assets = conf[:embed_assets] || conf[:embed_images]
@compress_assets = !(conf[:compress_assets] == false)
@compress_js = !(conf[:compress_js] == false) && @compress_assets
@compress_css = !(conf[:compress_css] == false) && @compress_assets
@gzip_assets = !(conf[:gzip_assets] == false)
@allow_debugging = !(conf[:allow_debugging] == false)
@mhtml_enabled = @embed_assets && @embed_assets != "datauri"
Expand Down
4 changes: 2 additions & 2 deletions lib/jammit/compressor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def compress_js(paths)
else
js = concatenate(paths - jst_paths) + compile_jst(jst_paths)
end
Jammit.compress_assets ? @js_compressor.compress(js) : js
Jammit.compress_js ? @js_compressor.compress(js) : js
end

# Concatenate and compress a list of CSS stylesheets. When compressing a
Expand All @@ -80,7 +80,7 @@ def compress_js(paths)
def compress_css(paths, variant=nil, asset_url=nil)
@asset_contents = {}
css = concatenate_and_tag_assets(paths, variant)
css = @css_compressor.compress(css) if Jammit.compress_assets
css = @css_compressor.compress(css) if Jammit.compress_css
case variant
when nil then return css
when :datauri then return with_data_uris(css)
Expand Down
9 changes: 9 additions & 0 deletions test/config/assets-compression-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
compress_css: false

javascripts:
js_test:
- fixtures/src/*.js

stylesheets:
css_test:
- fixtures/src/*.css
11 changes: 11 additions & 0 deletions test/unit/test_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def test_loading_a_nonexistent_file
def test_disabled_compression
Jammit.load_configuration('test/config/assets-compression-disabled.yml')
assert !Jammit.compress_assets
assert !Jammit.compress_js
assert !Jammit.compress_css
assert !Jammit.gzip_assets
@compressor = Compressor.new
# Should not compress js.
Expand All @@ -32,8 +34,17 @@ def test_disabled_compression
assert packed == File.open('test/fixtures/jammed/css_test-uncompressed.css', 'rb') {|f| f.read }
end

def test_individually_disabled_compression
Jammit.load_configuration('test/config/assets-compression-config.yml')
assert Jammit.compress_assets
assert Jammit.compress_js
assert !Jammit.compress_css
end

def test_css_compression
assert Jammit.compress_assets
assert Jammit.compress_js
assert Jammit.compress_css
assert Jammit.gzip_assets
packed = @compressor.compress_css(glob('test/fixtures/src/*.css'))
assert packed == File.read('test/fixtures/jammed/css_test.css')
Expand Down