Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sprite-path() does not honor the generated_images_dir path. #1077

Open
jannisg opened this issue Nov 1, 2012 · 20 comments
Open

sprite-path() does not honor the generated_images_dir path. #1077

jannisg opened this issue Nov 1, 2012 · 20 comments

Comments

@jannisg
Copy link

jannisg commented Nov 1, 2012

I've noticed that when setting the generated_images_dir in the config.rb that the sprite-path() function will still use the images_dir as the basis for the resulting path.

Example:

Inside my config.rb:

images_dir = "/public/assets/images"
generated_images_dir = "/public/assets/images/sprites"

Inside my application.scss:

$my-sprites: sprite-map('my-sprites/*.png);

@debug( sprite-path( $my-sprites ) );

// returns
DEBUG: my-sprites-xxxxxxx.png

Output of the debug() is my-sprites.png when it should've been sprites/my-sprites.png.

Is this a bug or am I missing the point on what the sprite-path should be used for?

Thanks for taking a look.

@dradford
Copy link

dradford commented Dec 6, 2013

Hi @scottdavis,

I'm still experiencing this issue in 0.12.2. It looks like the fix is on the allowed_extensions branch, I'm not sure how to utilise it in my version of Compass.

I'm using grunt-contrib-compass with the following image settings:

imagesPath: 'app/images',
generatedImagesDir: '.tmp/images/generated',

If I run

image-height(sprite-path($icons-2x)

I get:

No such file or directory - app/images/icons-2x-s6999b8e513.png

@dradford
Copy link

dradford commented Dec 6, 2013

Sorry, just realised this is now in 0.13, I changed my Gemfile like so and it's working:

gem 'sass', "3.3.0.rc.1"
gem 'compass', "0.13.alpha.10"

Thanks,
Damien

@ipiyer
Copy link

ipiyer commented Jan 7, 2014

when is this planned to the stable version?

@chriseppstein
Copy link
Member

@munichlinux I will release 1.0 in the next couple weeks.

@AndrewDryga
Copy link

No fix for more than 1 year :(

http_path = "/www/"
sass_dir = "/src/sass/"
images_dir = "/src/img/"
generated_images_dir = "/www/img/"
css_dir = "/www/css/"
Running "compass:prod" (compass) task
Errno::ENOENT on line ["28"] of /Library/Ruby/Gems/2.0.0/gems/compass-0.12.4/lib/compass/sass_extensions/functions/image_size.rb: No such file or directory - /Users/andrewdryga/Projects/www/mbank.web/src/img/icons/menu_x2-sf2ed120ba2.png
Run with --trace to see the full backtrace

@AndrewDryga
Copy link

Workaround, just put this into your config.rb:

# Workaround Compass bug
module Compass::SassExtensions::Functions::Sprites
    def sprite_path(map)
      Sass::Script::String.new(map.filename)
    end
    Sass::Script::Functions.declare :sprite_path, [:map]
end

@fender
Copy link

fender commented Apr 16, 2014

I'm assuming this is fixed in the latest version, 1.0.0.alpha.19? Unfortunately I get make failed errors when trying to update to the latest pre version.

@AndrewDryga
Copy link

Yes, but its alpha, so we need to wait for stable release

@fender
Copy link

fender commented Apr 16, 2014

@AndrewDryga Your workaround didn't seem to work for me. Was there anything else I needed to add to config.rb for this?

@AndrewDryga
Copy link

Here is my config:

            // To enable relative paths to assets via compass helper functions. Uncomment:
            outputStyle: "nested",
            relativeAssets: true,
            // To disable debugging comments that display the original location of your selectors. Uncomment:
            noLineComments: true,
            // We prefer SASS files
            raw: "preferred_syntax = :sass\n",
            // Add hashes to assets
            assetCacheBuster: true,
            // Where do we take sources
            sassDir: "./<%= paths.assets %>/sass/",
            imagesDir: "./<%= paths.assets %>/img/",
            importPath: "./<%= paths.vendor %>/",
            extensionsDir: "./<%= paths.vendor %>/",
            // Where we going to put them
            javascriptsDir: "./<%= paths.build %>/js/",
            cacheDir: "./<%= paths.tmp %>/compass/",
            httpPath: "./<%= paths.build %>/",
            cssDir: "./<%= paths.build %>/css/",
            fontsDir: "./<%= paths.build %>/fonts/",
            generatedImagesDir: "./<%= paths.build %>/img/",

@AndrewDryga
Copy link

Updated to latest version, Compass 1.0.0.alpha.20, and now my workaround is broken. Can someone assist? I don't know Ruby

@AndrewDryga
Copy link

New monkey patch that work for both versions in same time:

# Workaround Compass bug
require "fileutils"

module Compass::Core
end
module Compass::Core::SassExtensions
end
module Compass::Core::SassExtensions::Functions
end
module Compass::Core::SassExtensions::Functions::ImageSize
end

module Compass::Core::SassExtensions::Functions::ImageSize
  def real_path(image_file)
    # Compute the real path to the image on the file stystem if the images_dir is set.
    if Compass.configuration.generated_images_path
        if File.file?(File.join(Compass.configuration.generated_images_path, image_file))
            return File.join(Compass.configuration.generated_images_path, image_file)
        end
    end
    if Compass.configuration.images_path
        return File.join(Compass.configuration.images_path, image_file)
    end
    File.join(Compass.configuration.project_path, image_file)
  end
end

module Compass::SassExtensions
end
module Compass::SassExtensions::Functions
end
module Compass::SassExtensions::Functions::Sprites
end

module Compass::SassExtensions::Functions::Sprites
    def sprite_path(map)
        Sass::Script::String.new(map.filename)
    end
    Sass::Script::Functions.declare :sprite_path, [:map]
end

@rbcorrales
Copy link

I created the following function on my project as a workaround for this bug. I know this is not a clean solution, but it solves my need at this moment without changing any compass ruby files.

In my case, I'm using grunt-contrib-compass with the following settings:

...
imagesDir: 'app/images',
generatedImagesDir: '.tmp/images/generated',
...

So in my function, I'm just pointing to the generatedImagesDir relatively to my imagesDir:

@function sprite-path-fix($sprite-map) {
  $generated-path: "../../.tmp/images/generated/";
  $path: #{$generated-path}#{sprite-path($sprite-map)};
  @return $path;
}

I hope this could help someone experiencing a similar issue.

@martin-eberle
Copy link

In compass 1.0.1 this is still broken. :(

@AndrewDryga
Copy link

@marteb developers don't bother about bugs, just closing it without comments.

See #1715

@scottdavis
Copy link
Member

Sprites are going through a transformation to their own gem right now soon as chris approves the PR I will get this fixed and out with 1.0.1.rc

@jasonujmaalvis
Copy link

Can I get an update on this issue, has anyone got a fix for it?

@AndrewDryga
Copy link

@jasonalvis nope, i have workaround few posts above, thats all

@ivosantiago
Copy link

@AndrewDryga

I had the same problem today after update to 1.1.0.alpha.3. I did rollback to 1.0.0.rc.1 and it worked normally again. Can you check if this last one works for you?

If it does I can try to look the code changes and find the bug.

Thanks

akitaonrails added a commit to Codeminer42/cm42-central that referenced this issue Aug 10, 2016
@garrettw
Copy link

garrettw commented Feb 20, 2020

The workarounds above didn't work for me. What ended up working was just removing the generated_images_dir setting from my config.rb and replacing it with http_generated_images_path, using a path relative to css_dir (in my case, I used '../images').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests