In my rails 3.2 app, using compass 0.12.7
and rails-compass 2.0.0
to generate sprites. The icons directories are [root]/public/img/marketings/icons
and [root]/public/img/marketings/icons-retina
Since the images directories are not the default images directories for compass, added a compass_config.rb in config/initializers
options = {
:sprite_load_path => Compass.configuration.sprite_load_path + ["#{Rails.root}/public/img"],
:images_dir => "public/img",
:images_path => "#{Rails.root}/public/img",
:generated_images_dir => "public/img",
:generated_images_path => "#{Rails.root}/public/img"
}
Compass.add_configuration(options, "sprites")
Wrote a customized sass file:
$sprites: sprite-map("marketings/icons/*.png");
$sprites-url: sprite-url($sprites);
$sprites2x: sprite-map("marketings/icons-retina/*.png");
$sprites2x-url: sprite-url($sprites2x);
// some more codes....
@mixin retina-sprite($name, $sprites, $sprites-url, $sprites2x, $sprites2x-url, $dimensions: true, $pad: 0) {
@if $dimensions == true {
@include sprite-dimensions($sprites, $name);
}
background-image: $sprites-url;
background-position: sprite-position($sprites, $name, -$pad, -$pad);
background-repeat: no-repeat;
@if $pad > 0 {
padding: $pad;
}
@include hidpi(1.5) {
$pos: sprite-position($sprites2x, $name, -$pad*2, -$pad*2);
background-image: $sprites2x-url;
background-position: nth($pos, 1) nth($pos, 2)/2;
@include background-size(ceil(image-width(sprite-path($sprites2x)) / 2), auto);
}
}
The sprites images were generated correctly but threw 'can't convert nil into String' error in the lines of @include sprite-dimensions($sprites, $name)
and @include background-size(ceil(image-width(sprite-path($sprites2x)) / 2), auto)
If moved the icons directories into app/assets/images and removed compass_config.rb, it works ok. However for some historical reasons the icons have to be in the public/img directory. Is there something wrong in my compass_config.rb?
Aucun commentaire:
Enregistrer un commentaire