Closed aaronjensen closed 11 years ago
Are you importing sprites with something like @import "my-icons/*.png";
?
If it sees an @import
anywhere in your asset, this line will just fire the Sass compilation and it should pick up all the sprite changes. Please let me know if there's some more cases that we need to handle.
We're not able to consistently repro and it may actually be a compass issue or with our setup. Closing until I can repro and actually point at turbo sprockets.
For posterity, I believe the problem we were having was that we changed our compass generated_images_dir
to public/assets
. This caused compass to generate directly to public/assets
so they were not considered part of the precompile. turbo-sprockets-rails3
then would occasionally remove them during the assets:clean_expired
step.
To fix it, we set the generated_images_dir
to app/assets/images/sprites
Because we use compass-rails we also had to re-monkey patch part of compass:
in config/initializers/compass_sprites.rb
:
# compass-rails monkey patches this. We need to take it back
# so we can have our images in /sprites
Sass::Script::Functions.module_eval do
def generated_image_url(path, only_path = nil)
path = Sass::Script::String.new("sprites/#{path.value}")
asset_url(path, Sass::Script::String.new("image"))
end
end
scratch all of this. It doesn't work at all. The problem is that compass sprites generates a file, it does not get injected into the asset pipeline so the generated css files use the original non-digested file name. This causes turbo-sprockets to delete the file when an expire clean is done.
The right way to do this is to set generated_images_dir
to app/assets/generated/sprites
, add app/assets/generated
to .gitignore
, and add config.assets.paths << Rails.root.join("app", "assets", "generated", "sprites")
to your application.rb
This seems to actually be working. Whew.
Hi @aaronjensen, thanks for figuring this out! It's strange though, compass should be adding it's sprites to the generated manifest.yml
- See https://github.com/Compass/compass-rails/blob/stable/lib/compass-rails/patches/static_compiler.rb
I'm intentionally not touching the write_manifest
method in order to support the compass alias_method_chain
, so it's weird that it's not working... The assets:clean_expired
task should see those sprites being added to manifest.yml
, and not touch them.
Can you let me know if the sprites are being added to manifest.yml
? If not, the file I mentioned above would probably be a good place to debug.
Thanks!
P.S. Are you using the compass-rails gem?
Sorry, yeah you mentioned that in a comment above :P
They are being added now. They didn't seem to be being added before when we were generating directly to public/assets.
On Monday, November 5, 2012 at 2:00 PM, Nathan Broadbent wrote:
Hi @aaronjensen (https://github.com/aaronjensen), thanks for figuring this out! It's strange though, compass should be adding it's sprites to the generated manifest.yml - See https://github.com/Compass/compass-rails/blob/stable/lib/compass-rails/patches/static_compiler.rb I'm intentionally not touching the write_manifest method in order to support the compass alias_method_chain, so it's weird that it's not working... The assets:clean_expired task should see those sprites being added to manifest.yml, and not touch them. Can you let me know if the sprites are being added to manifest.yml? If not, the file I mentioned above would probably be a good place to debug. Thanks!
— Reply to this email directly or view it on GitHub (https://github.com/ndbroadbent/turbo-sprockets-rails3/issues/29#issuecomment-10089972).
ok i'm being crazy fickle on this. It seems my previous solution doesn't work either. The problem is:
https://github.com/Compass/compass-rails/blob/stable/lib/compass-rails/railties/3_1.rb#L61
compass-rails requires you to have your generated sprites nested in your images path. If you don't you're SOL when it comes to manifest.yml generation. No sprites in your manifest and they get cleaned up.
I'm trying out only changing my sprite generation path in development and test only and leaving it default in all other environments. This seems to be working so far.
in development.rb
and test.rb
config.assets.paths << Rails.root.join("app", "assets", "sprites", "generated")
config.compass.generated_images_dir = 'app/assets/sprites/generated'
Hi, I think we've come across another issue. Compass sprites do not get properly regenerated when one of the sprites changes or is added. I haven't had a chance to put together a repro yet, but we're not seeing changes. I'll post more info as I get it.