twolfson / spritesmith

Utility that takes sprites and converts them into a stylesheet and its coordinates
MIT License
911 stars 56 forks source link

NameError when compiling spritesmith Less spritesheet styles. #49

Closed Stratus3D closed 9 years ago

Stratus3D commented 9 years ago

I have spritesmith configured something like this:

module.exports.tasks = {
  sprite: {
    generalSprites: {
      src: 'app/img/*.png',
      dest: '<%= yeoman.sprites %>/img/sprites.png',
      destCss: '<%= yeoman.sprites %>/less/sprites.less',
      }
    }
 };

This works as expected and my sprites directory contains a less directory containing sprites.less. However, when I try to compile this file with lessc on the command line I get the following error:

NameError: variable @spriteOne is undefined in less/sprites.less on line 160, column 23:
159 @spritesheet-image: '../img/sprites.png';
160 @spritesheet-sprites: @spriteOne @spriteTwo @spriteThree;

Opening up less/sprites.less reveals this (4th line is line 160):

@spritesheet-width: 748px;
@spritesheet-height: 705px;
@spritesheet-image: '../img/sprites.png';
@spritesheet-sprites: @spriteOne @spriteTwo @spriteThree;
@spritesheet: 748px 705px '../img/sprites.png' @spritesheet-sprites;

Line 160 seems blatantly wrong. @spriteOne @spriteTwo @spriteThree are never defined anywhere in the file. I opened up the template that was used to generate the Less file part of the spritesheet-templates package (https://github.com/twolfson/spritesheet-templates/blob/master/lib/templates/less.template.mustache) and tried various things to fix the issue but nothing seemed to help. I thought line 36 should have changed from:

@{{spritesheet.strings.name_sprites}}:{{#items}} @{{name}}{{/items}};

To:

@{{spritesheet.strings.name_sprites}}:{{#items}} @{{strings.name}}{{/items}};

And while this allows the file to be compiled without error, the variables are not available in the other Less files in my project (the mixins defined in the file are available, so I know the file has been imported).

It seems to me like there is something wrong with the mustache template, but lacking experience with Less I don't know what the issue with it could be.

twolfson commented 9 years ago

Ah, yep. That is definitely an error. The latest minor release should be getting rolled back soon.

https://github.com/twolfson/gulp.spritesmith/issues/30

In the interim, you can use gulp.spritesmith@2.5.0 or grunt-spritesmith@3.6.2.

twolfson commented 9 years ago

The breaking changes have been reverted in gulp.spritesmith@2.7.0 and grunt-spritesmith@3.8.0. Thanks for the bug report!

Stratus3D commented 9 years ago

Thanks @twolfson! It now compiles without error.

twolfson commented 9 years ago

The changes have been reintroduced as major releases in gulp.spritesmith@3.0.0 and grunt-spritesmith@4.0.0.