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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/jammit.rb
Expand Up @@ -51,7 +51,8 @@ class << self
:embed_assets, :package_assets, :compress_assets, :gzip_assets, :embed_assets, :package_assets, :compress_assets, :gzip_assets,
:package_path, :mhtml_enabled, :include_jst_script, :config_path, :package_path, :mhtml_enabled, :include_jst_script, :config_path,
:javascript_compressor, :compressor_options, :css_compressor_options, :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 attr_accessor :compressors
end end


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


# Concatenate and compress a list of CSS stylesheets. When compressing a # 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) def compress_css(paths, variant=nil, asset_url=nil)
@asset_contents = {} @asset_contents = {}
css = concatenate_and_tag_assets(paths, variant) 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 case variant
when nil then return css when nil then return css
when :datauri then return with_data_uris(css) when :datauri then return with_data_uris(css)
Expand Down
9 changes: 9 additions & 0 deletions test/config/assets-compression-config.yml
@@ -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
Expand Up @@ -20,6 +20,8 @@ def test_loading_a_nonexistent_file
def test_disabled_compression def test_disabled_compression
Jammit.load_configuration('test/config/assets-compression-disabled.yml') Jammit.load_configuration('test/config/assets-compression-disabled.yml')
assert !Jammit.compress_assets assert !Jammit.compress_assets
assert !Jammit.compress_js
assert !Jammit.compress_css
assert !Jammit.gzip_assets assert !Jammit.gzip_assets
@compressor = Compressor.new @compressor = Compressor.new
# Should not compress js. # 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 } assert packed == File.open('test/fixtures/jammed/css_test-uncompressed.css', 'rb') {|f| f.read }
end 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 def test_css_compression
assert Jammit.compress_assets assert Jammit.compress_assets
assert Jammit.compress_js
assert Jammit.compress_css
assert Jammit.gzip_assets assert Jammit.gzip_assets
packed = @compressor.compress_css(glob('test/fixtures/src/*.css')) packed = @compressor.compress_css(glob('test/fixtures/src/*.css'))
assert packed == File.read('test/fixtures/jammed/css_test.css') assert packed == File.read('test/fixtures/jammed/css_test.css')
Expand Down