Skip to content

Commit

Permalink
Make sure generated sprites get into the asset manifest.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseppstein committed Mar 11, 2012
1 parent f78d2ce commit 0547934
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lib/compass-rails/patches/3_1.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'compass-rails/patches/static_compiler'

module Sass::Script::Functions
def generated_image_url(path, only_path = nil)
asset_url(path, Sass::Script::String.new("image"))
Expand Down Expand Up @@ -25,4 +27,4 @@ module Sass::Script::Functions
# Wierd that this has to be re-included to pick up sub-modules. Ruby bug?
class Sass::Script::Functions::EvaluationContext
include Sass::Script::Functions
end
end
4 changes: 2 additions & 2 deletions lib/compass-rails/patches/sprite_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def find(uri, options)
end
end
end

old
end

Expand All @@ -35,4 +35,4 @@ def resolver
end

end
end
end
12 changes: 12 additions & 0 deletions lib/compass-rails/patches/static_compiler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'sprockets/static_compiler'

module Sprockets
class StaticCompiler
cattr_accessor :generated_sprites
self.generated_sprites = {}
def write_manifest_with_sprites(manifest)
write_manifest_without_sprites(manifest.merge(self.class.generated_sprites))
end
alias_method_chain :write_manifest, :sprites
end
end
5 changes: 1 addition & 4 deletions lib/compass-rails/railties/3_1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,9 @@ def compass
asset = Rails.application.assets.find_asset(filename)
pathname = Pathname.new(filename)
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)
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
Expand Down

0 comments on commit 0547934

Please sign in to comment.