Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move asset Gzip compression to Sprockets to fix Rails 4 regression

  • Loading branch information...
commit e58f620ada8d7488ca903428a8a17e333c9d7dbc 1 parent 37e80b6
Andrey Sitnik ai authored
Showing with 17 additions and 0 deletions.
  1. +3 −0  lib/sprockets/manifest.rb
  2. +14 −0 test/test_manifest.rb
3  lib/sprockets/manifest.rb
View
@@ -132,6 +132,7 @@ def compile(*args)
else
logger.info "Writing #{target}"
asset.write_to target
+ asset.write_to "#{target}.gz" if target =~ /\.(js|css)$/
end
save
@@ -147,6 +148,7 @@ def compile(*args)
#
def remove(filename)
path = File.join(dir, filename)
+ gzip = "#{path}.gz"
logical_path = files[filename]['logical_path']
if assets[logical_path] == filename
@@ -155,6 +157,7 @@ def remove(filename)
files.delete(filename)
FileUtils.rm(path) if File.exist?(path)
+ FileUtils.rm(gzip) if File.exist?(gzip)
save
14 test/test_manifest.rb
View
@@ -154,6 +154,18 @@ def teardown
assert_equal gallery_digest_path, data['assets']['gallery.css']
end
+ test "compress assets" do
+ gallery_digest_path = @env['gallery.css'].digest_path
+ app_digest_path = @env['application.js'].digest_path
+ img_digest_path = @env['blank.gif'].digest_path
+
+ @manifest.compile('gallery.css', 'application.js', 'blank.gif')
+
+ assert File.exist?("#{@dir}/#{gallery_digest_path}.gz")
+ assert File.exist?("#{@dir}/#{app_digest_path}.gz")
+ assert !File.exist?("#{@dir}/#{img_digest_path}.gz")
+ end
+
test "recompile asset" do
digest_path = @env['application.js'].digest_path
filename = fixture_path('default/application.js.coffee')
@@ -193,6 +205,7 @@ def teardown
@manifest.compile('application.js')
assert File.exist?("#{@dir}/#{digest_path}")
+ assert File.exist?("#{@dir}/#{digest_path}.gz")
data = JSON.parse(File.read(@manifest.path))
assert data['files'][digest_path]
@@ -201,6 +214,7 @@ def teardown
@manifest.remove(digest_path)
assert !File.exist?("#{@dir}/#{digest_path}")
+ assert !File.exist?("#{@dir}/#{digest_path}.gz")
data = JSON.parse(File.read(@manifest.path))
assert !data['files'][digest_path]
Please sign in to comment.
Something went wrong with that request. Please try again.