Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Commit

Permalink
Move asset Gzip compression to Sprockets to fix Rails 4 regression
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Feb 25, 2013
1 parent 37e80b6 commit e58f620
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/sprockets/manifest.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def compile(*args)
else else
logger.info "Writing #{target}" logger.info "Writing #{target}"
asset.write_to target asset.write_to target
asset.write_to "#{target}.gz" if target =~ /\.(js|css)$/
end end


save save
Expand All @@ -147,6 +148,7 @@ def compile(*args)
# #
def remove(filename) def remove(filename)
path = File.join(dir, filename) path = File.join(dir, filename)
gzip = "#{path}.gz"
logical_path = files[filename]['logical_path'] logical_path = files[filename]['logical_path']


if assets[logical_path] == filename if assets[logical_path] == filename
Expand All @@ -155,6 +157,7 @@ def remove(filename)


files.delete(filename) files.delete(filename)
FileUtils.rm(path) if File.exist?(path) FileUtils.rm(path) if File.exist?(path)
FileUtils.rm(gzip) if File.exist?(gzip)


save save


Expand Down
14 changes: 14 additions & 0 deletions test/test_manifest.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ def teardown
assert_equal gallery_digest_path, data['assets']['gallery.css'] assert_equal gallery_digest_path, data['assets']['gallery.css']
end 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 test "recompile asset" do
digest_path = @env['application.js'].digest_path digest_path = @env['application.js'].digest_path
filename = fixture_path('default/application.js.coffee') filename = fixture_path('default/application.js.coffee')
Expand Down Expand Up @@ -193,6 +205,7 @@ def teardown


@manifest.compile('application.js') @manifest.compile('application.js')
assert File.exist?("#{@dir}/#{digest_path}") assert File.exist?("#{@dir}/#{digest_path}")
assert File.exist?("#{@dir}/#{digest_path}.gz")


data = JSON.parse(File.read(@manifest.path)) data = JSON.parse(File.read(@manifest.path))
assert data['files'][digest_path] assert data['files'][digest_path]
Expand All @@ -201,6 +214,7 @@ def teardown
@manifest.remove(digest_path) @manifest.remove(digest_path)


assert !File.exist?("#{@dir}/#{digest_path}") assert !File.exist?("#{@dir}/#{digest_path}")
assert !File.exist?("#{@dir}/#{digest_path}.gz")


data = JSON.parse(File.read(@manifest.path)) data = JSON.parse(File.read(@manifest.path))
assert !data['files'][digest_path] assert !data['files'][digest_path]
Expand Down

0 comments on commit e58f620

Please sign in to comment.