Skip to content
Browse files

Fix and cleanup asset precompile for sprites in rails 3.1 and 3.2

Conflicts:

	lib/compass-rails/railties/3_1.rb
  • Loading branch information...
1 parent 0547934 commit 6201548093f09ebdd959db442e442d0b51d1bc2d David Genord II committed with chriseppstein
Showing with 15 additions and 7 deletions.
  1. +15 −7 lib/compass-rails/railties/3_1.rb
View
22 lib/compass-rails/railties/3_1.rb
@@ -59,15 +59,23 @@ def compass
if Rails.application.config.assets.digest && # if digesting is enabled
caller.grep(/static_compiler/).any? && #OMG HAX - check if we're being precompiled
Compass.configuration.generated_images_path[Compass.configuration.images_path] # if the generated images path is not in the assets images directory, we don't have to do these backflips
- asset = Rails.application.assets.find_asset(filename)
+
+ # Clear entries in Hike::Index for this sprite's directory.
+ # This makes sure the asset can be found by find_assets
+ Rails.application.assets.send(:trail).instance_variable_get(:@entries).delete(File.dirname(filename))
+
pathname = Pathname.new(filename)
- logical_path = filename[(Compass.configuration.images_path.length+1)..-1]
+ logical_path = pathname.relative_path_from(Pathname.new(Compass.configuration.images_path))
+ asset = Rails.application.assets.find_asset(logical_path)
+ target = File.join(Rails.public_path, Rails.application.config.assets.prefix, asset.digest_path)
+
+ # Adds the asset to the manifest file.
+ Sprockets::StaticCompiler.generated_sprites[logical_path.to_s] = asset.digest_path
+
+ # Adds the fingerprinted asset to the public directory
+ FileUtils.mkdir_p File.dirname(target)
+ asset.write_to target
- target = Pathname.new(File.join(Rails.public_path, Rails.application.config.assets.prefix))
- Sprockets::StaticCompiler.generated_sprites[logical_path] = asset.digest_path
- filename = target.join(asset.digest_path)
- FileUtils.mkdir_p File.dirname(filename)
- asset.write_to filename
end
end
data

0 comments on commit 6201548

Please sign in to comment.
Something went wrong with that request. Please try again.