Skip to content

Commit

Permalink
Fix and cleanup asset precompile for sprites in rails 3.1 and 3.2
Browse files Browse the repository at this point in the history
Conflicts:

	lib/compass-rails/railties/3_1.rb
  • Loading branch information
David Genord II authored and chriseppstein committed Mar 11, 2012
1 parent 0547934 commit 6201548
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/compass-rails/railties/3_1.rb
Expand Up @@ -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
Expand Down

0 comments on commit 6201548

Please sign in to comment.