Skip to content

Commit

Permalink
Fix writing a digested sprite during precompilation and issues surrou…
Browse files Browse the repository at this point in the history
…nding using a generated images directory that is a subdirectory of the images directory.
  • Loading branch information
chriseppstein committed Mar 4, 2012
1 parent efc48c0 commit 5ced42f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gemfiles/rails2.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GIT
PATH
remote: ..
specs:
compass-rails (1.0.0.rc.1)
compass-rails (1.0.0.rc.3)
compass (~> 0.12.rc.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails3.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GIT
PATH
remote: ..
specs:
compass-rails (1.0.0.rc.1)
compass-rails (1.0.0.rc.3)
compass (~> 0.12.rc.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails31.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GIT
PATH
remote: ..
specs:
compass-rails (1.0.0.rc.1)
compass-rails (1.0.0.rc.3)
compass (~> 0.12.rc.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails32.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GIT
PATH
remote: ..
specs:
compass-rails (1.0.0.rc.1)
compass-rails (1.0.0.rc.3)
compass (~> 0.12.rc.0)

GEM
Expand Down
9 changes: 6 additions & 3 deletions lib/compass-rails/railties/3_1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,21 @@ def compass
# hash or some metadata that is opaque to sprockets that could be read from the
# asset's attributes, we could avoid cluttering the assets directory with generated
# sprites and always just use the logical_path + data version of the api.
if Rails.application.config.assets.digests.try(:any?)
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)
pathname = Pathname.new(filename)
logical_path = filename[(Compass.configuration.generated_images_path.length+1)..-1]
logical_path = filename[(Compass.configuration.images_path.length+1)..-1]
# Force the asset into the cache so find_asset will find it.
cached_assets = Rails.application.assets.instance_variable_get("@assets")
cached_assets[logical_path] = cached_assets[filename] = asset

target = Pathname.new(File.join(Rails.public_path, Rails.application.config.assets.prefix))
asset = Rails.application.assets.find_asset(logical_path)
filename = target.join(asset.digest_path)
asset.write_to(filename)
FileUtils.mkdir_p File.dirname(filename)
asset.write_to filename
end
end
data
Expand Down

0 comments on commit 5ced42f

Please sign in to comment.